renamed commitAndWait() to overload commit()

This commit is contained in:
John Rommel Estropia
2015-05-09 19:40:08 +09:00
parent a1610534cb
commit 202ec371f2
13 changed files with 131 additions and 60 deletions

View File

@@ -22,7 +22,7 @@
<key>4B60F1BCB491FF717C56441AE7783C74F417BE48</key>
<string>../../..</string>
<key>8B2E522D57154DFA93A06982C36315ECBEA4FA97</key>
<string>../../..Libraries/GCDKit/</string>
<string>../../..Libraries/GCDKit</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>github.com:JohnEstropia/HardcoreData.git</string>

View File

@@ -21,7 +21,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
HardcoreData.defaultStack.addSQLiteStore()
HardcoreData.defaultStack.addSQLiteStore(resetStoreOnMigrationFailure: true)
return true
}
}

View File

@@ -120,20 +120,20 @@
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<slider opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="359" translatesAutoresizingMaskIntoConstraints="NO" id="YQ6-fq-3Wb">
<rect key="frame" x="98" y="149" width="488" height="31"/>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="0.0" maxValue="359" translatesAutoresizingMaskIntoConstraints="NO" id="YQ6-fq-3Wb">
<rect key="frame" x="98" y="148" width="488" height="31"/>
<connections>
<action selector="hueSliderValueDidChange:" destination="dX3-kR-CYC" eventType="valueChanged" id="9Hy-3h-llE"/>
</connections>
</slider>
<slider opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="1" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="xXz-78-tAd">
<rect key="frame" x="98" y="187" width="488" height="31"/>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="1" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="xXz-78-tAd">
<rect key="frame" x="98" y="186" width="488" height="31"/>
<connections>
<action selector="saturationSliderValueDidChange:" destination="dX3-kR-CYC" eventType="valueChanged" id="qtU-ua-ZTc"/>
</connections>
</slider>
<slider opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="hpy-2d-eOP">
<rect key="frame" x="98" y="225" width="488" height="31"/>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="hpy-2d-eOP">
<rect key="frame" x="98" y="224" width="488" height="31"/>
<connections>
<action selector="brightnessSliderValueDidChange:" destination="dX3-kR-CYC" eventType="valueChanged" id="F09-EP-2iD"/>
</connections>
@@ -269,7 +269,6 @@
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="DAz-BE-6Ca">
<rect key="frame" x="0.0" y="0.0" width="600" height="268"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="PaletteTableViewCell" id="G3X-70-BCD" customClass="PaletteTableViewCell" customModule="HardcoreDataDemo" customModuleProvider="target">
<autoresizingMask key="autoresizingMask"/>
@@ -387,6 +386,11 @@
<navigationBar key="navigationBar" contentMode="scaleToFill" id="6XA-6M-yvZ">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<color key="tintColor" red="0.75362819430000005" green="0.91446238759999998" blue="0.99948346610000005" alpha="1" colorSpace="calibratedRGB"/>
<color key="barTintColor" red="0.49803921580314636" green="0.49803921580314636" blue="0.49803921580314636" alpha="1" colorSpace="calibratedRGB"/>
<textAttributes key="titleTextAttributes">
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</textAttributes>
</navigationBar>
<nil name="viewControllers"/>
<connections>
@@ -406,6 +410,11 @@
<navigationBar key="navigationBar" contentMode="scaleToFill" id="wJo-mp-1pS">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<color key="tintColor" red="0.7536281943321228" green="0.9144623875617981" blue="0.99948346614837646" alpha="1" colorSpace="calibratedRGB"/>
<color key="barTintColor" red="0.49803921579999999" green="0.49803921579999999" blue="0.49803921579999999" alpha="1" colorSpace="calibratedRGB"/>
<textAttributes key="titleTextAttributes">
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</textAttributes>
</navigationBar>
<nil name="viewControllers"/>
<connections>
@@ -421,6 +430,6 @@
<image name="second" width="30" height="30"/>
</resources>
<inferredMetricsTieBreakers>
<segue reference="fIB-GS-Ppk"/>
<segue reference="hyN-De-zte"/>
</inferredMetricsTieBreakers>
</document>

View File

