Cast array element type in loop
In the delegate method, I am returning a "custom object type result array" and I want to iterate over the elements of the array. I am doing the following now and it works
for result in results {
if result is XYZClass {
//This Works!
}
}
Is there a way to print objects in a for loop to avoid writing two lines? Does it make it fast? Used to make it pretty easy in Objective - C
for (XYZClass *result in results) {
}
However, I have had no success with Swift. I've tried explicit casting with no luck.
for result as XYZClass in results {
//ERROR: Expected ‘;’ in ‘for’ statements
}
for result:AGSGPParameterValue in results {
/* ERROR: This prompts down cast as
for result:AGSGPParameterValue in results as AGSGPParameterValue { }
which in turn errors again "Type XYZClass does not conform to Sequence Type"
*/
}
Any help is appreciated
+3
source to share