Re: What difference exist from where a method will be called?
Re: What difference exist from where a method will be called?
- Subject: Re: What difference exist from where a method will be called?
- From: Graham Cox <email@hidden>
- Date: Thu, 08 Sep 2016 23:06:13 +1000
> On 8 Sep 2016, at 9:27 PM, Raimond Hettrich <email@hidden> wrote:
>
> @interface Document : NSDocument {
> NSMutableArray *tableViewArray;
> }
>
> @property (copy) NSMutableArray *tableViewArray;
>
>
> @end
>
>
> //
> // Document.m
> // Test
> //
>
> #import "Document.h"
>
> @interface Document ()
>
> @end
>
> @implementation Document
> @synthesize tableViewArray;
>
There’s another problem, which is probably more pertinent to your issue than the one I mentioned about NSView’s -init method (I have sort of grokked what your protocol is doing now, though to be frank the design and method naming is horrible).
Above, you have an ivar called ‘tableViewArray’, then you synthesize a property called ‘tableViewArray’ which will be backed by a variable called ‘_tableViewArray’. It is NOT backed by ‘tableViewArray’.
Your code only references the ivar, not the property, but I expect if you have bindings (which you alluded to, being in NSArrayController), then these will bind to the property, not the ivar. These are two completely different things, despite being named similarly. Unfortunately you’ve run into a trap that Apple have set for the unwary with automatic synthesis and properties. If you want the propery to specifically be backed by an ivar you declared, you need to explicitly indicate that:
@synthesize tableViewArray = tableViewArray;
Alternatively, don’t declare your own ivar at all and rely on autosynthesis, and always reference the property:
self.tableViewArray
whenever you need to.
Do one or the other, but not both.
Also, as a general point, read up on model-view-controller design principles, designated initializers and cocoa naming conventions for methods. The naming of the method -getArray: is misleading to say the least.
—Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden