onesky / plugin-ios-ota

Over the air plugin
50 stars 8 forks source link

Bridging headers for Swift #10

Closed kermankohli closed 9 years ago

kermankohli commented 9 years ago

I can't use this library on Swift because it says that the OneSkyOTAPlugin module can't be found - presumably because there's no bridging headers.

bretdabaker commented 9 years ago

To use the plugin for Swift you should create one single Objective-C bridging header and add #import <OneSkyOTAPlugin/OneSkyOTAPlugin.h> along with other Objective-C imports there.

Please read the documentation for more details.

kermankohli commented 9 years ago

I would assume that a SDK for a product would provide Swift support by default?

bretdabaker commented 9 years ago

You can mix and match Swift and Objective-C in the same project, one simply won't write a library in Objective-C and rewrite it in Swift, vice versa.

If you develop in Swift you can not avoid using libraries written in Objective-C, so please read the documentation and learn how to use the bridging header.

bretdabaker commented 9 years ago

The bridging header should be created for the project and includes ALL Objective-C files and libraries, not just one library.

Even if a header was provided you still need to configure the Build Settings to make it work, you can't declare multiple bridging headers in Build Settings so what you are asking simply doesn't make sense for a library written in Objective-C.

Usually the name of the bridging header includes the name of the project. This step is expected to be done by the project owner.

You can find more detail here: http://stackoverflow.com/a/24005242

kermankohli commented 9 years ago

Another thing, OSLocalizedString doesn't work in Swift because of the #define in Objective-C

@bretdabaker Sorry, got a bit confused (it's 2am here)!

bretdabaker commented 9 years ago

It's okay, let me add swift integration guide to README.md later. Will also checkout the macro.

kermankohli commented 9 years ago

Thanks! I really need the plugin soon though :p

bretdabaker commented 9 years ago

You can still use the plugin without the macro.

OneSkyOTAPlugin.localizedStringForKey("key", value: "value", table: "tableName")
kermankohli commented 8 years ago

Is there a macro without the table property and comment instead of "value"?

OneSkyOTAPlugin.localizedStringForKey("key", comment: "value")

bretdabaker commented 8 years ago

You can use public functions to wrap the code, here is the file with the macros:

OneSkyOTAPlugin.swift.zip

thekie commented 8 years ago

Swift 3 needs to be like this:

public func OSLocalizedString(_ key: String, comment: String) -> String {
    return OneSkyOTAPlugin.localizedString(forKey: key, value: "", table: nil)
}

public func OSLocalizedStringFromTable(_ key: String, table: String, comment: String) -> String {
    return OneSkyOTAPlugin.localizedString(forKey: key, value: "", table: table)
}