0

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 implementations. 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...

smile.al.d.way
  • 361
  • 5
  • 17
  • I don't know the answer to your question, but if I were you, I would start by trying to understand why it is that the [super init] call within A is not calling B's initializer. In particular, suppose you set a breakpoint in your debugger just before that call, then step into it. What happens? – William Jockusch Nov 12 '10 at 21:29
  • The simulator and the device also use different versions of the runtime. This can also cause some fun issues at times. – Joshua Weinberg Nov 12 '10 at 22:33
  • To really clean all targets, use the finder to delete your build directory. – William Jockusch Nov 12 '10 at 22:38
  • @william - yea i tried stepping in from A's int but it didn't step into B's int. Also thanks others for the advices specially @Joe - i didn't really knew that stuff! Actually, I have figured out the actual problem now but no solutions yet - please see above my updated Question – smile.al.d.way Nov 15 '10 at 16:35
  • @Joe - That is incorrect. LLVM works for both Simulator and device, although the 4.1 SDK had a bug that required you to add a compiler flag to prevent some compile-time errors. See this question for more on that: http://stackoverflow.com/questions/3677879/strange-issue-after-upgrading-to-ios-4-1-sdk – Brad Larson Nov 16 '10 at 01:55

2 Answers2

0

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 ...

smile.al.d.way
  • 361
  • 5
  • 17
0

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.

Community
  • 1
  • 1
Brad Larson
  • 170,088
  • 45
  • 397
  • 571