Last active
August 29, 2015 13:56
-
-
Save hfossli/9020767 to your computer and use it in GitHub Desktop.
CYou'll see if you don't use 'copy' in the setter the tests will fail.
This file contains 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
@interface MyObject () | |
@property (nonatomic, strong) NSString *myStrongString; | |
@property (nonatomic, copy) NSString *myCopyString; | |
@end | |
@implementation MyObject | |
- (id)init | |
{ | |
self = [super init]; | |
if(self) | |
{ | |
NSMutableString *testString = [NSMutableString stringWithFormat:@"hello"]; | |
self.myCopyString = testString; | |
self.myStrongString = testString; | |
[testString appendFormat:@" world"]; | |
if(![self.myStrongString isEqualToString:@"hello world"]) | |
{ | |
NSLog(@"Expected string to be 'hello world', but was '%@'", self.myStrongString); | |
abort(); | |
} | |
if(![self.myCopyString isEqualToString:@"hello"]) | |
{ | |
NSLog(@"Expected string to be 'hello', but was '%@'", self.myCopyString); | |
abort(); | |
} | |
} | |
return self; | |
} | |
- (void)setMyStrongString:(NSString *)myStrongString | |
{ | |
_myStrongString = myStrongString; | |
} | |
- (void)setMyCopyString:(NSString *)myCopyString | |
{ | |
_myCopyString = [myCopyString copy]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment