我正在尝试使用第一个代码块here,但它是为早期版本的swift编写的。所以我为Swift 4更新了它。这就像我的游乐场一样:
import UIKit
class Person: NSObject {
let firstName: String
let lastName: String
let age: Int
init(firstName: String, lastName: String, age: Int) {
self.firstName = firstName
self.lastName = lastName
self.age = age
}
override var description: String {
return "\(firstName) \(lastName)"
}
}
let alice = Person(firstName: "Alice", lastName: "Smith", age: 24)
let bob = Person(firstName: "Bob", lastName: "Jones", age: 27)
let charlie = Person(firstName: "Charlie", lastName: "Smith", age: 33)
let quentin = Person(firstName: "Quentin", lastName: "Alberts", age: 31)
let people = [alice, bob, charlie, quentin]
let bobPredicate = NSPredicate(format: "firstName = %@", "Bob")
let smithPredicate = NSPredicate(format: "lastName = %@", "Smith")
let thirtiesPredicate = NSPredicate(format: "age >= 30")
(people as NSArray).filtered(using: bobPredicate)
在最后一行(people as NSArray).filtered(using: bobPredicate)
我收到错误:error: Execution was interrupted, reason: signal SIGABRT. The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.
我不确定如何解决此错误。谢谢,