What kind of object does @ create?
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?
- Is literal creation of an NSMutableDictionary less efficient than the class helper method?
- What are the details of “Objective-C Literals” mentioned in the Xcode 4.4 release notes?
- Creating an NSMutableArray with a literal via mutableCopy or arrayWithArray:
- Compiler error “expected method not found” when using subscript on NSArray
- Using @ vs
- Can the new Clang Objective-C literals be redirected to custom classes?
2 Solutions Collect From Internet About “What kind of object does @ create?”
This is a new collection literal available in the compiler that ship with xcode 4.4 and above
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 for creating an array. The compiler changes this to:
NSArray *array = [NSArray arrayWithObjects: object1,object2,nil];
So it is returning an autoreleased object.
A Google search brought up further info:
- How to handle YouTube video events (started, finished, etc) in uiwebview iOS
- How can I detect screen lock/unlock events on the iPhone?
- Cannot force unwrap value of non-optional type: Avoid “Optional()”
- Implementing NSTimer into Code – Swift
- iOS Rolling out app updates. Keeping user data intact when DB update required
- How to iterate all the UIViewControllers on the app
- Find if user is in a call or not?
- Objective C – How to create rtf from NSAttributedString
- Make button hyperlink Swift
- Properly Using Firebase Cloud Functions and Stripe
- Swift NSURLConnection sendSynchronousRequest
- How to delete single characters in an UITextView
- Integrate unity app to existing iOS app
- Map view is not loading with PhoneGap
- Running Ionic 3 app on iPhone throws error: 2 duplicate symbols for architecture arm64