Created
June 6, 2014 08:08
-
-
Save nek023/ed84f124094fac3ee33e to your computer and use it in GitHub Desktop.
Immutable user class in Objective-C and Swift
This file contains hidden or 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 <Foundation/Foundation.h> | |
@interface User : NSObject | |
@property (nonatomic, copy, readonly) NSString *name; | |
- (instancetype)initWithName:(NSString *)name; | |
@end |
This file contains hidden or 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 "User.h" | |
@interface User () | |
@property (nonatomic, copy, readwrite) NSString *name; | |
@end | |
@implementation User | |
- (instancetype)initWithName:(NSString *)name | |
{ | |
self = [super init]; | |
if (self) { | |
self.name = name; | |
} | |
return self; | |
} | |
@end |
This file contains hidden or 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 Cocoa | |
class User: NSObject { | |
let name: String | |
init(name: String) { | |
self.name = name | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment