问题描述:
为了coredata创建类:
LoginPass.h
然后first类
FirstClass.h
然后在secondclass中使用这些类,用@class声明:
SecondClass.h
...
@class FirstClass;
@class LoginPass;
...
@interface SecondClass : UIViewController
{
......
}
@property (strong, nonatomic) FirstClass *fromFirstClass;
@property (strong, nonatomic) LoginPass *myEntity;
...
@end
在.m文件中
#import "SecondClass.h"
#import "FirstClass.h"
#import "LoginPass.h"
@implementation SecondClass
...
@synthesize fromFirstClass = _fromFirstClass;
@synthesize myEntity = _myEntity;
...
我不明白为什么要写这行代码:@synthesize myEntity = _myEntity;
但是换成这行代码就不行了:@synthesize myEntity;
问题是:为什么可以用self.fromFirstClass
,但是不能用self.myEntity
。
如果用 self.myEntity的话系统会报错。为什么?
@synthesize fromFirstClass = _fromFirstClass;
@synthesize myEntity = _myEntity;
这两行代码都正确,不过现在@synthesize 已经包含在编译器里所以不用@了
在使用self.prop用来访问属性
在用_prop时是直接调用属性
在使用self.prop时, 调用方法取决于lhs 或者hs of =(assignment) :
-(NSString *)prop; //在使用myName=self.prop调用;
and/or
-(void)setProp; //在使用self.prop=@"master"调用;
同时 如果使用 self._myEntity
,系统会需找名字中带_
的方法, 导致错误.