Skip to content

Instantly share code, notes, and snippets.

@dgelessus
Created February 14, 2018 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgelessus/d943f2d1f477b046fd32b89e551ca23f to your computer and use it in GitHub Desktop.
Save dgelessus/d943f2d1f477b046fd32b89e551ca23f to your computer and use it in GitHub Desktop.
Test code to check whether compiler-synthesized property setters actually assign anything if the new object equals the current one
#import <Foundation/Foundation.h>
@interface DGVeryEqual : NSObject
@property(copy) NSString *desc;
-(instancetype)initWithDescription:(NSString *)description;
@end
@implementation DGVeryEqual : NSObject
-(instancetype)initWithDescription:(NSString *)description {
self = [self init];
if (self) {
self.desc = description;
}
return self;
}
-(BOOL)isEqual:(id)object {
return TRUE;
}
-(NSString *)description {
return self.desc;
}
@end
@interface DGPropertyHolder : NSObject
@property(retain) DGVeryEqual *thing;
@end
@implementation DGPropertyHolder : NSObject
@end
int main(int argc, char **argv) {
@autoreleasepool {
DGVeryEqual *thing1 = [[DGVeryEqual alloc] initWithDescription:@"thing1"];
DGVeryEqual *thing2 = [[DGVeryEqual alloc] initWithDescription:@"thing2"];
NSLog(@"%@ %@", thing1, thing2);
DGPropertyHolder *holder = [[DGPropertyHolder alloc] init];
holder.thing = thing1;
NSLog(@"%@", holder.thing);
holder.thing = thing2;
NSLog(@"%@", holder.thing);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment