I have myClass instantiated by my appDelegate, I have another class, newClass instantiated by myClass. From the newClass instance, I want to access a property in the myClass instance that created it. I have done this by:
[[[UIApplication sharedApplication].delegate myClass] property]
This works, I can actually get the property but I get this warning from Xcode:
warning: "-myClass" not found in protocols
warning: no "-myClass" method found
(messages without a matching signature will be assumed to return "id" and accept "..." as arguments)
The newClass property has been correctly declared in the .h and .m files, it’s properties have been set and it has been synthesized.
It compiles and runs and I can actually get the property’s value.
Should I ignore the warning in Xcode?
Is there a better way to access the myClass instance’s property?
Look at the documentation for -[UIApplication delegate]. Note that it has a return type of:
Therefore, all you know about the returned object is that it conforms to this protocol. It is nothing less than a leap of faith to then assume that the delegate responds to the
-myClassmessage, and not one the compiler is willing to make.You could hack it slightly to work like so:
But it would be bad practice. Instead, I suggest you make your application delegate a singleton so you can do: