Re: Accessing instance variables: Xcode warnings
On Dec 11, 2020, at 11:02 AM, Carl Hoefs <newslists@...> wrote:
This is not an instance variable, this is a property. In Objective-C, like Smalltalk, an instance variable is usually part of the internal implementation of your class. That's why as of Objective-C 2.0 and the new runtime, they can (and should) be declared in the @implementation instead fo the @interface.
(I'd also not name a property something like "mType," but give it a more semantic name.)
This will be the name of the instance variable providing storage for the property if your `@implementation` has `@synthesize mType;`.
This will be the name of the instance variable providing storage for the property if you either have no `@synthesize` for it, or if you have `@synthesize mType = _mtype;` in your `@implementation`.
This is interacting with the property via its accessors, not accessing its storage.
It all depends what you want. Often in the implementation of a class you know what the invariants you need to maintain are, so you can interact directly with the backing storage for a property. Note that this doesn't have to be an instance variable, that's just the default behavior.
What's right will depend on both context and an understanding of the distinction between the property (an interface) and its underlying storage (an implementation). You can usually