Let's say that some elements may appear in Feed if they implement the necessary properties defined by the Feedable protocol. Let them also say that the Photo object is worthy of submission:
extension Photo: Feedable { }
Is it possible to say that the Array these photos can also be Feedable ?
extension [Photo] : Feedable
Or do I always need some kind of wrapper object like PhotoAlbum to fit Feedable ?
Edit
To re-iterate, I was curious if I could only create arrays of Photo Feedable objects. Do not create an Array for any type of Feedable content without creating the Feedable array by Feedable itself (both of which are offered as solutions below, if necessary).
In other words, a solution (which I doubt exists) would allow me to define a variable of type Feedable with the following results:
var feedable: Feedable //photo is feedable, so this is fine feedable = Photo() //ok //arrays of photos are feedable let photo1 = Photo() let photo2 = Photo() feedable = [photo1, photo2] //arrays of other things are not feedable = ["no", "dice"] //nope //even if the contents of an array are themselves Feedable, that not sufficient. Eg Video is Feedable, but Array of Videos is not. let video1 = Video() let video2 = Video() feeble = video1 //fine feedable = [video1, video2] //nope
Perhaps this meaning (which, of course, does not compile) shows intent more clearly.
arrays ios swift protocols
Ben packard
source share