[TIMOB-17887] iOS: Add Swift modules support
GitHub Issue | n/a |
---|---|
Type | Epic |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2018-12-14T18:52:20.000+0000 |
Affected Version/s | Release 7.1.0 |
Fix Version/s | Release 8.0.0 |
Components | iOS |
Labels | ios, modules, swift |
Reporter | Ingo Muschenetz |
Assignee | Hans Knöchel |
Created | 2014-10-22T20:36:00.000+0000 |
Updated | 2019-05-27T20:14:25.000+0000 |
Description
It is not currently possible to add Swift code to a Titanium module.
Steps to reproduce:
ti create -n ti.test -p ios --id ti.test -t module -url "http://test.com" -d .
Open up the project in Xocde. Confirm it builds.
Add a Swift file and accept the addition of a “bridging header".
Attempt to build. It then prompts to update the minimum target version from 4.0 to 7.0
Build and get the following error:
Libtool build/ti.test.build/Release-iphoneos/ti.test.build/Objects-normal/arm64/libTiTest.a normal arm64
cd /Users/ingo/Documents/ti.test/iphone
export IPHONEOS_DEPLOYMENT_TARGET=7.0
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Users/ingo/Documents/adt-bundle-mac-x86/sdk/platform-tools:/Users/ingo/Documents/adt-bundle-mac-x86/sdk/tools:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only arm64 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -L/Users/ingo/Documents/ti.test/iphone/build/Release-iphoneos -filelist /Users/ingo/Documents/ti.test/iphone/build/ti.test.build/Release-iphoneos/ti.test.build/Objects-normal/arm64/TiTest.LinkFileList -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos -Xlinker -force_load -Xlinker /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphoneos.a -Xlinker -add_ast_path -Xlinker /Users/ingo/Documents/ti.test/iphone/build/ti.test.build/Release-iphoneos/ti.test.build/Objects-normal/arm64/TiTest.swiftmodule -framework Foundation -o /Users/ingo/Documents/ti.test/iphone/build/ti.test.build/Release-iphoneos/ti.test.build/Objects-normal/arm64/libTiTest.a
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `X' in: -Xlinker
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-sacLT] [-no_warning_for_no_symbols]
Usage: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -dynamic [-] file [...] [-filelist listfile[,dirname]] [-arch_only arch] [-o output] [-install_name name] [-compatibility_version #] [-current_version #] [-seg1addr 0x#] [-segs_read_only_addr 0x#] [-segs_read_write_addr 0x#] [-seg_addr_table <filename>] [-seg_addr_table_filename <file_system_path>] [-all_load] [-noall_load]
This is the error reported here: http://stackoverflow.com/questions/24020986/error-when-compiling-a-static-library-using-swift-unknown-option-character-x
And this is because you can't built a static library using Swift:
http://openradar.appspot.com/radar?id=5536341827780608
It may be possible to get around this:
http://andelf.github.io/blog/2014/06/25/write-swift-module-with-swift-cont/
Generate .swiftmodule .swiftdoc
xcrun swift -sdk $ (xcrun --show-sdk-path --sdk macosx) SwiftyJSON.swift -emit-library -emit-module -module-name SwiftyJSON -v -o libswiftSwiftyJSON.dylib -module-link-name swiftSwiftyJSON
Generate .o
xcrun swift -sdk $ (xcrun --show-sdk-path --sdk macosx) -c SwiftyJSON.swift -parse-as-library -module-name SwiftyJSON -v -o SwiftyJSON.o
Generate .a
ar rvs libswiftSwiftyJSON.a SwiftyJSON.o
We also need to account for Swift based dylib files. Frameworks are already being developed using these and wrapping them for titanium modules is next to imposable with the current build tools.
An example of an SDK using swift dylibs would be https://secure.paymentech.com/developercenter/mobilesdk/ios/?WT.mc_id=adc001_sdk
Does Apple's announcement of Swift 1.2 address this problem, or are static libraries a different beast? From page 4 of http://adcdownload.apple.com//Developer_Tools/Xcode_6.3_beta/Xcode_6.3_beta_Release_Notes.pdf ... “static” methods and properties are now allowed in classes (as an alias for “class final”). You are now allowed to declare static stored properties in classes, which have global storage and are lazily initialized on first access (like global variables). Protocols now declare type requirements as “static” requirements instead of declaring them as “class” requirements. (17198298)
[~pragmateq] No -- different "static."
is there any news about this? I mean including swift code directly in a titanium module? I thought Appcelerator declared it was possible: http://www.appcelerator.com/blog/2014/06/ios-8-support/
is there an ETA on this to be fixed? a lot of OSS code out there for iOS is being now written using Swift and we are left behind..
This must surely be of the highest priority. I'm really feeling held back with lack of Swift support and can't offer my clients any custom modules (obj c is too alien for me). I know you guys are probably busting a gut to get features implemented soon as and Hyperloop may void the need for what we're asking. Can we have a little feedback on what the current state of play is with Swift? It's such a great language.
I'm not sure that (without seriously overhauling how Titanium works) Swift support will happen. Swift doesn't allow you to compile to a static library, and Titanium can't use a dynamic library. I believe that accommodating this is one of the goals of Ti.Next though. So we're stuck until Apple finally lets us compile a normal static library, or until Ti.Next comes along.
OK could there be any workaround or middle-man that lets the base obj-c static lib call a separate Swift dynamic lib?
*To all watchers of this ticket*: You might receive a few notification mails as this is now scheduled and transitioned to an Epic. It will include sub-tasks and general discussion. One of the big tasks to solve here is to move the Titanium iOS-core into an independent framework, e.g. "TitaniumSDKCoreKit.framework", which will then be used in both normal Titanium development but also in combination with native modules. Talking about that, native modules will likely also be able to handle the dependency via Cocoapods to ease general dependency management across different versions. This task is expected to be completed in the SDK 8.0.0 time frame and will likely break native modules, requiring them to be recompiled with the core-framework again. More over the next months!
Basic implementation is done - moving the SDK core to an own framework that is used by the SDK itself. To prevent dependency issues across multiple version of the core-framework, we will likely also add CocoaPods support for classic modules like done for Hyperloop. All remaining tasks are CLI- and cleanup-related. Note: This ticket will allow both to *use* Swift libraries in native modules, but also to *build* Swift powered modules that are packaged as universal frameworks, e.g. "TiMap.framework".
Update: The changes to the core are done. Some details: - The core of the Titanium iOS-SDK is now moved to a framework and provided precompiled to the build process, saving 4-5 seconds build time. Together with other recent build pipeline improvements, we will save 10-15 seconds for clean builds, compared to older version of the SDK - This change does *not* represent a breaking change, retaining full backwards compatibility with older modules. No (iOS) modules will need to get recompiled in order to use this - You can now select between a Swift- and Obj-C template when creating a new module. The new templates also includes examples for distributing your module via CocoaPods and Carthage The changes and many more details can be seen in the [designated pull request](https://github.com/appcelerator/titanium_mobile/pull/10218).
This is awesome!
This is already resolved now.
Resolving as PR is merged.
*Closing ticket* Verified in SDK version
8.0.0.v20190109125941
Able to create module using swift and run it in a titanium project. Test Steps:Created a new test module using
ti create -t module --name test --id com.example.tese --code-base swift
Packaged the module using
appc run -p ios --build-only
(iOS folder within the module)Created a new titanium project
Added the following code
Ran the program
Able to see the correct outputs
*Test Environment*I have just tried the commands above and am getting an error when trying to compile the module created. After opening the default project in XCode 10.2.1 and letting it update the settings (and out-of-date Swift version!) the error is in ComExampleTeseExampleProxy.swift line 15 :