Re: How to avoid warning?

2013-01-23 Thread Uli Kusterer
On Jan 22, 2013, at 8:12 PM, Jens Alfke j...@mooseyard.com wrote: @interface SomeFictionalClassName - (id) initWithManager: (Foo*)manager; @end That feels a bit dirty to me. I'd recommend using a protocol instead. As long as the compiler has seen the method *somewhere*, it will consider it

Re: How to avoid warning?

2013-01-23 Thread Uli Kusterer
On Jan 22, 2013, at 8:28 PM, Andy Lee ag...@mac.com wrote: To be extra fail-safe, you might want to perform a cast to be sure the right initWithManager: gets called: if ([myClass conformsToProtocol:@protocol(MyProtocol)]) myObj = [(id MyProtocol)[myClass alloc] initWithManager:self];

Re: How to avoid warning?

2013-01-23 Thread Andy Lee
On Jan 23, 2013, at 8:22 AM, Uli Kusterer witness.of.teacht...@gmx.net wrote: @protocol UKCanInitWithManagerProtocol -(id) initWithManager: (Foo*)inManager; @end ... if( [myClass respondsToSelector: @selector(initWithManager:)] ) myObj = [(idUKCanInitWithManagerProtocol)[myClass

Re: How to avoid warning?

2013-01-22 Thread Dave
to avoid the warning or otherwise fix it? You need to #import a header file with an @interface declaration for the 'initWithManager:' method. The rule is that when the compiler sees a message send to a receiver of type 'id' (which is the return type of 'alloc'), it needs to have seen *some

Re: How to avoid warning?

2013-01-22 Thread Dave
on the initWithManager: statement (Obviously), how to avoid the warning or otherwise fix it? 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

Re: How to avoid warning?

2013-01-22 Thread Dave
On 21 Jan 2013, at 22:12, Jens Alfke wrote: On Jan 21, 2013, at 10:14 AM, Dave d...@looktowindward.com wrote: if (class_RespondsToSelector(myClass,@selector(initWithManager:) == NO) Off-topic: instead of using the Obj-C runtime’s C API, you can express this as if ([myClass

Re: How to avoid warning?

2013-01-22 Thread Jean Suisse
myObj = [[myClass alloc] performSelector(@selector(initWithManager:) withObject:self]; Would this work? You could do : id myObj =[myClass alloc]; myObj = [myObj performSelector(@selector(initWithManager:) withObject:myObj]; ___ Cocoa-dev

Re: How to avoid warning?

2013-01-22 Thread Jean Suisse
On 22 janv. 2013, at 18:34, Jean Suisse jean.li...@gmail.com wrote: myObj = [[myClass alloc] performSelector(@selector(initWithManager:) withObject:self]; Would this work? You could do : id myObj =[myClass alloc]; myObj = [myObj performSelector(@selector(initWithManager:)

Re: How to avoid warning?

2013-01-22 Thread Keary Suska
]]; I get a warning on the initWithManager: statement (Obviously), how to avoid the warning or otherwise fix it? 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

Re: How to avoid warning?

2013-01-22 Thread Dave
On 22 Jan 2013, at 17:34, Jean Suisse wrote: myObj = [[myClass alloc] performSelector(@selector (initWithManager:) withObject:self]; Would this work? You could do : id myObj =[myClass alloc]; myObj = [myObj performSelector(@selector(initWithManager:) withObject:myObj]; Thanks for

Re: How to avoid warning?

2013-01-22 Thread Dave
]; else myObj = [[myClass alloc] initWithManager:sel]]; I get a warning on the initWithManager: statement (Obviously), how to avoid the warning or otherwise fix it? You could try declaring initWithManager: in a category on the class visible only to your implementation code. (i.e. at the top

Re: How to avoid warning?

2013-01-22 Thread Jens Alfke
On Jan 22, 2013, at 9:24 AM, Dave d...@looktowindward.com wrote: Ok, cool, thanks for that, I still have the same problem though when I call the initWithManager. Others answered this already. To recap: The compiler needs to see a declaration of an -initWithManager: method before it parses

Re: How to avoid warning?

2013-01-22 Thread Dave
On 22 Jan 2013, at 18:26, Jens Alfke wrote: On Jan 22, 2013, at 9:24 AM, Dave d...@looktowindward.com wrote: Ok, cool, thanks for that, I still have the same problem though when I call the initWithManager. Others answered this already. To recap: The compiler needs to see a declaration

Re: How to avoid warning?

2013-01-22 Thread John McCall
On Jan 22, 2013, at 9:23 AM, Dave d...@looktowindward.com wrote: That's wont help because myClass is a variable created from a String. But it will help, because Quincey's suggestion is not contingent on the type of the object that you send the message to. The compiler is merely asking that

Re: How to avoid warning?

2013-01-22 Thread Andy Lee
On Jan 22, 2013, at 1:26 PM, Jens Alfke j...@mooseyard.com wrote: On Jan 22, 2013, at 9:24 AM, Dave d...@looktowindward.com wrote: Ok, cool, thanks for that, I still have the same problem though when I call the initWithManager. Others answered this already. To recap: The compiler needs

Re: How to avoid warning?

2013-01-22 Thread Jens Alfke
On Jan 22, 2013, at 9:23 AM, Dave d...@looktowindward.com 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

Re: How to avoid warning?

2013-01-22 Thread Charles Srstka
On Jan 22, 2013, at 12:58 PM, Andy Lee ag...@mac.com wrote: // Or this also works (protocol). @protocol AvoidCompilerWarning - (id)initWithArg:(id)arg; @end Really, a protocol is what you ought to be doing. Make a protocol with -initWithManager: in it, and then make all the classes that

Re: How to avoid warning?

2013-01-22 Thread Andy Lee
On Jan 22, 2013, at 2:19 PM, Charles Srstka cocoa...@charlessoft.com wrote: On Jan 22, 2013, at 12:58 PM, Andy Lee ag...@mac.com wrote: // Or this also works (protocol). @protocol AvoidCompilerWarning - (id)initWithArg:(id)arg; @end Really, a protocol is what you ought to be doing. Make

Re: How to avoid warning?

2013-01-22 Thread Charles Srstka
On Jan 22, 2013, at 1:28 PM, Andy Lee ag...@mac.com wrote: On Jan 22, 2013, at 2:19 PM, Charles Srstka cocoa...@charlessoft.com wrote: On Jan 22, 2013, at 12:58 PM, Andy Lee ag...@mac.com wrote: // Or this also works (protocol). @protocol AvoidCompilerWarning - (id)initWithArg:(id)arg;

Re: How to avoid warning?

2013-01-22 Thread Jens Alfke
On Jan 22, 2013, at 10:15 AM, Dave d...@looktowindward.com wrote: This has to work with classes that exist already as well as classes that don't. If initWithManager is defined in the class in question knows what it is being called like this, if not then it defaults to the regular NSObject

Re: How to avoid warning?

2013-01-22 Thread Dave
On 22 Jan 2013, at 21:27, Jens Alfke wrote: On Jan 22, 2013, at 10:15 AM, Dave d...@looktowindward.com wrote: This has to work with classes that exist already as well as classes that don't. If initWithManager is defined in the class in question knows what it is being called like this, if

How to avoid warning?

2013-01-21 Thread Dave
Hi All, I have the following code: if (class_RespondsToSelector(myClass,@selector(initWithManager:) == NO) myObj = [[myClass alloc] init]; else myObj = [[myClass alloc] initWithManager:sel]]; I get a warning on the initWithManager: statement (Obviously), how to avoid

Re: How to avoid warning?

2013-01-21 Thread David Duncan
a warning on the initWithManager: statement (Obviously), how to avoid the warning or otherwise fix it? What warning do you get? (Its not obvious from context). -- David Duncan ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post

Re: How to avoid warning?

2013-01-21 Thread Tom Davie
on the initWithManager: statement (Obviously), how to avoid the warning or otherwise fix it? Simple, Write better code where you know the types you're dealing with ;). Bob ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post

Re: How to avoid warning?

2013-01-21 Thread Robert Martin
]; else myObj = [[myClass alloc] initWithManager:sel]]; I get a warning on the initWithManager: statement (Obviously), how to avoid the warning or otherwise fix it? ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post

Re: How to avoid warning?

2013-01-21 Thread Quincey Morris
On Jan 21, 2013, at 10:14 , Dave d...@looktowindward.com wrote: myObj = [[myClass alloc] initWithManager:sel]]; I get a warning on the initWithManager: statement (Obviously), how to avoid the warning or otherwise fix it? You need to #import a header file with an @interface

Re: How to avoid warning?

2013-01-21 Thread Steve Sisak
At 6:14 PM + 1/21/13, Dave wrote: if (class_RespondsToSelector(myClass,@selector(initWithManager:) == NO) myObj = [[myClass alloc] init]; else myObj = [[myClass alloc] initWithManager:sel]]; I get a warning on the initWithManager: statement (Obviously), how to avoid

Re: How to avoid warning?

2013-01-21 Thread Jens Alfke
On Jan 21, 2013, at 10:14 AM, Dave d...@looktowindward.com wrote: if (class_RespondsToSelector(myClass,@selector(initWithManager:) == NO) Off-topic: instead of using the Obj-C runtime’s C API, you can express this as if ([myClass instancesRespondToSelector: @selector(initWithManager:)]