如何分发在iOS模拟器上运行的Objective-C和Swift代码?

时间:2014-06-09 18:00:10

标签: ios objective-c xcode ios-simulator swift

我有一组Swift和Objective-C文件,它们扩展了XCTest框架中的一些功能。

我很容易创建一个由这些文件组成的Cocoa框架。我将所有文件添加到OS X框架目标中,并且由于其中一些文件导入了XCTest头文件,因此我将XCTest.framework链接到了我的框架。用户可以将框架添加到他们的单元测试目标中,前提是他们正在为OS X构建。

问题:如何为构建iOS模拟器的用户执行相同操作(即:分发此代码)?

我尝试过的事情(1):Cocoa Touch框架

我无法创建导入XCTest.framework的Cocoa Touch框架 - 这样做会导致以下链接器错误(" Quick"是框架的名称):

Ld /Users/modocache/Library/Developer/Xcode/DerivedData/Quick-cajmiuprocunntdhiwsnsfzqydkc/Build/Products/Debug-iphonesimulator/Quick-iOS.framework/Quick-iOS normal x86_64
    cd /Users/modocache/GitHub/modocache/Quick
    export IPHONEOS_DEPLOYMENT_TARGET=8.0
    export PATH="/Applications/Xcode6-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode6-Beta.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -dynamiclib -isysroot /Applications/Xcode6-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk -L/Users/modocache/Library/Developer/Xcode/DerivedData/Quick-cajmiuprocunntdhiwsnsfzqydkc/Build/Products/Debug-iphonesimulator -F/Users/modocache/Library/Developer/Xcode/DerivedData/Quick-cajmiuprocunntdhiwsnsfzqydkc/Build/Products/Debug-iphonesimulator -F/Applications/Xcode6-Beta.app/Contents/Developer/Library/Frameworks -filelist /Users/modocache/Library/Developer/Xcode/DerivedData/Quick-cajmiuprocunntdhiwsnsfzqydkc/Build/Intermediates/Quick.build/Debug-iphonesimulator/Quick-iOS.build/Objects-normal/x86_64/Quick-iOS.LinkFileList -install_name @rpath/Quick-iOS.framework/Quick-iOS -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -Xlinker -objc_abi_version -Xlinker 2 -Xlinker -no_implicit_dylibs -mios-simulator-version-min=8.0 -framework XCTest -single_module -compatibility_version 1 -current_version 1 -Xlinker -dependency_info -Xlinker /Users/modocache/Library/Developer/Xcode/DerivedData/Quick-cajmiuprocunntdhiwsnsfzqydkc/Build/Intermediates/Quick.build/Debug-iphonesimulator/Quick-iOS.build/Objects-normal/x86_64/Quick-iOS_dependency_info.dat -o /Users/modocache/Library/Developer/Xcode/DerivedData/Quick-cajmiuprocunntdhiwsnsfzqydkc/Build/Products/Debug-iphonesimulator/Quick-iOS.framework/Quick-iOS

ld: building for iOS Simulator, but linking against dylib built for MacOSX file '/Applications/Xcode6-Beta.app/Contents/Developer/Library/Frameworks/XCTest.framework/XCTest' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我尝试过的事情(2):Cocoa Touch静态库

其他类似于我的扩展XCTest框架的项目使用静态库来分发他们的代码。但是,尝试构建包含Swift代码的静态库会导致以下错误:

Libtool /Users/MBP-006FYGC/Library/Developer/Xcode/DerivedData/Quick-chbdhbmwzcgjlyfsbxuvmajagydy/Build/Products/Debug/libQuick-OSX.a normal x86_64
    cd /Users/MBP-006FYGC/GitHub/modocache/Quick
    export MACOSX_DEPLOYMENT_TARGET=10.7
    /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool -static -arch_only x86_64 -syslibroot /Applications/Xcode6-Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -L/Users/MBP-006FYGC/Library/Developer/Xcode/DerivedData/Quick-chbdhbmwzcgjlyfsbxuvmajagydy/Build/Products/Debug -filelist /Users/MBP-006FYGC/Library/Developer/Xcode/DerivedData/Quick-chbdhbmwzcgjlyfsbxuvmajagydy/Build/Intermediates/Quick.build/Debug/Quick-OSX.build/Objects-normal/x86_64/Quick-OSX.LinkFileList -ObjC -L/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx -Xlinker -rpath -Xlinker /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx -Xlinker -force_load -Xlinker /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_macosx.a -Xlinker -sectalign -Xlinker __SWIFT -Xlinker __ast -Xlinker 4 -Xlinker -sectcreate -Xlinker __SWIFT -Xlinker __ast -Xlinker /Users/MBP-006FYGC/Library/Developer/Xcode/DerivedData/Quick-chbdhbmwzcgjlyfsbxuvmajagydy/Build/Intermediates/Quick.build/Debug/Quick-OSX.build/Objects-normal/x86_64/Quick_OSX.swiftmodule -framework XCTest -framework Foundation -o /Users/MBP-006FYGC/Library/Developer/Xcode/DerivedData/Quick-chbdhbmwzcgjlyfsbxuvmajagydy/Build/Products/Debug/libQuick-OSX.a

error: /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: unknown option character `X' in: -Xlinker
Usage: /Applications/Xcode6-Beta.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/Xcode6-Beta.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]

更多信息

对于那些感兴趣的人,或者如果您需要更多详细信息,相关项目为on GitHub。我使用this issue跟踪到目前为止我所尝试的内容。

如何将这个Swift / Objective-C代码(使用XCTest代码)分发给希望在iOS单元测试中使用它的用户?

1 个答案:

答案 0 :(得分:3)

项目中FRAMEWORK_SEARCH_PATHS的价值是多少?我刚刚创建了一个新的iOS框架,这是默认的:

$(inherited) $(DEVELOPER_FRAMEWORKS_DIR)

请改为尝试:

$(SDKROOT)/Developer/Library/Frameworks $(inherited) $(DEVELOPER_FRAMEWORKS_DIR)

这应该会导致Xcode在Mac版本之前找到iOS框架包。