I have two arrays. One array called albums
which contains objects of type Album
. The other one is called photosAlbums
which contains objects of type PHAlbum
. These types are custom classes.
I want to combine the two to form a single array. I have declared an AnyObject
array called allAlbums
and trying to put the contents of those two arrays in to this one but it's not working.
I tried these methods.
1). Assigned the content of albums
array to allAlbums
first and then try to append the other array.
self.allAlbums = albums
self.allAlbums.appendContentsOf(photosAlbums)
But I'm getting the error Cannot invoke 'appendContentsOf' with an argument list of type '([PHAlbum])' here.
2). The method from this answer.
self.allAlbums = [albums, photosAlbums].flatMap { $0 }
The type of the combined array becomes [Element]
.
Is there any other way to do this?