Skip to content

Instantly share code, notes, and snippets.

@trojanfoe
Last active January 3, 2016 23:29
Show Gist options
  • Save trojanfoe/8535318 to your computer and use it in GitHub Desktop.
Save trojanfoe/8535318 to your computer and use it in GitHub Desktop.
#import <Foundation/Foundation.h>
@interface ClassA : NSObject
@property NSMutableString *string;
- (void)changeString;
- (void)printString;
@end
@implementation ClassA
- (void)changeString {
[self.string appendString:@"ClassA Did This"];
}
- (void)printString {
NSLog(@"ClassA string='%@'", self.string);
}
@end
@interface ClassB : NSObject
@property NSMutableString *string;
- (void)changeString;
- (void)printString;
@end
@implementation ClassB
- (void)changeString {
[self.string appendString:@" ClassB Did This"];
}
- (void)printString {
NSLog(@"ClassB string='%@'", self.string);
}
@end
int main(int argc, const char * argv[])
{
@autoreleasepool {
ClassA *a = [[ClassA alloc] init];
ClassB *b = [[ClassB alloc] init];
NSMutableString *string = [[NSMutableString alloc] init];
a.string = string;
b.string = string;
[a changeString];
[a printString];
[b printString];
[b changeString];
[a printString];
[b printString];
}
return 0;
}
2014-01-21 06:33:00.798 CallByRef[37837:303] ClassA string='ClassA Did This'
2014-01-21 06:33:00.801 CallByRef[37837:303] ClassB string='ClassA Did This'
2014-01-21 06:33:00.802 CallByRef[37837:303] ClassA string='ClassA Did This ClassB Did This'
2014-01-21 06:33:00.802 CallByRef[37837:303] ClassB string='ClassA Did This ClassB Did This'
Program ended with exit code: 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment