testing some ways to make querying as elegant as possible

This commit is contained in:
John Rommel Estropia
2014-12-13 10:06:16 +09:00
parent 8010daa161
commit 45a65d9262
12 changed files with 604 additions and 175 deletions

View File

@@ -2,12 +2,30 @@
// HardcoreDataTests.swift
// HardcoreDataTests
//
// Created by John Rommel Estropia on 2014/09/14.
// Copyright (c) 2014 John Rommel Estropia. All rights reserved.
// Copyright (c) 2014 John Rommel Estropia
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
import UIKit
import XCTest
import HardcoreData
class HardcoreDataTests: XCTestCase {
@@ -23,7 +41,7 @@ class HardcoreDataTests: XCTestCase {
func testExample() {
// This is an example of a functional test case.
NSLog("Test aaaa")
#if DEBUG
let resetStoreOnMigrationFailure = true
#else
@@ -43,15 +61,18 @@ class HardcoreDataTests: XCTestCase {
HardcoreData.performTransaction { (transaction) -> () in
let obj = transaction.context.findFirst(FlickrPhoto)
let obj = transaction.findFirst(
TestEntity1
.WHERE(true)
.SORTEDBY(.Ascending("testEntityID"), .Descending("testString")))
transaction.commit { (result) -> () in
switch result {
case .Success(let hasChanges):
JEDump(hasChanges, "hasChanges")
dump(hasChanges, name: "hasChanges")
case .Failure(let error):
JEDump(error, "error")
dump(error, name: "error")
}
}
}

View File

@@ -0,0 +1,12 @@
<?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">
<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"/>
<attribute name="testString" optional="YES" attributeType="String" syncable="YES"/>
</entity>
<elements>
<element name="TestEntity1" positionX="-63" positionY="-18" width="128" height="105"/>
</elements>
</model>

View File

@@ -0,0 +1,36 @@
//
// TestEntity1.swift
// HardcoreData
//
// Copyright (c) 2014 John Rommel Estropia
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
import Foundation
import CoreData
class TestEntity1: NSManagedObject {
@NSManaged var testEntityID: NSNumber
@NSManaged var testString: String
@NSManaged var testNumber: NSNumber
@NSManaged var testDate: NSDate
}