Re: NSTableView data source issue - code moving from xcode 3 to xcode 4
Re: NSTableView data source issue - code moving from xcode 3 to xcode 4
- Subject: Re: NSTableView data source issue - code moving from xcode 3 to xcode 4
- From: Jens Alfke <email@hidden>
- Date: Sun, 09 Oct 2011 10:01:36 -0700
On Oct 9, 2011, at 9:41 AM, Peter Hudson wrote:
> For a long time ( in xcode 3 ) when I want to access a table view data source ( in the sub class code for the table view ) I simply called [self dataSource]
> I would then call methods declared and implemented on the class which I new to be the datasource. This worked fine.
>
> In xcode 4 ( sdk 10.7 ) the compiler throws a semantic warning when I do this. It complains that the return value from [self dataSource] is ignorant of the methods I am calling on it.
This probably happened because you changed the base SDK from 10.5 to 10.6+.
In the 10.6 SDK Apple introduced @protocols for most delegates/data-sources/etc instead of making them “informal protocols” aka categories. So the -delegate/-dataSource properties now no longer return an untyped “id” but a typed protocol reference like “id<NSTableViewDataSource>”. The benefit is that the compiler can now type-check it. The drawback is that the compiler will now type-check it :)
If you know your data source is of, say, class MyDataSource, then all you need to do is add a cast:
[(MyDataSource*)[self dataSource] myCustomMethod]
—Jens
_______________________________________________
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