2016-10-16 9 views
0

cocoapodでpermissionScopeをインストールすると、swift 3構文に変換する必要がありました。その結果、ほとんどのエラーは非常にシンプルでしたが、Sequence拡張機能正しく。Swift 2 Iterator拡張がSwiftで動作しない3

これは迅速2バージョンからの拡張である:それは迅速2及びSWIFT 3

func requiredAuthorized(_ completion: @escaping (Bool) -> Void) { 
    getResultsForConfig{ (results) -> Void in 
     let result = results 
      .first { $0.status != .authorized } 
      .isNil 
     completion(result) 
    } 
} 

で本質的に同じで使用さ

extension SequenceType { 
    func first(@noescape includeElement: Generator.Element -> Bool) -> Generator.Element? { 
     for x in self where includeElement(x) { return x } 
     return nil 
    } 
} 

及びSWIFT 3

extension Sequence { 
    func first(_ includeElement: (Iterator.Element) -> Bool) -> Iterator.Element? { 
     for x in self where includeElement(x) { return x } 
     return nil 
    } 
} 

3を除いてエラーが発生するambiguous use of 'first(where:)'

答えて

1

Swift 3では、Sequenceにはfirst(where:)というメソッドがあり、これは拡張メソッドfirst(_:)と非常によく似ています。

(生成されたヘッダ:)

/// Returns the first element of the sequence that satisfies the given 
/// predicate or nil if no such element is found. 
/// 
/// - Parameter predicate: A closure that takes an element of the 
/// sequence as its argument and returns a Boolean value indicating 
/// whether the element is a match. 
/// - Returns: The first match or `nil` if there was no match. 
public func first(where predicate: (Self.Iterator.Element) throws -> Bool) rethrows -> Self.Iterator.Element? 

から拡張を削除し、標準ライブラリのfirst(where:)方法を使用します。

関連する問題