Skip to content

Instantly share code, notes, and snippets.

@xremix
Created January 16, 2018 08:22
Show Gist options
  • Save xremix/ad460f7cd8378b7de511be69deb71dc5 to your computer and use it in GitHub Desktop.
Save xremix/ad460f7cd8378b7de511be69deb71dc5 to your computer and use it in GitHub Desktop.
First not nil Property
import UIKit
class MyObjects: NSObject{
var myOptional: String?
var myRequired: String
init(req: String, op: String?) {
myOptional = op
myRequired = req
}
}
var myArray = [MyObjects]()
myArray.append(MyObjects(req: "1", op: nil))
myArray.append(MyObjects(req: "2", op: "2"))
myArray.append(MyObjects(req: "3", op: nil))
myArray.append(MyObjects(req: "3", op: "3"))
let x = myArray.map({return $0.myOptional}).flatMap({$0}).first
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment