Skip to content

Commit

Permalink
Avoid static initialization of the kIdentity block
Browse files Browse the repository at this point in the history
Unlike other Objective-C objects, there's no hard reason why the compiler wouldn't be able to initialize a block statically (as it does with NSString literals). And it certainly doesn't complain about it (like it does with other object initializers). But as I haven't been able to find confirmation of this, and we're seeing a weird crash occur near this code, let's play it safe.
  • Loading branch information
jcanizales authored Aug 25, 2016
1 parent 19ea0cf commit ea5325c
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/objective-c/RxLibrary/transformations/GRXMappingWriter.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@

#import "GRXMappingWriter.h"

static id (^kIdentity)(id value) = ^id(id value) {
return value;
};

@interface GRXForwardingWriter () <GRXWriteable>
@end

Expand All @@ -51,7 +47,9 @@ - (instancetype)initWithWriter:(GRXWriter *)writer {
// Designated initializer
- (instancetype)initWithWriter:(GRXWriter *)writer map:(id (^)(id value))map {
if ((self = [super initWithWriter:writer])) {
_map = map ?: kIdentity;
_map = map ?: ^id(id value) {
return value;
};
}
return self;
}
Expand Down

0 comments on commit ea5325c

Please sign in to comment.