How create dynamics Region on iOS, Ibeacon

I have the info(Uuid, Major, Minor) of two beacons in my DB, and I want to create two CLBeaconRegion but dynamically, because there is the possibility of adding more beacons and create more CLBeaconRegion, I have this code:

                for i in 0 ... self.ArrayBeaconIDs.count-1 {
              let beaconRegion = CLBeaconRegion(
                    proximityUUID: UUID(uuidString: self.ArrayBeaconIDs[i])!,
                    major:  CLBeaconMajorValue(self.ArrayMajor[i])! ,minor:CLBeaconMajorValue(self.ArrayMinor[i])!
                    , identifier: "teuchlitlan"
            for i in 0 ... self.ArrayRegiones.count-1 {
                self.ArrayRegiones[i].notifyEntryStateOnDisplay = true
                self.ArrayRegiones[i].notifyOnEntry = true
                self.ArrayRegiones[i].notifyOnExit = true
                self.beaconManager.startMonitoring(for: self.ArrayRegiones[i])
                self.beaconManager.startRangingBeacons(in: self.ArrayRegiones[i])
                self.beaconManager.requestState(for: self.ArrayRegiones[i])

but only detect the last region in the Array, How can I solve it?

You’re re-using the “teuchlitlan” identifier for each of your CLBeaconRegions, that’s a no-go: they’ll just overwrite each other. You can make your identifiers unique by appending the i to it:

identifier: "teuchlitlan\(i)"

Note that with Core Location monitoring, there’s a limit of 20 regions.

If you write a bit more about what app/project you’re working on, we can probably suggest some better way to structure your regions.

Thanks so much, this is the solutions :D, I am working on an application to explore non-tourist places and reward every one that comes close to a beacon, for each village I have a total of 15-20 beacons