2017-09-20 3 views
2

私はちょうどすべてがすべてを除いてうまく行くように見えたスウィフト4にスウィフト3から、Objective Cの中に、もはや迅速な拡張

を混合言語プロジェクト(Objective-Cのとスウィフト)をアップグレード終了私のスウィフトエクステンションはもはや客観的にはアクセスできない。私はを取得する方法を見つけることができませんスピーディーな拡張子が目的に表示されます - c。私は検索を試みましたが、privateスコープを緩める点を除いて、Swift 4の拡張機能の変更については何の言及も見つかりません。

  • これらの拡張はすべてSwift 3のObjective-cからアクセスできました。したがって、互換性のない型(構造体または非生の列挙型)はありません。
  • 拡張子はpublicとマークされています。
  • エクステンションは、同じターゲットの一部であり、objective-cファイルと同じプロジェクトに含まれています。
  • はい、関連するobjective-cファイルに "ProjectName-Swift.h"をインポートしました。
  • その他の互換性のあるスウィフトクラスdoが表示されます。拡張機能が欠落しているようです。
  • 私は各funcも公開してみました。例えば

、Iはスイフト3を用いた場合にObjective-Cのコードを使用できるように使用される次の拡張:

public extension UIAlertController { 

    class func alert(_ title: String? = nil, message: String? = nil) -> UIAlertController { 
    return UIAlertController(title: title, message: message, preferredStyle: .alert) 
    } 

    @discardableResult func action(_ action: String) -> UIAlertController { 
    self.addAction(UIAlertAction(title: action, style: .default, handler: nil)) 
    return self 
    } 

    @discardableResult func action(_ action: String, style: UIAlertActionStyle = .default, onSelected: ((UIAlertAction) -> Void)? = nil) -> UIAlertController { 
    self.addAction(UIAlertAction(title: action, style: style, handler: onSelected)) 
    return self 
    } 

    @discardableResult func cancel(_ action: String? = "Cancel", onCancel: ((UIAlertAction) -> Void)? = nil) -> UIAlertController { 
    self.addAction(UIAlertAction(title: action, style: .cancel, handler: { alert in 
     onCancel?(alert) 
    })) 
    return self 
    } 

    @discardableResult func destructive(_ action: String, onDestruct: @escaping ((UIAlertAction) -> Void)) -> UIAlertController { 
    self.addAction(UIAlertAction(title: action, style: .destructive, handler: { action in 
     onDestruct(action) 
    })) 
    return self 
    } 

    func presentOn(_ viewController: UIViewController, animated: Bool = true) { 
    viewController.present(self, animated: animated, completion: nil) 
    } 
} 
+0

おそらく、すべてのメソッドに '@ objc'を追加する必要があります。 –

+0

または拡張宣言自体(例: '@objc public extension')(https://stackoverflow.com/q/44390378/2976878と比較) – Hamish

+0

ああ、そうですね。私はそれが彼らが作った '@ objc'推論の変更に関係していると思います。 –

答えて

0

Aスーパー簡単な解決策は、単に各スイフトの宣言に@objc public extensionを追加することです拡張。

関連する問題