automatic-ref-counting

ARC forbids Objective-C objects in structs or unions despite marking the file -fno-objc-arc

二次信任 提交于 2019-11-26 09:22:36
问题 ARC forbids Objective-C objects in structs or unions despite marking the file -fno-objc-arc? Why is this so? I had the assumption that if you mark it -fno-objc-arc you don\'t have this restriction. 回答1: If you got this message try __unsafe_unretained. It is only safe, if the objects in the struct are unretained. Example: If you use OpenFeint with ARC the Class OFBragDelegateStrings says this error in a struct. typedef struct OFBragDelegateStrings { NSString* prepopulatedText; NSString*

AVAudioPlayer not playing any sound

不问归期 提交于 2019-11-26 09:19:38
问题 I\'m working on an iOS application that needs to play some sounds using the AVFoundation framework. The workspace structure in Xcode 4 contains two projects: Workspace The application itself (main project) A utility library After building the utility library, it results in a static library which is used in the main application as a framework. So, when trying to play a sound inside the main application by using the code below, it works as expected. NSString *resourcePath = [[NSBundle

ARC - The meaning of __unsafe_unretained?

孤街醉人 提交于 2019-11-26 09:15:04
问题 Just want to make sure that I got it right: Do I need to __unsafe_unretain objects that I don\'t own? If an object is __unsafe_unretained Do I need to use assign in the @property ? Does that mean that the object is not retained, and just refers to the object I assign to? When would I want to use it except of delegates? Is that an ARC thing or was it in use before? 回答1: The LLVM Compiler 3.0 introduces four new ownership qualifiers: __strong , __autoreleasing , __unsafe_unretained , and __weak

Should I declare variables in interface or using property in objective-c arc?

北慕城南 提交于 2019-11-26 09:07:11
问题 approach 1: @interface MyController : UIViewController { UILabel *myText; } @property (nonatomic, strong) UILabel *myText; approach 2: @interface MyController : UIViewController @property (nonatomic, strong) UILabel *myText; approach 3: @interface MyController : UIViewController { UILabel *myText; } I have read some articles talking about this kind of stuff but I still do not really realize which approach I have to adopt. I also found that someone said approach 1 is a old way so I would like

NSString to CFStringRef and CFStringRef to NSString in ARC?

梦想的初衷 提交于 2019-11-26 09:05:49
问题 I am trying to understand the correct way of getting an NSString from a CFStringRef in ARC? Same for going the opposite direction, CFStringRef to NSString in ARC? What is the correct way to do this without creating memory leaks? 回答1: Typically NSString *yourFriendlyNSString = (__bridge NSString *)yourFriendlyCFString; and CFStringRef yourFriendlyCFString = (__bridge CFStringRef)yourFriendlyNSString; Now, if you want to know why the __bridge keyword is there, you can refer to the Apple

In which situations do we need to write the __autoreleasing ownership qualifier under ARC?

℡╲_俬逩灬. 提交于 2019-11-26 08:58:25
问题 I\'m trying to complete the puzzle. __strong is the default for all Objective-C retainable object pointers like NSObject, NSString, etc.. It\'s a strong reference. ARC balances it with a -release at the end of the scope. __unsafe_unretained equals the old way. It\'s used for a weak pointer without retaining the retainable object. __weak is like __unsafe_unretained except that it\'s an auto-zeroing weak reference meaning that the pointer will be set to nil as soon as the referenced object is

Under automatic reference counting, why are retain, release, and dealloc not allowed?

♀尐吖头ヾ 提交于 2019-11-26 08:20:19
问题 When trying to use -retain , -release , and -dealloc while building my application using automatic reference counting in Xcode 4.2, I get an error like the following: Automatic Reference Counting forbids explicit message send of \'dealloc\' Why am I seeing this error? Are -retain , -release , and -dealloc no longer allowed under automatic reference counting? 回答1: Basically: When using ARC, it's all or nothing. Either the compiler is managing all of the retains/releases/deallocs for you, or it

Does ARC work with Core Graphics objects?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 08:11:14
问题 I recently started a new project using Automatic Reference Counting (ARC). When I assigned the contents of a CALayer: UIView* view = ... UIImage* image = ... view.layer.contents = image.CGImage I got an error Implicit conversion of a non-Objective-C pointer type \'CGImageRef\' to \'id\' is disallowed with ARC Simply casting the CGImageRef to id hides the error, but I was wondering if the ARC still functions correctly then? 回答1: You should really check out the ARC videos from WWDC 2011. They

Is ARC really supported in iOS 4? The iOS 4.2 SDK is missing ARC-related symbols at linking time

落花浮王杯 提交于 2019-11-26 08:08:41
问题 I\'ve read and heard since ARC was first announced that it was a compile-time thing and would be backwards-compatible with iOS 4. I have successfully refactored my project to ARC using Xcode 4.2\'s automatic refactoring, and when compiled against the iOS 5.0 SDK, it works fine. However, if I try to compile against my iOS 4.2 SDK, it fails at link time, missing the following symbols: _objc_retainAutoreleaseReturnValue _objc_autoreleaseReturnValue _objc_storeStrong _objc_retain _objc_release

@autoreleasepool without ARC?

你离开我真会死。 提交于 2019-11-26 07:35:22
问题 I\'m new to Xcode 4.2, and I\'m not yet fully up to speed on ARC. However, I did read that @autoreleasepool replaces the manual use of autorelease pools and does some special magic under the hood to play nice with ARC. Yet, when I start a new project in Xcode 4.2 specifically with the ARC option turned off I still get @autoreleasepool statements in the template code. What\'s the deal here? 回答1: From http://clang.llvm.org/docs/AutomaticReferenceCounting.html#autoreleasepool: @autoreleasepool