Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift with no ARC

Is it possible to write apps using manual memory management (instead of automatic reference counting) using SWIFT?

Can I call retain and release using Swift?

like image 945
YogevSitton Avatar asked Aug 28 '14 06:08

YogevSitton


People also ask

Can we write Swift code without ARC?

No you can't.

What is the problem with ARC in Swift?

Because a weak reference doesn't keep a strong hold on the instance it refers to, it's possible for that instance to be deallocated while the weak reference is still referring to it. Therefore, ARC automatically sets a weak reference to nil when the instance that it refers to is deallocated.

How do I turn off ARC in Xcode?

You can disable ARC for a specific class using the -fno-objc-arc compiler flag for that class. In Xcode, in the target Build Phases tab, open the Compile Sources group to reveal the source file list. Double-click the file for which you want to set the flag, enter -fno-objc-arc in the pop-up panel, then click Done.

Does Objective-C support ARC?

Automatic Reference Counting (ARC) is a memory management option for Objective-C provided by the Clang compiler. When compiling Objective-C code with ARC enabled, the compiler will effectively retain, release, or autorelease where appropriate to ensure the object's lifetime extends through, at least, its last use.


1 Answers

You can call retain and release on Unmanaged<T> values. Unmanaged is basically object pointers that are outside of ARC management. But you would have to convert to managed pointers to interact with Cocoa APIs.

But you wouldn't want to do this unless in exceptional circumstances. And a project that isn't converted to ARC isn't such a situation.

like image 118
newacct Avatar answered Sep 21 '22 11:09

newacct