elegant queries

This commit is contained in:
John Rommel Estropia
2014-12-14 23:47:18 +09:00
parent 45a65d9262
commit 6b8bb3e434
14 changed files with 237 additions and 145 deletions

View File

@@ -30,18 +30,17 @@ import HardcoreData
class HardcoreDataTests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testExample() {
// This is an example of a functional test case.
NSLog("Test aaaa")
#if DEBUG
let resetStoreOnMigrationFailure = true
#else
@@ -56,33 +55,33 @@ class HardcoreDataTests: XCTestCase {
reason: error.localizedDescription,
userInfo: error.userInfo).raise()
default: break
default:
break
}
HardcoreData.performTransaction { (transaction) -> () in
HardcoreData.performTransactionAndWait({ (transaction) -> () in
let obj = transaction.create(TestEntity1)
obj.testEntityID = 1
obj.testString = "lololol"
obj.testNumber = 42
obj.testDate = NSDate()
transaction.commitAndWait()
})
HardcoreData.performTransactionAndWait({ (transaction) -> () in
let obj = transaction.findFirst(
let obj = transaction.findAll(
TestEntity1
.WHERE(true)
.SORTEDBY(.Ascending("testEntityID"), .Descending("testString")))
transaction.commit { (result) -> () in
switch result {
.WHERE("testEntityID", isEqualTo: 1)
.SORTEDBY(.Ascending("testEntityID"), .Descending("testString")),
customizeFetch: { (fetchRequest) -> () in
case .Success(let hasChanges):
dump(hasChanges, name: "hasChanges")
case .Failure(let error):
dump(error, name: "error")
fetchRequest.includesPendingChanges = true
}
}
}
)
NSLog("%@", obj ?? [])
})
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock() {
// Put the code you want to measure the time of here.
}
}
}

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="6254" systemVersion="14B25" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
<entity name="TestEntity1" representedClassName="TestEntity1" syncable="YES">
<entity name="TestEntity1" representedClassName="HardcoreDataTests.TestEntity1" syncable="YES">
<attribute name="testDate" optional="YES" attributeType="Date" syncable="YES"/>
<attribute name="testEntityID" attributeType="Integer 64" syncable="YES"/>
<attribute name="testNumber" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/>

View File

@@ -28,9 +28,9 @@ import CoreData
class TestEntity1: NSManagedObject {
@NSManaged var testEntityID: NSNumber
@NSManaged var testString: String
@NSManaged var testNumber: NSNumber
@NSManaged var testDate: NSDate
@NSManaged var testEntityID: NSNumber?
@NSManaged var testString: String?
@NSManaged var testNumber: NSNumber?
@NSManaged var testDate: NSDate?
}