Created
February 14, 2018 11:28
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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