Adding ActivityIndicator to Dice Roller

This patch includes two changes:
- The dice rolling logic is updated to always produce a different numer on each
  roll, so that users know that they have generated a new number
- An actitvity indicator is added to indicate syncing

Change-Id: I89a5501152a6ef8dd8dda3f7f4a21a6d545f3a5f
diff --git a/Syncbase/Example/Dice Roller/Base.lproj/Main.storyboard b/Syncbase/Example/Dice Roller/Base.lproj/Main.storyboard
index 17dee1d..98bd78b 100644
--- a/Syncbase/Example/Dice Roller/Base.lproj/Main.storyboard
+++ b/Syncbase/Example/Dice Roller/Base.lproj/Main.storyboard
@@ -32,7 +32,7 @@
                                 </constraints>
                             </view>
                             <activityIndicatorView hidden="YES" opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" hidesWhenStopped="YES" style="whiteLarge" translatesAutoresizingMaskIntoConstraints="NO" id="QOU-JV-r2d" userLabel="Spinner">
-                                <rect key="frame" x="281.5" y="457.5" width="37" height="37"/>
+                                <rect key="frame" x="282" y="458" width="37" height="37"/>
                             </activityIndicatorView>
                         </subviews>
                         <color key="backgroundColor" red="0.2470588235" green="0.31764705879999999" blue="0.70980392160000005" alpha="1" colorSpace="calibratedRGB"/>
@@ -84,7 +84,7 @@
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
                             <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillEqually" alignment="center" spacing="50" translatesAutoresizingMaskIntoConstraints="NO" id="APD-dz-sU0">
-                                <rect key="frame" x="260" y="224" width="80" height="152"/>
+                                <rect key="frame" x="260" y="174" width="80" height="253"/>
                                 <subviews>
                                     <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="2" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="180-RC-nik">
                                         <rect key="frame" x="0.0" y="0.0" width="80" height="51"/>
@@ -106,7 +106,13 @@
                                             <action selector="didPressRollDie:" destination="70a-ZD-vEg" eventType="touchUpInside" id="jDV-E7-3Ta"/>
                                         </connections>
                                     </button>
+                                    <activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" animating="YES" style="gray" translatesAutoresizingMaskIntoConstraints="NO" id="ofb-qf-jIF">
+                                        <rect key="frame" x="30" y="202" width="20" height="51"/>
+                                    </activityIndicatorView>
                                 </subviews>
+                                <constraints>
+                                    <constraint firstItem="ofb-qf-jIF" firstAttribute="top" secondItem="W1t-Lo-OTx" secondAttribute="bottom" id="Ik5-Rh-9RQ"/>
+                                </constraints>
                             </stackView>
                         </subviews>
                         <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
@@ -123,6 +129,7 @@
                         </barButtonItem>
                     </navigationItem>
                     <connections>
+                        <outlet property="activityIndicator" destination="ofb-qf-jIF" id="iqN-ov-TiD"/>
                         <outlet property="numberLabel" destination="180-RC-nik" id="nyZ-Kj-0LD"/>
                         <segue destination="01J-lp-oVM" kind="showDetail" identifier="LogoutSegue" id="fOL-0c-Tbh"/>
                     </connections>
diff --git a/Syncbase/Example/Dice Roller/DiceViewController.swift b/Syncbase/Example/Dice Roller/DiceViewController.swift
index f0b7155..3ff5ac6 100644
--- a/Syncbase/Example/Dice Roller/DiceViewController.swift
+++ b/Syncbase/Example/Dice Roller/DiceViewController.swift
@@ -11,12 +11,15 @@
 
 class DiceViewController: UIViewController {
   @IBOutlet weak var numberLabel: UILabel!
+  @IBOutlet weak var activityIndicator: UIActivityIndicatorView!
   var collection: Collection?
+  var currentDieRoll = UInt8(2) // The starting number from the XIB
 
   override func viewDidLoad() {
     super.viewDidLoad()
 
     do {
+      activityIndicator.alpha = 0.0
       collection = try Syncbase.database().collection(collectionName)
     } catch let e {
       print("Unexpected error: \(e)")
@@ -57,8 +60,12 @@
     if let value = lastValue {
       // Get the single byte out via typecasting to an array of UInt8. This will be unnecessary
       // when we have VOM support in Swift.
-      let num = unsafeBitCast(value.bytes, UnsafePointer<UInt8>.self).memory
-      numberLabel.text = num.description
+      currentDieRoll = unsafeBitCast(value.bytes, UnsafePointer<UInt8>.self).memory
+      numberLabel.text = currentDieRoll.description
+
+      UIView.animateWithDuration(0.35) {
+        self.activityIndicator.alpha = 0.0
+      }
     }
   }
 
@@ -68,7 +75,16 @@
   }
 
   @IBAction func didPressRollDie(sender: UIButton) {
-    var nextNum = UInt8(arc4random_uniform(6) + 1)
+    var nextNum: UInt8
+
+    UIView.animateWithDuration(0.35) {
+      self.activityIndicator.alpha = 1.0
+    }
+
+    repeat {
+      nextNum = UInt8(arc4random_uniform(6) + 1)
+    } while (nextNum == currentDieRoll)
+
     // Right now we can only store NSData, so we have to serialize this number to store it.
     // Soon we will have VOM support and can just put the raw int as the value and expect
     // it to work properly.