objective-c-literals

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

不想你离开。 提交于 2019-11-28 01:07:46
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? wattson12 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]; this question has a good description of all of the new literals It's the new llvm compiler's literal

Using @[array, of, items] vs [NSArray arrayWithObjects:]

你离开我真会死。 提交于 2019-11-27 15:32:00
Is there a difference between NSArray *myArray = @[objectOne, objectTwo, objectThree]; and NSArray *myArray = [NSArray arrayWithObjects:objectOne, objectTwo, objectThree, nil]; Is one preferred over the other? They are almost identical, but not completely. The Clang documentation on Objective-C Literals states: Array literal expressions expand to calls to +[NSArray arrayWithObjects:count:] , which validates that all objects are non-nil. The variadic form, +[NSArray arrayWithObjects:] uses nil as an argument list terminator, which can lead to malformed array objects. So NSArray *myArray = @

Can the new Clang Objective-C literals be redirected to custom classes?

泄露秘密 提交于 2019-11-27 03:51:41
Although the overloading of @ begins to tread on dangerous territory, I love the addition of the new Objective-C literals in Clang 3.1. Unfortunately the new literals are of limited use to me. Except for instances where code needs to interface with AppKit, I've mostly dropped the use of Foundation classes in favor of my own custom framework (for a variety of reasons; most of which is that I need direct control over the memory allocation patterns used by objects). I could always use some runtime trickery to pass off the newly created object as my custom class (and is what I already have to do

Using @[array, of, items] vs [NSArray arrayWithObjects:]

拟墨画扇 提交于 2019-11-26 17:14:54
问题 Is there a difference between NSArray *myArray = @[objectOne, objectTwo, objectThree]; and NSArray *myArray = [NSArray arrayWithObjects:objectOne, objectTwo, objectThree, nil]; Is one preferred over the other? 回答1: They are almost identical, but not completely. The Clang documentation on Objective-C Literals states: Array literal expressions expand to calls to +[NSArray arrayWithObjects:count:] , which validates that all objects are non-nil. The variadic form, +[NSArray arrayWithObjects:]

Can the new Clang Objective-C literals be redirected to custom classes?

落爺英雄遲暮 提交于 2019-11-26 10:56:39
问题 Although the overloading of @ begins to tread on dangerous territory, I love the addition of the new Objective-C literals in Clang 3.1. Unfortunately the new literals are of limited use to me. Except for instances where code needs to interface with AppKit, I\'ve mostly dropped the use of Foundation classes in favor of my own custom framework (for a variety of reasons; most of which is that I need direct control over the memory allocation patterns used by objects). I could always use some

Compiler error “expected method not found” when using subscript on NSArray

家住魔仙堡 提交于 2019-11-26 09:35:29
问题 I wrote this simple code to try out the new Objective-C literal syntax for NSArray s: NSArray *array = @[@\"foo\"]; NSLog(@\"%@\", array[0]); The first line works fine, but the subscripting results in an error: Expected method to read array element not found on object of type \'NSArray *\' Just wondering if I have done something wrong, or if the literals haven\'t been fully implemented yet. I\'m compiling with Apple LLVM 4.0 and using the iOS 5 SDK. Here\'s a screenshot of the error, too. 回答1

What are the details of “Objective-C Literals” mentioned in the Xcode 4.4 release notes?

泄露秘密 提交于 2019-11-25 23:47:51
问题 I was going through the release notes for Xcode 4.4 and noticed this: LLVM 4.0 Compiler Xcode now includes the Apple LLVM Compiler version 4.0, including the following newObjective-C language features: [...] - Objective-C literals: create literals for NSArray, NSDictionary, and NSNumber, just the same as the literals for NSString I\'m intrigued about this feature. It\'s not entirely clear to me just how literals for NSString work and how one could use them on NSArray , NSDictionary , and