I'm starting to add Swift files to a very large, legacy Objective-C project that doesn't use ARC.
When I compile the project, I get warnings for every property emitted in the ProjectName-Swift.h
bridge header:
It seems like Swift is emitting ARC-based Objective-C code.
Is this a limitation/bug in this particular release of Swift, or is Swift designed to work only with ARC code?
Objective-C has a superior runtime compared to Swift. It's probably going to be several years before Swift can catch up. If you're using powerful SDKs, Objective-C is also your best option here as well. I'd still recommend that new developers start off learning Swift.
Swift is a successor to both the C and Objective-C languages. It includes low-level primitives such as types, flow control, and operators. It also provides object-oriented features such as classes, protocols, and generics, giving Cocoa and Cocoa Touch developers the performance and power they demand.
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.
You can mix ARC and non-ARC code. All ARC-compiled code does is manage its memory automatically to the user. You should enable ARC for your project and then disable ARC for individual files using -fno-objc-arc
or enable ARC for just Swift files using -fobjc-arc
(this may not be necessary as the compiler may automatically be adding it). Swift code is eventually compiled to use the same Objective C runtime, and ARC calls inserted by the compiler are the same as in Objective C. After compilation, ARC and non-ARC code behave the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With