SQLFetchedResultsController 可以让使用 SQLite 建立表格更加容易。对于那些喜欢 SQL 的灵活性,又不想放弃可以轻松建立表格的 Core Data’s NSFetchedResultsController 的开发者,可以试试这个类。
作者注 :这个脚本正在开发中,还不能保证总是正确的显示列表。
override func viewDidLoad() { super.viewDidLoad() var request = SQLFetchRequest() request.table = "Test as t" //Not tested with > 1 table request.fields = ["id","title", "(SELECT AVG(id) FROM Test WHERE title=t.title) as idAvg"] request.predicate = "id % 10 = 0 AND title != 'SomeString'" request.sortDescriptors = [(key:"title", isASC:true)] request.groupBy = "title" request.having = "count(*) > 3" fetchController = SQLFetchedResultsController(request: request, pathToDatabase: DatabaseSetup.getDatabasePath()) let preview = fetchController!.previewSQL() println("--SQL Preview: \(preview.SQL) \n--Parameters: \(preview.Parameters)") }