ivar

Synthesized Properties and ivar error

£可爱£侵袭症+ 提交于 2021-02-07 18:11:09
问题 I've been building my program in the "Debug X86-64" mode (Xcode 3.6) and everything works flawlessly. However, I just tried switching to "Release X86-64" mode and upon compiling received the following errors for each of my properties: Synthesized property 'x' must either be named the same as a compatible ivar or must explicitly name an ivar. Where 'x' is one of my properties, the first being 'company' (I received 51 errors of this type.). In my .h interface file, I've listed the items this

What is the correct way of init iVar variables in presence of ARC

跟風遠走 提交于 2020-01-10 20:17:08
问题 Example iVar foo , @property (nonatomic) NSString* foo; // inside .h Option 1 @Synthesize foo; //Inside .m foo = [[NSString alloc] init]; // viewDidLoad method Option 2 @Synthesize foo; //Inside .m self.foo = [[NSString alloc] init]; // viewDidLoad method Option 3 @Synthesize foo = _foo; //Inside .m _foo = [[NSString alloc] init]; // viewDidLoad method Why? At so many places I have seen code which has different ways of doing init an Object in Obj - C but which one is the best practise? 回答1:

Syntax for accessing instance variables? (Objective-C)

耗尽温柔 提交于 2020-01-02 03:45:09
问题 What is the proper syntax for accessing an instance variable in Objective-C? Assume we have this variable: @interface thisInterface : UIViewController { NSMutableString *aString; } @property (nonatomic, retain) NSMutableString *aString; and that it is synthesized. When we want to access it, we first would want to allocate and initialize it. Having programmed in Objective-C for about a month now, I've seen two different forms of syntax. I've seen people do simply aString = [[NSMutableString

Assignment to ivar in a Block via weak pointer

断了今生、忘了曾经 提交于 2019-12-30 03:20:09
问题 I have a read-only property isFinished in my interface file: typedef void (^MyFinishedBlock)(BOOL success, NSError *e); @interface TMSyncBase : NSObject { BOOL isFinished_; } @property (nonatomic, readonly) BOOL isFinished; and I want to set it to YES in a block at some point later, without creating a retain cycle to self : - (void)doSomethingWithFinishedBlock:(MyFinishedBlock)theFinishedBlock { __weak MyClass *weakSelf = self; MyFinishedBlock finishedBlockWrapper = ^(BOOL success, NSError *e

Why would you use an ivar?

落花浮王杯 提交于 2019-12-27 10:36:07
问题 I usually see this question asked the other way, such as Must every ivar be a property? (and I like bbum's answer to this Q). I use properties almost exclusively in my code. Every so often, however, I work with a contractor who has been developing on iOS for a long time and is a traditional game programmer. He writes code that declares almost no properties whatsoever and leans on ivars. I assume he does this because 1.) he's used to it since properties didn't always exist until Objective C 2

Why would you use an ivar?

浪尽此生 提交于 2019-12-27 10:35:40
问题 I usually see this question asked the other way, such as Must every ivar be a property? (and I like bbum's answer to this Q). I use properties almost exclusively in my code. Every so often, however, I work with a contractor who has been developing on iOS for a long time and is a traditional game programmer. He writes code that declares almost no properties whatsoever and leans on ivars. I assume he does this because 1.) he's used to it since properties didn't always exist until Objective C 2

Use property in class extension instead of ivar in post ARC

早过忘川 提交于 2019-12-24 21:49:48
问题 The recommended practice is to use property, including private ones through class extension instead of ivar (except in init and dealloc) in the post ARC environment. Aside from it being a recommended practice, what are the main drawbacks in someone using ivar instead of property? I am trying to convince some folks to make the switch but some have argued ivar works just as well and faster. So I would like to collect good solid arguments rather than giving soft statements such as "it's better,

“property is backed by an ivar” ? What technically does that mean?

北城余情 提交于 2019-12-21 05:31:21
问题 So ... I'm still fairly new to Objective C ... taking some iTunes U corses ... doing some exercises and all ... But when you uses to do @synthesize myProperty = _myIvarPropertyNameToUse; ... iOS 5 would create an ivar that would "back" the property. What exactly is going on here as far as where things sit in memory ... (1) Is the ivar a true variable? ... or is it a pointer to the location of the property in the object? (2) The property is on the heap, (being part of the object), right? Is

Changing an instance variable in a block

血红的双手。 提交于 2019-12-18 16:26:12
问题 I am quite confused about how to change an instance variable inside of a block. The interface file (.h): @interface TPFavoritesViewController : UIViewController { bool refreshing; } The implementation: __weak TPFavoritesViewController *temp_self = self; refreshing = NO; [myTableView addPullToRefreshWithActionHandler:^{ refreshing = YES; [temp_self refresh]; }]; As you might guess, I get a retain cycle warning when I try to change the refreshing ivar inside of the block. How would I do this

Changing an instance variable in a block

≡放荡痞女 提交于 2019-12-18 16:26:07
问题 I am quite confused about how to change an instance variable inside of a block. The interface file (.h): @interface TPFavoritesViewController : UIViewController { bool refreshing; } The implementation: __weak TPFavoritesViewController *temp_self = self; refreshing = NO; [myTableView addPullToRefreshWithActionHandler:^{ refreshing = YES; [temp_self refresh]; }]; As you might guess, I get a retain cycle warning when I try to change the refreshing ivar inside of the block. How would I do this