objective-c中,对对象赋值是否是为指针赋值?
我想大声告诉你
我想大声告诉你 2017-05-02 09:21:38
0
2
537

声明一个类

#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对象?

我想大声告诉你
我想大声告诉你

reply all(2)
大家讲道理

The modification of NSString is copy, which means that when copying, another piece of memory is opened, not a pointer copy.

洪涛

All classes in Objective-c, operations after instantiating objects are pointer operations. @ returns an anonymous object pointer.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template