2016年2月12日 星期五

Compiler error: Method with Objective-C selector conflicts with previous declaration with the same Objective-C selector

使用相同函式,不同方法,會造成error

error code:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import UIKit

import UIKit

class ViewController: UIViewController
{
    func perform(operation: (Double) -> Double) {
    }

    func perform(operation: (Double, Double) -> Double) {
    }
}


complier error:
1
Method 'performOperation' with Objective-C selector 'performOperation:' conflicts with previous declaration with the same Objective-C selector


解決函式重載問題


加入@nonobjc即可

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import UIKit

import UIKit

class ViewController: UIViewController
{
    func perform(operation: (Double) -> Double) {
    }

    @nonobjc
    func perform(operation: (Double, Double) -> Double) {
    }
}


Using Swift with Cocoa and Objective-C (Swift 2.1)





reference:

沒有留言:

張貼留言