SQLFetchedResultsController可以让使用SQLite建立表格更加容易。对于那些喜欢SQL的灵活性,又不想放弃可以轻松建立表格的CoreData'sNSFetchedResultsController的开发者,可以试试这个类。
作者注:这个脚本正在开发中,还不能保证总是正确的显示列表。
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)") }
评论