Re: How to remove 'not found in protocol' compiler warning
Re: How to remove 'not found in protocol' compiler warning
- Subject: Re: How to remove 'not found in protocol' compiler warning
- From: Paul Johnson <email@hidden>
- Date: Fri, 12 Nov 2010 10:36:05 -0600
In the array controller I added an outlet for the data source of the second
table view:
IBOutlet ZZSecondArrayController *dataSource;
and connected it to the Array Controller for the second table view.
Then I changed the line that gave the compiler warning message to:
NSArray *selectedObjects = [dataSource selectedObjects];
This removed the warning message. Thanks, Sherm.
(If this doesn't look like proper implementation, let me know, because I'd
want to do things correctly.)
On Fri, Nov 12, 2010 at 8:35 AM, Thomas Davie <email@hidden> wrote:
>
> On 12 Nov 2010, at 14:17, Sherm Pendley wrote:
>
> > On Fri, Nov 12, 2010 at 9:09 AM, Paul Johnson <email@hidden> wrote:
> >
> >> I'm getting a compiler warning message at the following line of code:
> >>
> >> NSArray *selectedObjects = [[secondTableView dataSource]
> >> selectedObjects];
> >>
> >> The warning message is <'selectedObjects' not found in protocol>.
> >>
> >
> > Note that NSTableView's -dataSource returns an object of type
> > id<NSTableViewDataSource>. So, the compiler knows nothing about the
> object
> > other than its protocol conformance. Since -selectedObjects isn't part of
> > the protocol, it gives this warning.
> >
> >
> >> Can someone suggest what I need to do to remove the warning?
> >>
> >
> > Use a type cast to tell the compiler what class the data source really
> is:
> >
> > NSArray *selectedObjects = [(MyDataSourceClass*)[secondTableView
> > dataSource] selectedObjects];
>
> While this will work, I don't agree that it's the "correct" solution to the
> problem. The issue here is that you are making an assumption about the TV's
> data source that may not be true. Instead, what should be happening is that
> if you want to send messages to that particular object with the knowledge
> that it's the right type to receive those messages, you should maintain your
> own pointer to the object, and you should send messages there instead.
>
> This is roughly the same reason as why you shouldn't be sending messages to
> [NSApp delegate] – that's the app delegate, and the app is responsible for
> sending it messages, not you... if you want to send messages to a controller
> that just so happens to be the same object, maintain your own pointer to it
> with a more specific type.
>
> Bob
_______________________________________________
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