I am having some trouble using .map on a collection in Swift 4.2. Here is what is happening:
I have a property declared like this:
var cbPerifList:[CBPeripheral]!
Later in the code when I write:
_ = cbPerifList.map { (perif) -> Void in
print(perif.identifier)
}
The compiler seems happy and does not complain.
But when I write:
_ = cbPerifList.map { (perif) -> Void in
print(perif.identifier)
print("HELLO")
}
The compiler complains by displaying this message.
Value of type '[CBPeripheral]' has no member 'identifier'
on the line of code: print(perif.identifier)
Can someone explain what is going on here?
I don't see why adding this line of code makes a difference.
print("HELLO")
I expect perif to be of type CBPeripheral and not [CBPeripheral] as the error message says.