Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8841771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:48:13+00:00 2026-06-14T10:48:13+00:00

Is it possible to access NSArray’s objects using [idx]? I have a standard library

  • 0

Is it possible to access NSArray’s objects using [idx]? I have a standard library that uses [] style indexing and I don’t want to rewrite the whole library to suit ObjC’s objectAtIndex: method.

As in, NSArray *obj = [NSArray ...]; id item = obj[0];

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:48:15+00:00Added an answer on June 14, 2026 at 10:48 am

    The accepted answer (whilst true at the time) is now out of date. As of Xcode 4.5, you can now set and get NSArray elements using:

    id object = array[5]; // equivalent to [array objectAtIndex:5];
    mutableArray[5] = object; // equivalent to [mutableArray replaceObjectAtIndex:5 withObject:object];
    

    You can also do the same for NSDictionaries using:

    id object = dict[@"key"]; // equivalent to [dict objectForKey:@"key"];
    mutableDict[@"key"] = object; // equivalent to [mutableDict setObject:object forKey:@"key"];
    

    Even cooler, you can now create array and dictionary objects using JSON-like syntax:

    NSArray *array = @[@"value1", @"value2"]; // equivalent to [NSArray arrayWithObjects:@"value1", @"value2", nil];
    NSDictionary *dict = @{@"key1":@"value1", @"key2":@"value2"}; // equivalent to [NSDictionary dictionaryWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];
    

    And in a similar vein, boxed values like NSNumber can now be written in a shorthand syntax:

    NSNumber *intNumber = @5; // equivalent to [NSNumber numberWithInteger:5];
    NSNumber *boolNumber = @YES; // equivalent to [NSNumber numberWithBool:YES];
    NSNumber *someNumber = @(variable); // equivalent to [NSNumber numberWithWhatever:variable];
    

    EDIT:

    Far more detailed answer than mine here: What are the details of "Objective-C Literals" mentioned in the Xcode 4.4 release notes?

    EDIT 2:

    To be clear, though this feature wasn’t added until Xcode 4.5, it works on iOS 4.3 and above, so you don’t have to avoid using this if you need to support older iOS versions.

    EDIT 3:

    For the sake of pedantic precision, it works on Apple LLVM compiler version 4.1 and above. AKA the version that shipped with Xcode 4.5.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app (using retain/release, not GC) that maintains an NSArray instance variable,
is is possible to access objects using variables in a FOR statement? Say i
Is it possible to access the properties of objects in xCode console? If I
Is it possible to access an XML section / node using an attribute value
Possible Duplicate: Access to file download dialog in Firefox I'm using selenium and firefox
Is it possible to access a temporary column that was defined in a query
Possible Duplicate: Access the first property of an object I have a hash h
Does it possible to access microphone or Webcam using Visual Basic Scripting ? i
Possible Duplicate: Access x86 COM from x64 .NET I have a COM object which
Possible Duplicate: Access array returned by a function in php I have a function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.