I\'m new in swift programming. I need to create pure swift framework and import it in my existing pure swift project. When I try to import swift framework, I\'m getting this
On Swift:
Create Framework:-
Start Xcode -> Create a new Xcode Project -> iOS -> Framework & Library -> Cocoa Touch Framework -> Name the framework(ex. sampleCocoaFramework) -> Create.
Set Taget -> General -> Deployment info -> Deployment Target.
Add a public class: File -> New File -> iOS -> Swift File -> Name it (ex. openCocoaClass) -> Create.
Now add some code to the openCocoaClass.swift.
import Foundation
public class openCocoaClass {
public init() {
}
public var samplePublicVariable = "samplePublicVariable @ openCocoaClass"
public func samplePublicFunction()
{
print("samplePublicFunction @ openCocoaClass")
}
}
Clean the project : Product -> Clean
Configure the scheme settings : Product -> Scheme -> Edit Scheme -> Run -> Build Configuration -> Release.
Build the framework : Product -> Build.
Adding Framework to Project:-
Start a Xcode project and name it (ex. CocoaFrameworkTest).
Drag and drop the sampleCocoaFramework.framework to the CocoaFrameworkTest's project folder.
Target -> General -> Embed Binaries -> Add Other -> Select Framework -> Copy Items if needed -> Done.
Accessing Framework on ViewController:-
import UIKit
import sampleCocoaFramework
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let frameworkObject = openCocoaClass.init()
frameworkObject.samplePublicFunction()
print(frameworkObject.samplePublicVariable)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}