Q:

How to use filter method instead of for in loop? Swift

I would like to assign the BookingFeedback property of each element of bookings array to arrayOfFeedBackValues. Is there a shorter version than for in loop?
     //long version
  let bookings = [FireBaseData]()
  var arrayOfFeedBackValues = [Double]()
       for item in bookings{
          if item.BookingFeedback != nil {
            arrayOfFeedBackValues.append(Double(item.BookingFeedback)!)
           }
       }

//attempted short version. How can I make the returned value be of type Double?
  var arrayOfFeedBackValues = bookings.filter {$0.BookingFeedback != nil}

A:

You can use map
arrayOfFeedBackValuesa.append(contentsOf: 
                               bookings.filter {$0.BookingFeedback != nil}
                                       .map { Double($0.BookingFeedback)! })

