miyabi / unity-swift

Native plugin to write native code in Swift for Unity.
166 stars 26 forks source link

No known class method for selector 'swiftMethod:' #4

Open naninunenoy opened 5 years ago

naninunenoy commented 5 years ago

Xcode: 10.2 Swift Language Version: 4

スクリーンショット 2019-03-29 19 46 30

@objc attribute is required to call from obj-c source code in Swift4. https://github.com/apple/swift-evolution/blob/master/proposals/0160-objc-inference.md And Xcode 10.2 can only use Swift4 or later.

Please fix Exapmle.swift this way.


import Foundation

class Example : NSObject {
    static func callUnityMethod(_ message: String) {
        // Call a method on a specified GameObject.
        UnitySendMessage("CallbackTarget", "OnCallFromSwift", message)
    }

    // !!Here!!
    @objc static func swiftMethod(_ message: String) {
        print("\(#function) is called with message: \(message)")

        self.callUnityMethod("Hello, Unity!")
    }
}
richardschembri commented 5 years ago

@naninunenoy Fixed this issue on my fork, currently have a pending pull request. https://github.com/richardschembri/unity-swift

muyen commented 4 years ago

@richardschembri, thank you fro the fix.