objective-c-literals

What does it mean when you put an @ before an integer in Objective-C?

邮差的信 提交于 2020-01-02 04:37:21
问题 What does it mean when you put an @ before an integer in Objective-C? Like so: @4 回答1: It is the NSNumber literal. A shortcut for this: [NSNumber numberWithInt:4]; 来源: https://stackoverflow.com/questions/17629874/what-does-it-mean-when-you-put-an-before-an-integer-in-objective-c

Is there any way to get the neat Objective-C literal indexing feature in Xcode 4.4?

筅森魡賤 提交于 2019-12-28 11:57:33
问题 I read all about the new Objective-C literals, and used Xcode to convert my old code, but the indexing code didn't change. I changed it by hand but then it wouldn't compile. I saw a post that said we have to wait until iOS 6, but I want the indexing NOW! Is there any solution? 回答1: Well, there is a way to do it! Add the indexing methods as a category to NSArray and NSDictionary, and you can get the feature for most of the classes you'd want it for. You can read up on ObjectiveC literals here.

Is there any way to get the neat Objective-C literal indexing feature in Xcode 4.4?

做~自己de王妃 提交于 2019-12-28 11:57:05
问题 I read all about the new Objective-C literals, and used Xcode to convert my old code, but the indexing code didn't change. I changed it by hand but then it wouldn't compile. I saw a post that said we have to wait until iOS 6, but I want the indexing NOW! Is there any solution? 回答1: Well, there is a way to do it! Add the indexing methods as a category to NSArray and NSDictionary, and you can get the feature for most of the classes you'd want it for. You can read up on ObjectiveC literals here.

Is there some literal dictionary or array syntax in Objective-C?

拥有回忆 提交于 2019-12-27 12:20:45
问题 It's always been possible to create NSArrays (and NSDictionaries/NSNumber) with vararg method calls, like: [NSArray arrayWithObjects: @"a", @"b", @"c", nil]; Can these be created with in-line literals in a new improvement to LLVM and Clang? 回答1: With this change to the LLVM codebase, Apple has added a new syntax for literals in upcoming versions of the Clang compiler. Before, arrays were created using a C-based array and were converted on the fly into Objective-C objects, such as: NSArray*

Is there some literal dictionary or array syntax in Objective-C?

耗尽温柔 提交于 2019-12-27 12:18:53
问题 It's always been possible to create NSArrays (and NSDictionaries/NSNumber) with vararg method calls, like: [NSArray arrayWithObjects: @"a", @"b", @"c", nil]; Can these be created with in-line literals in a new improvement to LLVM and Clang? 回答1: With this change to the LLVM codebase, Apple has added a new syntax for literals in upcoming versions of the Clang compiler. Before, arrays were created using a C-based array and were converted on the fly into Objective-C objects, such as: NSArray*

Creating an NSMutableArray with a literal via mutableCopy or arrayWithArray: [duplicate]

眉间皱痕 提交于 2019-12-22 03:41:26
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: Is literal creation of an NSMutableDictionary less efficient than the class helper method? According to the WWDC video that introduces ObjectiveC literals, NSMutableArray s can be initialized like so: [NSMutableArray arrayWithArray:@[]]; but what if we were to do it like this: [@[] mutableCopy]; I know that one is initializing the array, and the other is just providing a shallow copy; thus the memory

What kind of object does @[obj1, obj2] create?

六眼飞鱼酱① 提交于 2019-12-17 16:46:16
问题 I came across the following: NSArray *array = @[object1, object2]; It seems to be creating an NSArray , but is this array instance an autoreleased object, or must I release it? 回答1: This is a new collection literal available in the compiler that ship with xcode 4.4 and above @[object1, object2]; is equivalent to [NSArray arrayWithObjects:object1, object2, nil]; so yes, it is an autoreleased object, if you need this to be retained, you can do myRetainedArray = [@[object1, object2] retain];

Objective-C at sign and curly braces, @{ … } what does it mean?

本小妞迷上赌 提交于 2019-12-11 01:23:30
问题 I have this line in Objective-C. NSMutableArray *mutableArray; [mutableArray addObject:@{ @"Something" : aObject, @"Otherthing" : anotherObject }]; What does the @{ ... } part do exactly? It is an object, but it seems to create some kind of key, value pair on the fly. 回答1: It is creating NSDictionary object as you said. Syntax is simple NSDictionary* dictionary = @{key: object, key: object}; In your example, keys are objects of NSString class. It is important to remember that dictionary

Is there NSMutableDictionary literal syntax to remove an element?

半腔热情 提交于 2019-12-08 21:18:01
问题 There is a literal syntax to add object and change object in an NSMutableDictionary, is there a literal syntax to remove object? 回答1: Yes, but... :-) This is not supported by default, however the new syntax for setting dictionary elements uses the method setObject:forKeyedSubscript: rather than setObject:forKey: . So you can write a category which replaces the former and either sets or removes the element: @implementation NSMutableDictionary (RemoveWithNil) - (void) setObject:(id)obj

Difference between @[] and [NSArray arrayWithObjects:] [duplicate]

落花浮王杯 提交于 2019-12-06 23:52:04
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Should I prefer to use literal syntax or constructors for creating dictionaries and arrays? Is there any difference between: NSArray *array = @[@"foo", @"bar"]; and NSArray *array = [NSArray arrayWithObjects:@"foo", @"bar", nil]; Is one of those more stable, faster, or anything else? 回答1: This documentation doesn't mention anything about efficiency directly, but does mention that NSArray *array = @[@"foo", @"bar