Re: NSArray's objectAtIndex compiles to objectAtIndexedSubscript?
Re: NSArray's objectAtIndex compiles to objectAtIndexedSubscript?
- Subject: Re: NSArray's objectAtIndex compiles to objectAtIndexedSubscript?
- From: Greg Parker <email@hidden>
- Date: Fri, 07 Mar 2014 11:42:57 -0800
On Mar 7, 2014, at 8:50 AM, Kyle Sluder <email@hidden> wrote:
> On Mar 7, 2014, at 4:54 AM, Bill Cheeseman <email@hidden> wrote:
>>
>> My code calls -[NSArray objectAtIndex:]. I compile it with Xcode 5.0.2 on OS X 10.9.x Mavericks in a project with the target's Base SDK set to 10.9 and the OS X Deployment Target set to OS X 10.7. It works fine when I run it on OS X 10.9 or OS X 10.8.
>>
>> However, when I run it on Mac OS X 10.7 Lion, I get a runtime error claiming it encountered an invalid argument, namely, the unrecognized selector -objectAtIndexedSubscript:. The NSArray Class Reference notes that -objectAtIndexedSubscript: is available only in OS X 10.8 and later, and that it is "identical to objectAtIndex:". Of course, -objectAtIndex: still exists in the 10.9 API, and it is not marked as deprecated.
>>
>> It appears, therefore, that the compiler generated a call to -objectAtIndexedSubscript: even though my source specifies -objectAtIndex: and a deployment version of 10.7.
>>
>> Has anyone else encountered this? -- I don't find anything in my searches. It seems like a serious bug that would have cropped up for practically everybody.
>
> -objectAtIndexedSubscript: is what the compiler generates when it sees square-bracket indexing syntax applied to an NSArray:
>
> NSArray *a = …;
> foo(a[0]); // generates call to -objectAtIndexedSubscript:
>
> It’s unfortunate that the compiler doesn’t catch that you’re targeting 10.7, where this method does not exist, and prevent such syntax.
The arclite glue library is supposed to add that method at runtime if it does not exist.
Perhaps arclite is not being linked in somehow? The machinery for linking arclite is complicated and I forget what it is supposed to look like in your build transcript.
Aaron Tuller wrote:
> According to this:
>
> https://developer.apple.com/library/mac/releasenotes/ObjectiveC/ObjCAvailabilityIndex/index.html
>
> subscripting works back to 10.6 and requires the modern runtime. Is this by any chance a 32-bit app?
Object subscripting is supposed to be a compiler error on 32-bit Mac.
--
Greg Parker email@hidden Runtime Wrangler
_______________________________________________
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