automatic-ref-counting

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

社会主义新天地 提交于 2019-11-27 00:24:11
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. 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* originalMessage; } OFBragDelegateStrings; to typedef struct OFBragDelegateStrings { __unsafe_unretained NSString*

cast of Objective-C pointer type 'NSString *' to C pointer type 'CFStringRef' (aka 'const struct __CFString *') requires a bridged cast

会有一股神秘感。 提交于 2019-11-27 00:20:55
问题 When converting an Objective-C program to a Objective-C ARC, I get the error: "cast of Objective-C pointer type 'NSString *' to C pointer type 'CFStringRef' (aka 'const struct __CFString *') requires a bridged cast " The code is as follows: - (NSString *)_encodeString:(NSString *)string { NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)string, // this is line in error NULL, (CFStringRef)@";/?:@&=$+{}<>,", kCFStringEncodingUTF8); return [result

With ARC, what's better: alloc or autorelease initializers?

旧巷老猫 提交于 2019-11-27 00:19:52
Is it better (faster & more efficient) to use alloc or autorelease initializers. E.g.: - (NSString *)hello:(NSString *)name { return [[NSString alloc] initWithFormat:@"Hello, %@", name]; } OR - (NSString *)hello:(NSString *)name { return [NSString stringWithFormat:@"Hello, %@", name]; // return [@"Hello, " stringByAppendingString:name]; // even simpler } I know that in most cases, performance here shouldn't matter. But, I'd still like to get in the habit of doing it the better way. If they do exactly the same thing, then I prefer the latter option because it's shorter to type and more readable

AVAudioPlayer not playing any sound

泄露秘密 提交于 2019-11-27 00:12:44
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 mainBundle] resourcePath]; NSString *path = [NSString stringWithFormat:@"%@/sound.mp3", resourcePath]; NSURL *url

Swift Managing Memory

老子叫甜甜 提交于 2019-11-27 00:11:45
问题 This question was cleaned up and the important info moved to the answer below. I have some questions about memory management. I am building a photo editing app. So keeping memory usage low is important. Also I am not going to post code because I do not have a big memory leak when doing one specific thing. I just lose a couple of KB's/MB's with everything that happens. And going over tens of thousands of lines of code to find kilobytes is no fun ;) my app uses core data, lots of cifilter stuff

Should an NSString property under ARC be strong or copy?

此生再无相见时 提交于 2019-11-27 00:09:42
问题 When not compiling with ARC, it is recommended to use copy properties for data types such as NSString . I could not find proper documentation on the use of copy in ARC mode. Can someone tell me what's applicable for ARC? 回答1: It is still recommended to copy because you want to avoid something passing a mutable string and then changing it without you knowing. A copy guarantees that the string you have will not change. 回答2: Copying and ARC are orthogonal: you make copies of mutable objects to

Dealloc not being called on ARC app

情到浓时终转凉″ 提交于 2019-11-27 00:06:35
问题 I have a UIViewController that is pushed onto a container controller and then popped off, and using the allocations instrument, I can see that the view controller is destroyed afterwards. However, a breakpoint in the controller's dealloc is never reached. Does anyone know why dealloc isn't called? Is it possible for ARC to destroy an object without calling dealloc? Also, I've disabled NSZombies (some have said that can cause dealloc not to fire). Edit: Dealloc doesn't do much, just prints to

How do I verify reference count in ARC mode?

谁说我不能喝 提交于 2019-11-26 23:57:13
问题 I used to verify that some of my variables had the expected retain count using [myVar retainCount] under the debugger, especially for var that did not have a custom dealloc. How do you do this in ARC mode? How do you ensure that there are no memory leaks? Note: I understand that ARC should handle this for me, but life is far from being perfect, and in real life you have objects that are sometimes allocated by third party libraries (using retain?) and never deallocated. Image that I do this:

ARC - The meaning of __unsafe_unretained?

我的未来我决定 提交于 2019-11-26 23:27:37
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? Brad Larson The LLVM Compiler 3.0 introduces four new ownership qualifiers: __strong , __autoreleasing , __unsafe_unretained , and __weak . The first three are available even outside ARC, as per the specification . As Joshua indicates

How do I know whether the compiler has ARC support enabled?

ε祈祈猫儿з 提交于 2019-11-26 23:04:19
问题 I need to write a lib in my iOS app. The statement should be pre-process define as : myObject ... #if ARC // do nothing #else [myObject release] #endif or run-time process as: if (ARC) { // do nothing } else { [myObject release]; } How can I do? Please help me! Thank you. 回答1: You can use __has_feature , like so: #if __has_feature(objc_arc) // ARC is On #else // ARC is Off #endif If you want to also build with GCC (Apple's GCC does not support ARC), you may also need the following to