

Xcode 4.4 adds support for Obj-C literals - BenjieGillam
http://itunes.apple.com/gb/app/xcode/id497799835?mt=12

======
BenjieGillam
See <http://clang.llvm.org/docs/ObjectiveCLiterals.html> for more information,
but some examples from that page:

    
    
      NSNumber *fortyTwo = @42;             // equivalent to [NSNumber numberWithInt:42]
      NSNumber *piDouble = @3.1415926535;   // equivalent to [NSNumber numberWithDouble:3.1415926535]
      NSNumber *yesNumber = @YES;           // equivalent to [NSNumber numberWithBool:YES]
      NSArray *array = @[ @"Hello", NSApp, [NSNumber numberWithInt:42] ];
      NSDictionary *dictionary = @{
          @"name" : NSUserName(),
          @"date" : [NSDate date],
          @"processInfo" : [NSProcessInfo processInfo]
      };
    

This, especially the NSArray/NSDictionary stuff, should make coding in Obj-C
so much faster and more pleasant - well done LLVM team!

PS: Not sure if the object subscripting stuff is supported yet, but that looks
awesome too!

~~~
upinsmoke
Subscripting only on OS X not iOS.

~~~
weiran
You can use them on iOS 5.1 by implementing the methods the subscripts map to
on NSArray and NSDictionary (as well as mutable) in categories.

For NSArray:

    
    
        - (id)objectAtIndexedSubscript:(NSUInteger)index {
            return [self objectAtIndex:index];
        }
    

NSMutableArray:

    
    
        - (void)setObject:(id)object atIndexedSubscript:(NSUInteger)index {
            if (index < self.count){
                if (object)
                    [self replaceObjectAtIndex:index withObject:object];
                else
                    [self removeObjectAtIndex:index];
            } else {
                [self addObject:object];
            }
        }
    

NSDictionary:

    
    
        - (id)objectForKeyedSubscript:(id)key {
            return [self objectForKey:key];
        }
    

NSMutableDictionary:

    
    
        - (void)setObject:(id)object forKeyedSubscript:(id)key {
            [self setObject:object forKey:key];
        }

~~~
puls
The implementation already exists in iOS 5, you just need to make the compiler
happy; a header that declares them is sufficient.

------
steipete
Also see this guide how to use subscripting in Xcode 4.4
[http://petersteinberger.com/blog/2012/using-subscripting-
wit...](http://petersteinberger.com/blog/2012/using-subscripting-with-
Xcode-4_4-and-iOS-4_3/)

------
ashcairo
Is it possible to downgrade back to 4.4? 4.4.1 seems to crash often now when
stepping through my code.

~~~
ashcairo
[https://developer.apple.com/downloads/index.action?name=Xcod...](https://developer.apple.com/downloads/index.action?name=Xcode)

