func filteredBeacons(_ beacons: [CLBeacon]) -> [CLBeacon] {
    var filteredBeacons = beacons   // Copy

    var lookup = Set<String>()
    for index in 0..<beacons.count {


        let currentBeacon = beacons[index]
        let identifier = "\(currentBeacon.major)/\(currentBeacon.minor)"

        if lookup.contains(identifier) {
            filteredBeacons.remove(at: index)
        } else {
            lookup.insert(identifier)
        }

    }

    return filteredBeacons
}

我的理解是,这段代码将删除任何重复的信标。现在,我希望这个代码也可以删除接近“未知”(即很远)的信标。有人能教我怎么做吗?我知道需要上课。
我对xcode很陌生,如果可能的话,希望能有更多的解释。谢谢您。

最佳答案

尝试:

func filteredBeacons(_ beacons: [CLBeacon]) -> [CLBeacon] {
    var filteredBeacons = beacons   // Copy

    var lookup = Set<String>()
    for index in 0..<beacons.count {
        let currentBeacon = beacons[index]
        if currentBeacon.proximity == .unknown {
          filteredBeacons.remove(at: index)
        }
        else {
          let identifier = "\(currentBeacon.major)/\(currentBeacon.minor)"

          if lookup.contains(identifier) {
              filteredBeacons.remove(at: index)
          } else {
              lookup.insert(identifier)
          }
        }
    }

    return filteredBeacons
}

09-25 18:44