protocol LazyUpdateable {
func waitToDoStuff()
func myMethodName()
}
extension LazyUpdateable where Self: NSObject {
func waitToDoStuff() {
self.performSelector(#selector(myMethodName), withObject: nil, afterDelay: 1.5)
}
func myMethodName() {
}
}
このアップデートでは、エラーArgument of #selector refers to a method that is not exposed to objective c
が表示されますが、古いSelector("myMethodName")
と一緒に行った場合、より良い方法に変更するよう警告が表示されます。この場合、#selector()
を使用できますか?私のプロトコルで@objc
を設定すると動作しません。試しました。ここでプロトコル拡張で#selector(myMethodName)を使用するにはどうすればよいですか?
あなたはそれはそれは@objc
import Foundation
import UIKit
import XCPlayground
@objc protocol LazyUpdatable {
optional func waitToDoStuff()
optional func myMethodName()
}
extension LazyUpdatable where Self: UIViewController {
func waitToDoStuff() {
self.performSelector(#selector(myMethodName), withObject: nil, afterDelay: 1.5)
}
func myMethodName() {
print("LOL")
}
}
@objc
class AViewController: UIViewController, LazyUpdatable {
func start() {
waitToDoStuff()
}
}
let aViewController = AViewController()
aViewController.start()
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true