App crashes on simulator but runs fine on iPod 3.1.3. The Super class' init method is not being hit (even at debug) when app runs in simulator
All this might look too trivial but read it through -
I have simple class (A) and super class (B). I have init methods on both (designated initializer initWithData for A and regular (id)init for B) . I have a delegate defined on my super (B) which is called by [instanceofA setDelegate:self]. And of course I have following line of code - @interface A:B { //declarations }
So when I run my app on iphone simulator (Ver 3.2) the call to set Delegate the run fails with message "-[A setDelegate:]: unrecognized selector sent to instance 0x4c59e10" and therefore the app crashes
When I debug my app, the [super init] call within initializer for A doesn't call its super i.e. B (even if I keep a debug pointer within B's init method)
All this works absolutely fine if I run the app on my iPod (SDK 3.1.3) - even the debug points are hit
For some reason, at run time the simulator is not able to find class A's super class that is B.
I have already tried resetting "Contents and Settings" on my iPhone Simulator but in-vain. I have also tried rebuilding multiple times, marked all my classes "touched". Nothing is working. Is this issue with cleaning the existing targets? How do we clean targets in XCODE?
I am not sure if its relevant but slightly similar issue is under discussion here - [http://stackoverflow.com/questions/3706068/app-crashes-on-simulator-works-on-iphone-device][1]
Update!
I know the problem - please ignore all the super int stuff above. The issue is with this message (which shows upfront on my debugger console - not as warning though) -
objc[34514]: Class Connection is implemented in both /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.3.sdk/System/Library/PrivateFrameworks/Message.framework/Message and /Users/admin1/Library/Application Support/iPhone Simulator/3.1.3/Applications/xxxyyyyzzzzbbbbb/MyApp.app/MyApp. One of the two will be used. Which one is undefined.
so i remove "messageUI.framework" and remove all my references to it in my code like MFMailComposeViewController, canSendMail etc. and everything is back to normal. I should have known, that was my last set of implementatio开发者_开发知识库ns. I wasn't really doing any unit testing and therefore didn't realize this when I started testing my app.
I googled ofcourse and bumped into following url - groups.google.com/group/objectiveresource/tree/browse_frm/month/2009-07/d8b3f3664c39785b?rnum=1&_done=%2Fgroup%2Fobjectiveresource%2Fbrowse_frm%2Fmonth%2F2009-07%3F
which links to - groups.google.com/group/objectiveresource/browse_thread/thread/349756a5e01eb8b1/8712f5fde9e9b47c?lnk=gst&q=prefix#8712f5fde9e9b47c
What are class name related guidelines for objective C? Any online resource (apple/non apple) which talks about how to avoid class name collisions? For now I will try to figure out which class of mine is causing this conflict...
In answer to your revised question, Objective-C lacks namespaces, which is why you see collisions like what happened in your case. This is why it is a convention to use two- or three-letter prefixes before your custom class names (something like SBHConnection would have avoided this problem in your case, for example).
See the question "What is the best way to solve an Objective-C namespace collision?" for a detailed discussion about this, although that veers off into more technical territory. See Scott Stevenson's Cocoa Style for Objective-C for a more down-to-earth explanation of some of the elements of style that you'll commonly see in Cocoa and Cocoa Touch applications.
it's Class named "Connection" in my class and also in messageUI.framework.. i should be reading stuff more closely!!
Answer was right there in front of me all the time!! i guess it always is ...
精彩评论