I want to append items to an array using a loop in swift.
My code looks like the following and I am seeing this error:
For-in loop requires 'JSON?' to conform to 'Sequence'; did you mean to unwrap optional?
In the code below I want to add each email to an array defined in the class:
func loadData() {
Alamofire.request(URL, method: .get)
.responseSwiftyJSON { dataResponse in
let response = dataResponse.value
for item in response { // For-in loop requires 'JSON?' to conform to 'Sequence'; did you mean to unwrap optional?
print(item)
// ideally I want to push the email here
// something like emails.append(item.email)
}
if let email = response?[0]["email"].string{
print(email) // This shows correct email
}
}
}
Can anyone advise what the solution is here?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…