automatic-ref-counting

Swift ARC and blocks

倖福魔咒の 提交于 2019-12-01 05:15:39
I'm trying a simple example as seen here: https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AutomaticReferenceCounting.html#//apple_ref/doc/uid/TP40014097-CH20-XID_88 And this is my code. (Ignore other possible code, this is a empty project with this code written inside an empty UIViewcontroller viewDidLoad) dispatch_async(dispatch_get_main_queue()) { [unowned self] in println(self) } I don't understand why it crashes when I run the pro thread #1: tid = 0x1a796, 0x00284d18 libswiftCore.dylib`_swift_release_slow + 8, queue = 'com.apple

Dangling pointers in objective c - does nil also release memory?

和自甴很熟 提交于 2019-12-01 04:17:21
What I understand is: Memory leaks occur when memory has not been freed or "released" Dangling pointers occur when the pointer is NOT set to nil AND the object is released. my question is: Can setting the object to nil free the memory and clear the pointer reference? i.e. Car *myCar = [[Car alloc] initWithCoolRims: YES]; myCar = nil; //no mem leaks or dang pointers or does the ARC do this: Car *myCar = [[Car alloc] initWithCoolRims: YES]; [myCar release]; myCar = nil; //no mem leaks or dang pointers Thankyou Under ARC For your first example myCar will be set to nil and the newly created Car

Why variable with __weak qualifier retains an object?

拥有回忆 提交于 2019-12-01 04:15:24
问题 Here is my code: extern void _objc_autoreleasePoolPrint(); int main(int argc, const char * argv[]) { NSArray __weak *tmp = nil; @autoreleasepool { NSArray __strong *obj = [[NSArray alloc] init]; NSLog(@"obj &: %p", obj); tmp = obj; NSLog(@"tmp &: %p", tmp); _objc_autoreleasePoolPrint(); } NSLog(@"tmp: %@", tmp); // why not (null) ? return 0; } And console output: 2013-05-01 22:14:32.966 SimpleConsoleObjectiveCApplicationWithARC[40660:f07] obj &: 0x7fedf9403110 2013-05-01 22:14:32.969

Why ARC forbids calls to undeclared methods?

感情迁移 提交于 2019-12-01 04:08:37
问题 When using manual memory management we can write a call to a method which is not declared in the class. What we get during compilation in this case is warning only. This is what Wikipedia states on one of the most distinctive Objective-C features: The Objective-C model of object-oriented programming is based on message passing to object instances. In Objective-C one does not simply call a method; one sends a message. This is unlike the Simula-style programming model used by C++. The

Conditional compilation when using ARC

柔情痞子 提交于 2019-12-01 04:07:46
Is there a way to ask the compiler if ARC is turned on, and then conditionally compile based upon that value? For example, I have a protocol: @protocol ProtocolA @required -(void)protocolMethodOne @optional -(void)protocolMethodTwo; @end If I'm using ARC, I would like to make protocolMethodA optional when using ARC, and required when not using ARC. This is because one of the main reasons for utilizing this method is to dealloc the object instance. With that said, here's what I would like to happen: @protocol ProtocolA #ifdef SOME_ARC_VARIABLE @optional #else @required #endif -(void

Convert to ARC - LLVM compiler 3.0 Error

不问归期 提交于 2019-12-01 03:55:14
问题 I opened up an older project of mine and chose Convert to Objective-C ARC from the Edit/Refactor menu. I am getting the following error: Apple LLVM compiler 3.0 Error Error in format of file: /Users/myUserName/Library/Developer/Xcode/DerivedData/ProjectName-fkjvtdsoypoyrdcedtarbtypupor/Build/Intermediates/ProjectName.build/Debug-iphoneos/ProjectName.build/ProjectName-arc.migrate/remap Is this one of those situations where I need to manually delete some files/folders in Finder and then try it

how to add ARC in between of project

谁都会走 提交于 2019-12-01 01:07:53
I am creating iPhone app and in between I need to use SDWebImage . For this I need to use ARC. Any idea how to add ARC in between in project? Note: In one file I have below content. #if !__has_feature(objc_arc) #error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag #endif Where should I add -fobjc-arc flag? Select Project Form Project Manager | | Targets | | Build Phases | | Compile Sources | | Select File that you Want to crate as ARC. (You can also Select Multiple File name from here) | | Press "ENTER" key | | Popup Box/Window is displayed | | Write here - '

Disable ARC with Xcode 5

戏子无情 提交于 2019-12-01 00:52:20
In versions of Xcode previous to 5, we can disable ARC in the project settings when we create the project. Now ARC is causing this problem for me. With an property list file, for the reading step, the compiler gives me an error: "implicit conversion of 'int' to 'id' is disallowed with ARC". I did not have this problem with the same code with Xcode 4. In my property list file, The keys are numbers and also in my viewController.m When I disallow ARC for the target, the warning persists. I don't see how I can add a compiler flag. The code (with French strings): NSString *error; NSString *rootPath

EXC_BAD_ACCESS on NSManagedObjectContext save method inside NSOperation and ARC, why?

强颜欢笑 提交于 2019-11-30 23:43:08
问题 I have found some problems when saving NSManagedObjectContext inside NSOperation with turned on ARC. Without ARC everything was fine before. It is always gives EXC_BAD_ACCESS during saving. The code looks like this: //on the main thread -(void)someFunc { array = ... //fetching an array of entities from a core data for(SomeEntity * obj in array) { NSSomeOperation * op = [[NSSomeOperation alloc] initWithValue:[obj someField]]; //start an operation } } //NSSomeOperation implementation //... -

C-style array of pointers to Objective-C objects under ARC

妖精的绣舞 提交于 2019-11-30 23:38:04
问题 I have a 2D array of pointers to Objective-C instances to keep track of game objects on a map grid. Now I am transitioning my code to ARC, and Xcode pointed the error. I knew pointers to objects aren't allowed as struct members, but this one caught me (almost) off guard. I understand the rationale behind the ARC constrains, but: I can't afford the overhead of objective-C arrays when looking up objects in the grid, and The objects themselves are already owned by an NSArray ivar defined in the