I'm new to learning swift and I ran into this issue and can't seem to find an answer for it. I create a collection of type Any that includes a Double, String, Int and Bool. When I attempt to loop through it I get an error:
"Value of protocol type 'Any' cannot conform to 'Sequence'.
Here is the exercise:
"Create a collection of type [Any], including a few doubles, integers, strings, and booleans within the collection. Print the contents of the collection."
var items: Any = [5.2, "Hello", 2, true]
print(items)
"Loop through the collection. For each integer, print "The integer has a value of ", followed by the integer value. Repeat the steps for doubles, strings and booleans."
for item in items {
if let unwrappedItem = item as? Int {
print("The integer has a value of \(item)")
} else if let unwrappedItem = item as? Double {
print("The integer has a value of \(item)")
}
}
Thanks in advance for the help!