如何在swift 3上调用模糊的扩展方法

时间:2016-09-20 07:11:45

标签: swift swift3 swift-extensions

// - Module1

import Foundation

public extension String {
    public func testMethod() {
        print("something Module1 ---------------------")
    }
}

// - Module2

import Foundation

public extension String {
    public func testMethod() {
        print("something Module2 ---------------------")
    }
}

// - 代码

import UIKit
import Module1
import Module2

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        "Hello".testMethod() //----- here is the problem, not any way to call it
        return true
    }
}

有没有办法调用模糊方法testMethod来从Module1或Module2中进行选择。与"Hello".(Module1.testMethod)()"Hello".(Module2.testMethod())

相同

0 个答案:

没有答案