Skip to content

Instantly share code, notes, and snippets.

@hfossli
Last active August 29, 2015 13:56
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 hfossli/9020767 to your computer and use it in GitHub Desktop.
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.
@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