【发布时间】:2013-10-19 18:46:17
【问题描述】:
我想给一个 NSString 对象添加一个属性。出于这个原因,我想继承它。
我尝试做这样的事情:
@interface MyString : NSString
@property (nonatomic) NSInteger userId;
@end
那我就可以了
MyString *testString = [[MyString alloc] init];
testString = [MyString stringWithFormat:@"hello"];
testString.userId = 2;
NSLog(@"testString: %@", testString); //-> Want it to return "testString: hello"
NSLog(@"userId: %d", testString.userId); //-> Want it to return "userId: 2"
我不知道如何继承 NSString(创建存储设施,重写一些方法(长度,characterAtIndex)。有想法吗?
【问题讨论】:
-
为什么字符串会有用户ID?
标签: iphone ios objective-c