Swift:无法推断出通用参数

时间:2017-01-26 01:29:08

标签: swift

编译时遇到错误:

var beaconIDs = [BeaconID]()
for i in 0..<BeaconsStruct.uuidT.count {
beaconIDs.append(BeaconID(UUIDString: BeaconsStruct.uuidT[i], major:  
Int(BeaconsStruct.majorT[i])!, minor: Int(BeaconsStruct.minorT[i])!))
}

错误是:无法推断通用参数“元素”。

BeaconID包含:

struct BeaconID: Equatable, CustomStringConvertible, Hashable {
    let proximityUUID: UUID
    let major: CLBeaconMajorValue
    let minor: CLBeaconMinorValue

    init(proximityUUID: UUID, major: CLBeaconMajorValue, minor: CLBeaconMinorValue) {
        self.proximityUUID = proximityUUID
        self.major = major
        self.minor = minor
    }

    init(UUIDString: String, major: CLBeaconMajorValue, minor: CLBeaconMinorValue) {
        self.init(proximityUUID: UUID(uuidString: UUIDString)!, major: major, minor: minor)
    }
}

BeaconsStruct包含:

struct BeaconsStruct {
static var uuidT: [String] = []
static var minorT: [String] = []
static var majorT: [String] = []
static var lokalizacjaT: [String] = []
}

我可以请你帮忙吗?

1 个答案:

答案 0 :(得分:0)

majorminor的演员表错了。初始值设定项需要CLBeaconMajorValueCLBeaconMinorValue,因此转换为Int而不是转换为var beaconIDs = [BeaconID]() for i in 0..<BeaconsStruct.uuidT.count { beaconIDs.append(BeaconID(UUIDString: BeaconsStruct.uuidT[i], major: CLBeaconMajorValue(BeaconsStruct.majorT[i])!, minor: CLBeaconMinorValue(BeaconsStruct.minorT[i])!)) }

data-grunticon-embed