automatic-ref-counting

Is it possible to enable non-arc files without adding “fno-objc-arc” in compile sources of Build Phases?

百般思念 提交于 2019-12-12 16:27:31
问题 Is it possible to somehow handle the non-arc files without adding fno-objc-arc to the compile sources in the build phases? More specifically, is there any way to add fno-objc-arc somewhere in the code? The reason is, I want to open source one of my library which uses non-arc files and I don't want people who use my library to manually add fno-objc-arc . Just drag and drop... 回答1: No. But if you look at what some libraries do, they write macros that will conditionally call the MRC calls, e.g.,

updating to ARC errors

让人想犯罪 __ 提交于 2019-12-12 16:09:51
问题 I am trying to update a project to ARC. Though I've seen a few posts on updating to ARC, none of the posts I've seen handle this specific issue. I've got multiple errors, most saying: ARC Issue Pointer to non-const type 'id' with no explicit ownership pointing to line CCARRAY_FOREACH(children_, item) in the CCMenu.m class. Please help. Updated: After restarting Xcode the above issue is no longer found at CCARRAY_FOREACH(children_, item) but was found in the ccCArray.h class at the lines I've

ViewController gets deallocated which leads to crash

左心房为你撑大大i 提交于 2019-12-12 12:22:33
问题 I have a view in my storyboard which I assigned an identifier called "MainView". However if I add its view to the subview, everything that follows produces a crash (e.g. pressing a button) MainViewController *mvc = [self.storyboard instantiateViewControllerWithIdentifier:@"MainView"]; [self.view addSubview:mvc.view]; This is the action triggered by the button : (MainViewController.h) -(IBAction)showUsername:(id)sender{ [testLabel setText:@"username"]; } and the crash log : -

why is UIWebViewDelegate assign instead of weak?

被刻印的时光 ゝ 提交于 2019-12-12 11:34:07
问题 Normally all delegates throughout the UIKit/Foundation frameworks are weak except UIWebView. UIWebView's delegate @property(nonatomic, assign) id< UIWebViewDelegate > delegate; I am interested because this has caused a crash several time in my application when you forgot to nil out delegate while dismissing the UIWebView's ViewController. Normally you don't expect something like this, so there might be specific reason why this isn't set to weak by default. 回答1: Suppose if the

Objective-C SCNetworkReachabilityContext ARC conversion

这一生的挚爱 提交于 2019-12-12 10:52:12
问题 While converting an app to use Automatic Reference Counting I came across this error: SCNetworkReachabilityContext context = {0, self, NULL, NULL, NULL}; Implicit conversion of an Objective-C pointer to 'void *' is disallowed with ARC This fixes the compiler error, but gives a warning: SCNetworkReachabilityContext context = {0, objc_unretainedPointer(self), NULL, NULL, NULL}; How to get rid of this warning? Initializing 'void *' with an expression of type 'objc_objectptr_t' (aka 'const void *

Is it necessary to deallocate an AutoreleasingUnsafeMutablePointer? If so, how?

江枫思渺然 提交于 2019-12-12 10:43:38
问题 With ARC, I can just set all of an object's strong references to nil to deallocate it. With an UnsafePointer or UnsafeMutablePointer , I need to manage its memory explicitly: let buffer = sizeof(Int8) * 4 var ptr = UnsafeMutablePointer<Void>.alloc(buffer) defer { ptr.destroy() ptr.dealloc(someVal) ptr = nil } But the documentation is ambiguous for AutoreleasingUnsafeMutablePointer objects. I cannot explicitly call destroy or dealloc on a AutoreleasingUnsafeMutablePointer . var ptr:

Cache that can purge unused objects by demand

陌路散爱 提交于 2019-12-12 10:15:25
问题 I need to create a cache, that could save some objects, but then, at some point when I have memory warning or simply user wants it, I would like to purge all instances that are used only in the cache at the moment. In other words: I need to deinit objects with ARC count == 1. The problem is that based on my googling of this project, it is not possible in pure Swift to get the retain count of an object. From my experience I see that it is not possible by default in Swift. In objective-c I was

App crashes when using __bridge for CoreGraphics gradient on ARC

☆樱花仙子☆ 提交于 2019-12-12 09:56:57
问题 I'm creating an application for iOS 5 and I'm drawing some gradients. The following gradient code I've always used before ARC, but now it does not work on my device anymore (however, it works on the simulator) when I use it several times (so I suppose it's a memory management issue). Anyways, here's the code: CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGFloat locations[] = { 0.0, 1.0 }; NSArray *colors = [NSArray arrayWithObjects:(__bridge id)startColor, (__bridge id)endColor

difference between ARC and MRC

只谈情不闲聊 提交于 2019-12-12 09:37:47
问题 I am confused with Apple material. In 3 ways we manage the memory, they are : automatic referance counting. manual reference counting. garbage colletion. My doubt is what is the difference between automatic reference counting and manual referance counting. Can someone explain me ? 回答1: In ARC you don't have to release/autorelease the memory allocated by you where as in case of manual you have to take care of this. e.g. manual case -(void)someMethod { NSMutableArray *arr = [[NSMutableArray

Using ARC and UITableViewController is throwing Observation info was leaked, and may even become mistakenly attached to some other object

一个人想着一个人 提交于 2019-12-12 09:28:20
问题 I cannot seem to figure out what to do to resolve this error that I am receiving. I click on a cell which pops a new UITableViewController onto the stack. Once I hit the back button on the Navigation UI when in this controller I receive this error in the debugger but there doesn't seem to be any issue with the app as it doesn't crash or hang and still works fine. An instance 0x79a8400 of class UITableView was deallocated while key value observers were still registered with it. Observation