Re: How to avoid warning?
Re: How to avoid warning?
- Subject: Re: How to avoid warning?
- From: Jens Alfke <email@hidden>
- Date: Tue, 22 Jan 2013 11:12:01 -0800
On Jan 22, 2013, at 9:23 AM, Dave <email@hidden> wrote:
>> You could try declaring initWithManager: in a category on the class visible only to your implementation code. (i.e. at the top of your .m file)
>
> The class name is passed in as a string and the class is formed from that, so I can't pre-declare it. Please see my other reply.
Sure you can:
@interface SomeFictionalClassName
- (id) initWithManager: (Foo*)manager;
@end
Put that at the top of your source file and the warning will go away, because the compiler is now confident that there exists an -initWithManager: method. (The fact that you’ve declared it on a completely fictional class doesn’t matter.)
As others have said, though, it really sounds like what you want is a protocol that defines the -initWithManager: method. This is a better solution because it adds more type-safety — if you ever rename -initWithManager:, but don’t fix all the places it’s used, the compiler will then be able to complain about the places you missed, so you’ll avoid confusing runtime errors.
—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