Reputation: 11107
I have a function that I would like to return different types of arrays. Here's what I have so far.
func typeForSection(section: Int) -> Array<What do I put here?> {
switch section {
case 1:
return media // media is an array of strings
case 2:
return hashtags // hashtags is an array of strings
case 3:
return urls // hashtags is an array of NSUrls
case 4:
return mentions // array of integers
}
}
What do I need to do to assign for the return array as any type? Thanks.
Upvotes: 1
Views: 99
Reputation: 30488
Use AnyObject
for returning any type of object
func typeForSection(section: Int) -> AnyObject
AnyObject
in swift is equivalent to id
in Obj C
And if you only want to return Array
with different Object in it use Array<AnyObject>
func typeForSection(section: Int) -> Array<AnyObject>
Upvotes: 2