@@ -3,14 +3,11 @@
<entity name="Palette" representedClassName="HardcoreDataDemo.Palette">
<attribute name="brightness" optional="YES" attributeType="Float" defaultValueString="0.0" syncable="YES"/>
<attribute name="colorName" optional="YES" transient="YES" attributeType="String" syncable="YES"/>
<attribute name="dateAdded" optional="YES" attributeType="Date">
<userInfo/>
</attribute>
<attribute name="hue" optional="YES" attributeType="Integer 32" defaultValueString="0.0" syncable="YES"/>
<attribute name="saturation" optional="YES" attributeType="Float" defaultValueString="0.0" syncable="YES"/>
<userInfo/>
</entity>
<elements>
<element name="Palette" positionX="261" positionY="189" width="128" height="120"/>
<element name="Palette" positionX="261" positionY="189" width="128" height="105"/>
</elements>
</model>

View File

@@ -15,7 +15,7 @@ struct Shared {
static let palettes = HardcoreData.observeObjectList(
From(Palette),
GroupBy("colorName"),
SortedBy(.Ascending("hue"), .Ascending("dateAdded"))
SortedBy(.Ascending("hue"))
)
}
@@ -191,7 +191,7 @@ class ObjectListObserverDemoViewController: UITableViewController, ManagedObject
HardcoreData.beginAsynchronous { (transaction) -> Void in
transaction.deleteAll(From(Palette))
transaction.commit { (result) -> Void in }
transaction.commit()
}
}
@@ -202,7 +202,7 @@ class ObjectListObserverDemoViewController: UITableViewController, ManagedObject
let palette = transaction.create(Palette)
palette.setInitialValues()
transaction.commit { (result) -> Void in }
transaction.commit()
}
}
}

View File

@@ -56,7 +56,7 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
let palette = transaction.create(Palette)
palette.setInitialValues()
transaction.commitAndWait()
transaction.commit()
}
let palette = HardcoreData.fetchOne(From(Palette), SortedBy(.Ascending("hue")))!
@@ -126,8 +126,7 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
if let palette = transaction.fetch(self?.objectController?.object) {
palette.hue = Int32(hue)
palette.dateAdded = NSDate()
transaction.commit { (result) -> Void in }
transaction.commit()
}
}
}
@@ -140,8 +139,7 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
if let palette = transaction.fetch(self?.objectController?.object) {
palette.saturation = saturation
palette.dateAdded = NSDate()
transaction.commit { (result) -> Void in }
transaction.commit()
}
}
}
@@ -154,8 +152,7 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
if let palette = transaction.fetch(self?.objectController?.object) {
palette.brightness = brightness
palette.dateAdded = NSDate()
transaction.commit { (result) -> Void in }
transaction.commit()
}
}
}
@@ -165,7 +162,7 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
HardcoreData.beginAsynchronous { [weak self] (transaction) -> Void in
transaction.delete(self?.objectController?.object)
transaction.commit { (result) -> Void in }
transaction.commit()
}
}
@@ -177,12 +174,11 @@ class ObjectObserverDemoViewController: UIViewController, ManagedObjectObserver
self.colorNameLabel?.textColor = color
self.colorView?.backgroundColor = color
self.hsbLabel?.text = palette.colorText
let hue = palette.hue
let saturation = palette.saturation
let brightness = palette.brightness
self.hsbLabel?.text = "H: \(hue)˚, S: \(Int(saturation * 100))%, B: \(Int(brightness * 100))%"
if Int32(self.hueSlider?.value ?? 0) != hue {
self.hueSlider?.value = Float(hue)

View File

@@ -16,7 +16,6 @@ import HardcoreData
class Palette: NSManagedObject {
@NSManaged var dateAdded: NSDate
@NSManaged var hue: Int32
@NSManaged var saturation: Float
@NSManaged var brightness: Float
@@ -25,12 +24,8 @@ class Palette: NSManagedObject {
get {
let key = "colorName"
self.willAccessValueForKey(key)
let value: AnyObject? = self.primitiveValueForKey(key)
self.didAccessValueForKey(key)
if let colorName = value as? String {
let KVCKey = "colorName"
if let colorName = self.accessValueForKVCKey(KVCKey) as? String {
return colorName
}
@@ -49,15 +44,12 @@ class Palette: NSManagedObject {
default: colorName = "Upper Reds"
}
self.setPrimitiveValue(colorName, forKey: key)
self.setPrimitiveValue(colorName, forKey: KVCKey)
return colorName
}
set {
let key = "colorName"
self.willChangeValueForKey(key)
self.setPrimitiveValue(newValue, forKey: key)
self.didChangeValueForKey(key)
self.setValue(newValue, forKVCKey: "colorName")
}
}
@@ -80,7 +72,6 @@ class Palette: NSManagedObject {
self.hue = Int32(arc4random_uniform(360))
self.saturation = 1.0
self.brightness = 0.5
self.dateAdded = NSDate()
self.brightness = Float(arc4random_uniform(70) + 30) / 100.0
}
}