Re: How to remove 'not found in protocol' compiler warning
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 wrote: > > On 12 Nov 2010, at 14:17, Sherm Pendley wrote: > > > On Fri, Nov 12, 2010 at 9:09 AM, Paul Johnson 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. 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 (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: How to remove 'not found in protocol' compiler warning
On 12 Nov 2010, at 14:17, Sherm Pendley wrote: > On Fri, Nov 12, 2010 at 9:09 AM, Paul Johnson 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. 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 (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: How to remove 'not found in protocol' compiler warning
On Fri, Nov 12, 2010 at 9:09 AM, Paul Johnson 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. 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]; sherm-- -- Cocoa programming in Perl: http://camelbones.sourceforge.net ___ 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
How to remove 'not found in protocol' compiler warning
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>. Can someone suggest what I need to do to remove the warning? ___ 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