How can I import Swift code to Objective-C?

前端 未结 15 2442
南方客
南方客 2020-11-22 02:52

I have written a library in Swift and I wasn\'t able to import it to my current project, written in Objective-C.

Are there any ways to import it?

#i         


        
15条回答
  •  攒了一身酷
    2020-11-22 03:16

    If you have a project created in Swift 4 and then added Objective-C files, do it like this:

    @objcMembers
    public class MyModel: NSObject {
        var someFlag = false         
        func doSomething() {         
            print("doing something")
        }
    }
    

    Reference: https://useyourloaf.com/blog/objc-warnings-upgrading-to-swift-4/

提交回复
热议问题