草庐IT

self-assignment

全部标签

iphone - Objective-C - 何时使用 'self'

这是来自Apple的iPhone'UtilityAplication'模板的未修改代码:-(void)applicationDidFinishLaunching:(UIApplication*)application{MainViewController*aController=[[MainViewControlleralloc]initWithNibName:@"MainView"bundle:nil];self.mainViewController=aController;[aControllerrelease];mainViewController.view.frame=[UIS

iphone - Objective-C - 何时使用 'self'

这是来自Apple的iPhone'UtilityAplication'模板的未修改代码:-(void)applicationDidFinishLaunching:(UIApplication*)application{MainViewController*aController=[[MainViewControlleralloc]initWithNibName:@"MainView"bundle:nil];self.mainViewController=aController;[aControllerrelease];mainViewController.view.frame=[UIS

iphone - self.window.rootViewController 与窗口 addSubview

我注意到ApplicationDelegate中有很多iPhone应用示例-(void)applicationDidFinishLaunching:(UIApplication*)application有[windowaddSubview:someController.view];(1)相对于self.window.rootViewController=self.someController;(2)是否有任何实际理由使用其中一个而不是另一个?一个在技术上是正确的吗?Controller是否有与数字(2)等效的命令,例如self.someController.rootController

iphone - self.window.rootViewController 与窗口 addSubview

我注意到ApplicationDelegate中有很多iPhone应用示例-(void)applicationDidFinishLaunching:(UIApplication*)application有[windowaddSubview:someController.view];(1)相对于self.window.rootViewController=self.someController;(2)是否有任何实际理由使用其中一个而不是另一个?一个在技术上是正确的吗?Controller是否有与数字(2)等效的命令,例如self.someController.rootController

ios - _和 self 之间的区别。在 Objective-C 中

在Objective-C中调用@property时使用下划线和使用self关键字有区别吗?属性(property)声明:@property(weak,nonatomic)NSString*myString;在属性上调用@synthesize:@synthesizemyString=_myString;如果我想在我的代码中使用它有区别吗?什么时候?在getter/setter中?self.myString=@"test";_myString=@"test"; 最佳答案 self.myString=@"test";完全等同于编写[sel

ios - _和 self 之间的区别。在 Objective-C 中

在Objective-C中调用@property时使用下划线和使用self关键字有区别吗?属性(property)声明:@property(weak,nonatomic)NSString*myString;在属性上调用@synthesize:@synthesizemyString=_myString;如果我想在我的代码中使用它有区别吗?什么时候?在getter/setter中?self.myString=@"test";_myString=@"test"; 最佳答案 self.myString=@"test";完全等同于编写[sel

ios - 无法访问 dispatch_async : "Variable is not Assignable (missing _block type specifier)" 中的全局变量

这个问题在这里已经有了答案:AssignavariableinsideaBlocktoavariableoutsideaBlock(8个回答)关闭9年前。在我的dispach_async代码block中,我无法访问全局变量。我收到此错误VariableisnotAssignable(missing_blocktypespecifier)。NSString*textString;dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,(unsignedlong)NULL),^(void){textS

ios - 无法访问 dispatch_async : "Variable is not Assignable (missing _block type specifier)" 中的全局变量

这个问题在这里已经有了答案:AssignavariableinsideaBlocktoavariableoutsideaBlock(8个回答)关闭9年前。在我的dispach_async代码block中,我无法访问全局变量。我收到此错误VariableisnotAssignable(missing_blocktypespecifier)。NSString*textString;dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,(unsignedlong)NULL),^(void){textS

objective-c - 我应该在 ARC 的 init 方法中引用 self.property 吗?

一个简单的问题。如果我有一个属性和一个用相同名称声明的ivar:在.h文件中:(Reminder*)reminder;@property(nonatomic,strong)(Reminder*)reminder;在.m文件中,如果我使用ARC,我应该使用ivar还是init方法中的属性?-(id)initWithReminder:(Reminder*)reminder_{self=[superinit];if(self){reminder=reminder_;}returnself;}或者我应该像这样使用该属性来获得自动引用计数的好处:-(id)initWithReminder:(Re

objective-c - 我应该在 ARC 的 init 方法中引用 self.property 吗?

一个简单的问题。如果我有一个属性和一个用相同名称声明的ivar:在.h文件中:(Reminder*)reminder;@property(nonatomic,strong)(Reminder*)reminder;在.m文件中,如果我使用ARC,我应该使用ivar还是init方法中的属性?-(id)initWithReminder:(Reminder*)reminder_{self=[superinit];if(self){reminder=reminder_;}returnself;}或者我应该像这样使用该属性来获得自动引用计数的好处:-(id)initWithReminder:(Re