Bill3 Bill3 - 6 months ago 11x
Swift Question

Return an array created from custom objects in Swift where they aren't known until runtime?

This function works fine except for the return

func fillAnObjectClassArrayGivenURL(URL: String, className: NSObject) -> [NSObject] {
var returnList = [className]
var objectToAddToList = className
//some code that appends objectToAddToList to returnList
return returnList

But this
isn't the right thing to return and I don't know what class it will be making the array from until runtime. Not that swift with Swift yet. Is there a way to return essentially


You can use generics.

func fillAnObjectClassArrayGivenURL<T: AnyObject>(urlString: String, className: T.Type) -> [T]