Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Property: What's the difference between strong and copy. Blogpost:
// main.m
// strong_retain_copy
// Created by Christopher Loessl on 25/02/14.
// Copyright (c) 2014 Christopher Loessl. All rights reserved.
#import <Foundation/Foundation.h>
@interface Person : NSObject
@property (strong, nonatomic) NSString *name;
@property (copy, nonatomic) NSString *nick;
@implementation Person
int main(int argc, const char * argv[])
@autoreleasepool {
Person *per = [[Person alloc] init];
NSMutableString *aName = [NSMutableString stringWithString:@"Christopher"];
// The pointer "" is changed.
// "" points at the same location as "someName" afterwards = aName;
// This is equal to
// per.address = [someName copy];
// Therefore the points are not the same afterwards
per.nick = aName;
// Changing "someName" to
[aName setString:@"hashier"];
NSLog(@" : %@",;
NSLog(@"per.nick : %@", per.nick);
NSLog(@"someName : %@", aName);
NSLog(@"\nPointer 1: %p\nPointer 2: %p\nPointer 3: %p",, per.nick, aName);
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.