简体   繁体   中英

Xcode Swift Import Code Within "an App Target" vs. "a Framework Target" -- What is difference?

I'm importing two .swift files into an existing ObjC app.

The Apple document "Importing Swift into Objective-C" lists these two choices but I don't understand their difference.

I don't know the difference between "App Target" and "Framework Target".

I created an Xcode app project and not a framework project. Is that the difference?

A framework target means that your project compiles your code into a library which can then be consumed by other programs. CocoaPods are examples of frameworks.

A project can contain multiple targets. It's possible to have your project define a framework and provide the source files for that framework, and also build an application as a separate target (normally you'd do this when your application consumes the framework(s) that it builds)

Unless you are building your own frameworks, you should pick "App Target".

Not gaining to deliver the correct answer with this post. As of your other question swift-error-use-of-centralmanager-refers-to-instance-method-rather-than-var suggests i think you are mixing up what the difference of a static library and a framework is. Without going to deep into the differences and how to use them it may help to distinguish one from another.

  1. A static library can make use of frameworks and other libraries.
  2. Frameworks can make use other frameworks and (other) libraries.
  3. An App can make use of static libraries and different frameworks.

在此处输入图片说明

When creating targets in your workspace/project you see for iOS there are different templates to create supporting code. The dialog specially differentiate between Static Library and Framework.

Each of them would create a target in your project and usually also create a Scheme to compile those with their separated target settings. In your Apps Target setting you can define where headers are, what needs to be linked and copied into resources or can be found somewhere else to make it work. When those targets are part of one project you can take advantage of Xcodes features that helps you to compile the dependency before going on and finally compiling the App itself. Once a (in example) framework is compiled Xcode will keep it around so it does not have to be compiled each time you compile your App depending on this framework. As soon you change the framework you (can) expect that Xcode will compile it again. If the targets are separate from each other in different workspaces/projects you are responsible to keep an eye on those dependencies and their last compiled version that will be used in your App.

Because - nothing surprising - you are responsible to link, define dependencies and deploy/place and declare the parts needed to make your app work for runtime.

And here a screenshot showing different targets in one project (random naming) and Framework, Libraries and Embedded Content settings for the selected App Target .

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM