I've got var campaigns: [Campaign] = []
Campaign objects have a property published.
I'd like to map through the array and filter out unpublished campaigns so that the result is an array holding published campaigns only
I've tried below but get of course get 'nil' is incompatible with return type 'Campaign'
self.campaigns = self.campaigns.map({ (campaign) -> Campaign in
if campaign.published == 1 {
return campaign
} else {
return nil
}
})
Anyone knowing the solution to this mini-problem? Thanks ;-)
self.campaigns, why don't you callfilter? Is there some good reason why you cannot call it?self.campaigns = self.campaigns.filter {$0.published == 1}or whateverfilterin your question and you are not using it. Try what @matt said, if it still didn't work do share theObjectand we will help you figure out.