Created
November 24, 2019 17:20
-
-
Save GrantJEmerson/2e308ad56f6ea9757e0d0c00f450d796 to your computer and use it in GitHub Desktop.
Powerful Predicates - SwiftMoji Entry #26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
@objcMembers class Craft: NSObject { | |
let name: String | |
let maxAltitude: Int | |
let maxSpeed: Int | |
init(name: String, maxAltitude: Int, maxSpeed: Int) { | |
self.name = name | |
self.maxAltitude = maxAltitude | |
self.maxSpeed = maxSpeed | |
} | |
override var description: String { name } | |
} | |
let π© = Craft(name: "Gulfstream G550", maxAltitude: 49500, maxSpeed: 585) | |
let π¬ = Craft(name: "gulfstream g650", maxAltitude: 51000, maxSpeed: 610) | |
let π = Craft(name: "BFR", maxAltitude: Int.max, maxSpeed: 18000) | |
let π = Craft(name: "Bell 407", maxAltitude: 17618, maxSpeed: 162) | |
let crafts = [π©, π¬, π, π] as NSArray | |
let predicate = NSPredicate(format: "(name BEGINSWITH[c] %@) AND (maxAltitude BETWEEN { 25000, 50000 })", "Gulfstream") | |
let listings = crafts.filtered(using: predicate) | |
print(listings) // [Gulfstream G550] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment