声明一个类
#import <Foundation/Foundation.h>
@interface Foo : NSObject <NSCoding>
@property(copy, nonatomic)NSString *strVal;
@property int intVal;
@property float floatVal;
@end
在main函数里
#import <Foundation/Foundation.h>
#import "Foo.h"
int main (int argc, char *argv[])
{
@autoreleasepool {
Foo *myfoo1 = [[Foo alloc] init];
Foo *myfoo2;
myfoo1.strVal = @"This is the string";
}
return 0;
}
这里的strVal
既然是一个指向NSString
的指针,为什么又可以给它赋值一个NSString
对象?
大家讲道理2017-05-02 09:23:38
The modification of NSString is copy, which means that when copying, another piece of memory is opened, not a pointer copy.
PHP中文网2017-05-02 09:23:38
All classes in Objective-c, operations after instantiating objects are pointer operations. @ returns an anonymous object pointer.