Re: NSTableView data source issue - code moving from xcode 3 to xcode 4

2011-10-09 Thread Fritz Anderson
On 9 Oct 2011, at 11:41 AM, Peter Hudson wrote:

> I have found a solution in overriding the dataSource  method in my table view 
> subclass and simply returning [self  dataSource]   cast to the class which I 
> know the datasource to be. 

Why override the method, when all you can just cast the return value?

@implementation MyTableViewClass

- (void) myMethod
{
DataSourceClass * aVar = (DataSourceClass *) [self dataSource];
// ...
}
// ...
@end

You will have to make sure that DataSourceClass declares it complies with 
.

— F

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSTableView data source issue - code moving from xcode 3 to xcode 4

2011-10-09 Thread Jens Alfke

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”. 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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSTableView data source issue - code moving from xcode 3 to xcode 4

2011-10-09 Thread Peter Hudson
Hi There

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.

I have found a solution in overriding the dataSource  method in my table view 
subclass and simply returning [self  dataSource]   cast to the class which I 
know the datasource to be.  

This feels evil.  Is there a nicer way to do this ?

Peter
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com