• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
initWithObject Confusion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

initWithObject Confusion


  • Subject: initWithObject Confusion
  • From: John Nairn <email@hidden>
  • Date: Thu, 8 Apr 2010 14:05:37 -0700

How is this possible?

I wrote code in Snow Leopard to create an array with a single object using

     NSArray *myArray = [ [NSArray alloc] initWithObject:oneObject ] ;

and it worked fine. When it crashed in either Leopard or Tiger, I went to NSArray documentation and found out that it does not have the method initWithObject. Once I found that out, it was easy to fix with the proper

NSArray *myArray = [ [NSArray alloc] initWithObjects:oneObject ,nil] ;

But, the remaining questions are:

1. Why would the initWithObject: compile in the first place? (perhaps because one of my custom classes defines an initWithObject: method)

2. Even if it compiles, how can it run in Snow Leopard when there is no initWithObject: selector for NSArray (or at least according to the NSArray docmentation there isn't one)?

---------------
John Nairn (1-541-737-4265, FAX:1-541-737-3385)
Professor and Richardson Chair
Web Page: http://www.cof.orst.edu/cof/wse/faculty/Nairn/
FEA/MPM Web Page: http://oregonstate.edu/~nairnj




_______________________________________________

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


  • Follow-Ups:
    • Re: initWithObject Confusion
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: What gets automatically localized?
  • Next by Date: Re: initWithObject Confusion
  • Previous by thread: Re: CFRunLoopStop exception
  • Next by thread: Re: initWithObject Confusion
  • Index(es):
    • Date
    • Thread