Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

swift3 - Swift Framework build fails for device but not for simulator

Any ideas why a build would succeed for simulator but not a device?

I created a Cocoa framework and was able to add it to a new single-page application project, and call the methods defined in the framework. The project built as long as I had a simulator selected as the build target and not a device. I have not tried running it, only building. I'm using Swift 3 and XCode 8.1.

I get Use of unresolved identifier errors.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It sounds like you built the framework for a simulator and not for a device. When the linker is trying to link the application for a device, it doesn't find the framework built for that device.

Two of the ways to do it are as follows.

1) When building the framework, set the active scheme appropriate for the device (upper left area in Xcode). Then, before building the application for the device, go to Build Settings for the app and add the framework's location to Framework Search Paths. Make sure you pick the right binary! For example, when building for the iOS simulator, a debug binary of the framework is going to be in a directory called Build/Products/Debug-iphonesimulator.

With this approach you also need to add the framework to the Copy Files build phase of your app, specifying Destination as Frameworks.

2) Embed the framework into the application, make it a dependency of the app, and set up the application to link with the framework in the app's Build Phases. See

https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html

about embedding a framework and for other useful framework-related info. A convenient way of accomplishing this is to go to the General tab of your application target and add the framework in the Embedded Binaries section.

Alternatively, if you create your framework after creating the application, you can ask Xcode to embed the framework into the app.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...