[TIMOB-12558] iOS: Allow external modules to use ARC
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-04-05T21:23:56.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 3.1.0, 2013 Sprint 03 API, 2013 Sprint 03, Release 3.2.0 |
Components | iOS |
Labels | ARC, qe-closed-3.2.0 |
Reporter | Sindre Sorhus |
Assignee | Blain Hamon |
Created | 2013-02-01T23:28:16.000+0000 |
Updated | 2013-12-11T00:27:08.000+0000 |
Description
The original feature request was for ARC in all of TiMob codebase. This is less ambitious, and just to allow modules that use ARC to interact with Titanium.
{quote}
Automatic Reference Counting (ARC) for Objective-C makes memory management the job of the compiler. By enabling ARC with the new Apple LLVM compiler, you will never need to type retain or release again, dramatically simplifying the development process, while reducing crashes and memory leaks. The compiler has a complete understanding of your objects, and releases each object the instant it is no longer used, so apps run as fast as ever, with predictable, smooth performance.
{quote}
More info [here](http://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/_index.html).
Originally a community pull request. Max added a line. I added snarky comments. It's all good and merged. Unfortunately, the test case is not much more than 'compiles, make sure there's no side effects for Titanium itself' (Spoilers: no change for non-ARC code)
Pull requests https://github.com/appcelerator/titanium_mobile/pull/3838 https://github.com/appcelerator/titanium_mobile/pull/3839
Hi, I'm the original author of this pull request. Thanks for merging this in 3.0.2. I've tried it and compiling works now - thanks! Yet there are lots of warning now about the __bridge. There's an easy workaround for this: (KrollContext.h, Line 156) #if __has_feature(objc_arc) KrollContext *ctx = (__bridge KrollContext*)TiObjectGetPrivate(TiValueToObject(globalContext, value, NULL)); #else KrollContext *ctx = (KrollContext*)TiObjectGetPrivate(TiValueToObject(globalContext, value, NULL)); #endif Alternatively you can also make something like an __arc_bridge and define that to either "" or "__bridge" if you need this more than once.
The following block would be better:
Will close issue after discussion with QE. Please reopen if this becomes a problem again.
Community user in TC-1965 suggests that the __bridge warnings still exist, and that one of the workarounds suggested in the last couple of comments should be implemented. Or alternatively an explanation as to why this was closed. Cheers.
Actually, the better answer would be to move this into a non-inlined function so that it can be better optimized and avoid any conflicts if an old module runs on a newer SDK.
https://github.com/appcelerator/titanium_mobile/pull/3985
Functional Test passed. This is how I tested:
Created Titanium Module Project based on SDK 3.0.2GA. This SDK is not aware of ARC.
Created Titanium Project based on SDK 3.1.0 master branch, which removed the inline function mentioning __bridge (i.e. an ARC construct).
Noted there were no regressions, proving that functional test passed.
Also noted there were 29 compiler warnings.
Rebuild the Titanium project based on SDK 3.2.0GA.
Noted there were 58 compiler warnings. The decrease in the number of compiler warnings is also an improvement.
Tested with 3.1.0.v20130402092426 and it is not working. I get two errors in the following files: TiBuffer.h http://f.cl.ly/items/1D2d1l3p1s3i0p2e2m3A/Screen%20Shot%202013-04-04%20at%2010.07.04%20AM.png KrollCallback.h http://f.cl.ly/items/2O092U2Q0M1Z001E3j1l/Screen%20Shot%202013-04-04%20at%2010.07.42%20AM.png
TiBuffer.h is due to our -(NSNumber*)copy:(id)args (As in copy data in and return how much) with -(void)copy:(id)sender (as in cut, copy, paste). To support arc, we'll have to have a renamed version. KrollCallback.h is due to having code in the header not in the implementation. Guh.
3_1_X PR merged. pending master PR
Testing the PR
Testing Instruction ** Create a new Titanium Module Project for iOS from Studio. ** Open the module project in Xcode. ** click on the projectname on left pane in xcode and in build settings turn on Obj-C Automatic Reference Counting. ** Compile the project. You should see only on failure(That is because of the template. If you remove the dealloc method the project would compile successfully)
Closing ticket as fixed. Verified using Sabil's steps. Tested on: Appcelerator Studio, build: 3.2.0.201312091648 SDK build: 3.2.0.v20131210112451 CLI: 3.2.0-cr Alloy: 1.3.0-cr Xcode: 5.0.2