简体   繁体   English

参数类型&#39;范围 <Int> &#39;不符合预期类型&#39;序列&#39;Swift3

[英]Argument type 'Range<Int>' does not conform to expected type 'Sequence' Swift3

Hi i get error after Swift3. 嗨我在Swift3之后得到错误。 How can i fix this error? 我该如何解决这个错误? These methods provide non-repeated random numbers. 这些方法提供非重复的随机数。

 func uniqueRandoms(_ count: Int, inRange range: Range<Int>, blacklist: [Int] = []) -> [Int] {
    var r = [Int](range)
        .filter{ !blacklist.contains($0) }
        .shuffle()

    return Array(r[0..<count])
}



extension Array {
func shuffle() -> Array<Element> {
    var newArray = self

    for i in 0..<newArray.count {
        let j = Int(arc4random_uniform(UInt32(newArray.count)))
        guard i != j else { continue }
        swap(&newArray[i], &newArray[j])
    }

    return newArray
}
}

Thanks 谢谢

使用range的lowerBoundupperBound属性为[Int] Array创建序列。

var r = [Int](range.lowerBound..<range.upperBound)

我建议你使用CountableRange<Int>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有 Swift 4/Xcode 10 的 Facebook SDK:参数类型“SDKLoggingBehavior?” 不符合预期的类型“序列” - Facebook SDK with Swift 4/Xcode 10: Argument type 'SDKLoggingBehavior?' does not conform to expected type 'Sequence' 参数类型&#39;SecretSpec&#39;不符合预期类型&#39;序列&#39; - Argument type 'SecretSpec' does not conform to expected type 'Sequence' Xcode Swift Argument 类型不符合预期类型“解码器” - Xcode Swift Argument type does not conform to expected type 'Decoder' 类型不符合协议序列类型 - Swift - type does not conform to protocol Sequence Type - Swift 参数类型与预期类型不符 - Argument type does not conform to expected type 参数类型不符合预期的类型 MKAnnotation - Argument type does not conform to expected type MKAnnotation TKChartDataPoint不符合预期的类型序列 - TKChartDataPoint does not conform to expected type Sequence Swift3:类型“ NSObject”不符合协议“ URLAuthenticationChallengeSender” - Swift3: Type 'NSObject' does not conform to protocol 'URLAuthenticationChallengeSender' 参数类型&#39;customClass.Type&#39;不符合预期类型&#39;NSItemProviderWriting&#39; - Argument type 'customClass.Type' does not conform to expected type 'NSItemProviderWriting' iOS SWIFT - 文件存档 - 参数类型“[String?]”:不符合预期类型&#39;AnyObject&#39; - iOS SWIFT - File Archive - Argument Type “[String?]” : does not conform to expected type'AnyObject'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM