unity-swift icon indicating copy to clipboard operation
unity-swift copied to clipboard

No known class method for selector 'swiftMethod:'

Open naninunenoy opened this issue 5 years ago • 2 comments

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!")
    }
}

naninunenoy avatar Mar 29 '19 10:03 naninunenoy

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

richardschembri avatar Sep 09 '19 02:09 richardschembri

@richardschembri, thank you fro the fix.

muyen avatar Nov 26 '19 18:11 muyen