I plan to create swift static library and use in ios swift app. I create a swift static libraryn call SimpleLib and it include a public class Greeting which return Hello World string:
//
// Greeting.swift
// SimpleLib
//
import Foundation
public class Greeting {
public func Hello() -> String {
return "Hello World";
}
public init() {
}
public static func SayMorning() -> String{
return "Hi, Morning";
}
}
The swift static library project look like:
And the module.modulemap is defined as following:
module SimpleLib {
header "SimpleLib-Swift.h"
export *
}
I build and produce a libSimpleLib.a file, I place the .a and other files (referred by other posts in internet to mention need put in app folder) in app folder:
In the app project, I include the Libs path in FREAMEWORK_SEARCH_PATHS, LIBRARY_SEARCH_PATHS and HEADER_SEARCH_PATHS and include .a file in Linked Framework
However, when I attempt to refer the Greeting class in the AppDelegate, I got the error - Use of unresolved identifier 'Greeting'
//
// AppDelegate.swift
// testStatic
//
import UIKit
import SimpleLib
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
var s = Greeting
return true
}
......
}
How to make Swift objects in static library can be referred in the App. What is the proper steps to export the class/functions in swift static library? Anyone success to build and use swift static library in iOS app?