How to import framework into XCode project?
That's not a Swift module, so first, you need to create a bridging header, in which you import <BRLMPrinterKit/BRLMPrinterKit.h>, then you can use the BRLM classes in your Swift files.
Add Swift Package to a custom framework
Well, there are numerous isses you could have faced during importing framework itself. It also depends if you use framework as binary or source code. I assume you were using source code approach as you are the creator of framework. You can however check all approaches here: in this SO question . Lets look at all the steps you need to implement in order to successfully use framework with SPM dependencies in your swift project.
- create SPM properly and also link all additional SPM dependencies tutorial here. Make sure all your classes, structs etc. and their coresponding initializer has correct access level property. If you plan to use them outside of the package, use public initializers..
2)Once you created you SPM package, link it to framework. For the sake of this answer I createdtestFramework
and linked one of my custom SPM package calledVodApiPackage
. This package also contains dependency to anotherBaseTvApiServicePackage
.
I also added TestPrinter
file containing simple function for creating error declared in my SPM package. This function servers only for checking that everything is working properly and will be user later. It is also declared public.
import Foundation
import VodApiPackage
public struct TestPrinter {
public init () {}
public func makeTest() {
let x = VodApiError.customErr(msg: "testMsg")
print(x.localizedDescription)
}
}
Open your project and make link to framework, you can also check this nice tutorial. The most important step from tutorial is step 5 and 6. Where you drag
.xcproj
into your project and link libraries and frameworkmake sure your library and SPM dependencies are correctly linked in your project. Check sample project below.
Build and test using your framework and its packages:
import UIKit
import testFramework
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
testmodel()
TestPrinter().makeTest()
}
}
How can I add existing frameworks in Xcode 4?
As per Apple's documentation:
- In the project navigator, select
your project. - Select your target.
- Select the "Build Phases" tab.
- Open "Link Binaries With Libraries"
expander. - Click the + button.
- Select your framework.
- (optional) Drag and drop the added
framework to the "Frameworks" group.
Create a framework from existing iOS project
When you want to make a framework, or module, from a project, the first thing you’ll need to do is, if you don’t have one already, make an Xcode project workspace (File > Save as Workspace) . The next step is to add a new framework “project” to your workspace (that could’ve been why you saw some resources telling you to make a new project) with File > New Project and choosing Cocoa Touch framework. When you add it, make sure you pick your workspace under both Add to and Group. Then you will need to migrate in the files that you wanted to be in this module — make sure to choose copy items if needed.
Here’s an article with more specific details on the process if you need it:
https://medium.com/kinandcartacreated/modular-ios-splitting-a-workspace-into-modules-331293f1090
Import Framework in Swift Project, Xcode
If I get you correctly you don't have a separate build target for your framework (you already built it with Xcode 5) and included the framework into your project's build target.
The part of the documentation you're referring to is about frameworks within different targets.
Since your framework is in the project's target this part of the documentation doesn't apply here.
In your case you can't do an import of the framework in your Swift file. That's why you get the error message "No such module myFramework".
myFramework is no module -- it is part of your project's module (which is by default determined by your product name). As such the classes in your framework should be accessible.
However your framework is written in Objective-C. So what you have to do is to import the Swift facing classes in your bridging-header as described here.
Please note that this has nothing to do with the Swift import of a module. The import directive in the bridging-header file just notifies the compiler to 'translate' Objective-C header files to Swift syntax and makes the public header visible to Swift.
So what should you do now?
First import the header files you're interested in in the bridging-header. You only need to import the headers you will interact with in Swift.
Try to compile your project in this stage. If Xcode can't find the header files of the framework your problem is probably not related to Swift or Xcode 6 but a problem with including frameworks in general.
After that try to instantiate a class you imported in the bridging-header, maybe in your AppDelegate.swift. Xcode auto-completion should offer you the type names.
Hope this helps.
Related Topics
How to Chain Filters in Metal for iOS
How to Use Indexesofobjectspassingtest: in Swift
Bluetooth Didconnect or Didfailtoconnect Not Called Xcode 9.2 with iOS 11.1.2
Url Opening Swift App - Open Works - Called Function Does Not Work
Swift 3 Weird Crashes (Type Inference)
Swiftui: Navigate to Home Screen After Login Completed. Navigating Views by Button Click
How to Get Index of Xcuielement in Xcuielementquery
Camera Only Takes Pictures in Portrait Mode Swift
Dynamic Height for a Uitableview Based on a Dynamic Collection View
Wrong Text Height When Text Contains Emoji
Didreceiveremotenotification Not Called in Background Mode
How to Override Convenience Init in Uialertcontroller for Swift
Xcode 4.2 with Arc: Will My Code Run Even on iOS Devices with Firmware Older Than 5.0
Native-Like Momentum-Scrolling on Body in iOS Webapp
Alamofire Request Gets Stuck When Entering Background
How to Compile Aws Customidentityprovider on Xcode 8 Beta 6
Swift 3: Transfer Utility Enumeratetoassignblocks Method Signature
How to Launch IPA File in iOS 10 Real Device Using Appium 1.6.0