Last active
January 5, 2018 04:46
-
-
Save vitonzhangtt/1fa7ade1280ce8e598ec404d9a9aa986 to your computer and use it in GitHub Desktop.
@synchronized keyword
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
@class TTUserObject; | |
@interface TTFriendsCollection : NSObject | |
- (void)addFriend:(TTUserObject *)user; | |
- (void)removeFriend:(TTUserObject *)user; | |
@end |
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
#import "TTFriendsCollection.h" | |
#import "TTUserObject.h" | |
@interface TTFriendsCollection () | |
@property(nonatomic, strong) NSMutableArray *friendsArray; | |
@end | |
@implementation TTFriendsCollection | |
- (void)addFriend:(TTUserObject *)user { | |
@synchronized (self.friendsArray) { | |
if (!self.friendsArray) { | |
self.friendsArray = [NSMutableArray array]; | |
} | |
[self.friendsArray addObject:user]; | |
} | |
} | |
- (void)removeFriend:(TTUserObject *)user { | |
@synchronized (self.friendsArray) { | |
if (self.friendsArray) { | |
[self.friendsArray removeObject:user]; | |
} | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment