diff --git a/Accelerometer-Soup/.gitignore b/Accelerometer-Soup/.gitignore
new file mode 100644
index 0000000..988d2da
--- /dev/null
+++ b/Accelerometer-Soup/.gitignore
@@ -0,0 +1,43 @@
+# Xcode
+#
+# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
+
+## Build generated
+build/
+DerivedData
+
+## Various settings
+*.pbxuser
+!default.pbxuser
+*.mode1v3
+!default.mode1v3
+*.mode2v3
+!default.mode2v3
+*.perspectivev3
+!default.perspectivev3
+xcuserdata
+
+## Other
+*.xccheckout
+*.moved-aside
+*.xcuserstate
+*.xcscmblueprint
+
+## Obj-C/Swift specific
+*.hmap
+*.ipa
+
+# CocoaPods
+#
+# We recommend against adding the Pods directory to your .gitignore. However
+# you should judge for yourself, the pros and cons are mentioned at:
+# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
+#
+# Pods/
+
+# Carthage
+#
+# Add this line if you want to avoid checking in source code from Carthage dependencies.
+# Carthage/Checkouts
+
+Carthage/Build
\ No newline at end of file
diff --git a/Accelerometer-Soup/Accelerometer.xcodeproj/project.pbxproj b/Accelerometer-Soup/Accelerometer.xcodeproj/project.pbxproj
index 9d87328..30f268c 100644
--- a/Accelerometer-Soup/Accelerometer.xcodeproj/project.pbxproj
+++ b/Accelerometer-Soup/Accelerometer.xcodeproj/project.pbxproj
@@ -164,7 +164,9 @@
BFE82E941B14202B008B6981 /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 0630;
+ LastSwiftMigration = 0700;
+ LastSwiftUpdateCheck = 0700;
+ LastUpgradeCheck = 0700;
ORGANIZATIONNAME = "Linda Dong";
TargetAttributes = {
BFE82E9B1B14202B008B6981 = {
@@ -286,6 +288,7 @@
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
@@ -354,6 +357,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Accelerometer/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = "lindadong.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
@@ -364,6 +368,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Accelerometer/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = "lindadong.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
@@ -382,6 +387,7 @@
);
INFOPLIST_FILE = AccelerometerTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = "lindadong.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Accelerometer.app/Accelerometer";
};
@@ -397,6 +403,7 @@
);
INFOPLIST_FILE = AccelerometerTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = "lindadong.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Accelerometer.app/Accelerometer";
};
diff --git a/Accelerometer-Soup/Accelerometer.xcodeproj/project.xcworkspace/xcuserdata/linda.xcuserdatad/UserInterfaceState.xcuserstate b/Accelerometer-Soup/Accelerometer.xcodeproj/project.xcworkspace/xcuserdata/linda.xcuserdatad/UserInterfaceState.xcuserstate
deleted file mode 100644
index 61b3568..0000000
Binary files a/Accelerometer-Soup/Accelerometer.xcodeproj/project.xcworkspace/xcuserdata/linda.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ
diff --git a/Accelerometer-Soup/Accelerometer.xcodeproj/xcuserdata/linda.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/Accelerometer-Soup/Accelerometer.xcodeproj/xcuserdata/linda.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
deleted file mode 100644
index fe2b454..0000000
--- a/Accelerometer-Soup/Accelerometer.xcodeproj/xcuserdata/linda.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
diff --git a/Accelerometer-Soup/Accelerometer.xcodeproj/xcuserdata/linda.xcuserdatad/xcschemes/Accelerometer.xcscheme b/Accelerometer-Soup/Accelerometer.xcodeproj/xcuserdata/linda.xcuserdatad/xcschemes/Accelerometer.xcscheme
deleted file mode 100644
index bad89d0..0000000
--- a/Accelerometer-Soup/Accelerometer.xcodeproj/xcuserdata/linda.xcuserdatad/xcschemes/Accelerometer.xcscheme
+++ /dev/null
@@ -1,112 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Accelerometer-Soup/Accelerometer.xcodeproj/xcuserdata/linda.xcuserdatad/xcschemes/xcschememanagement.plist b/Accelerometer-Soup/Accelerometer.xcodeproj/xcuserdata/linda.xcuserdatad/xcschemes/xcschememanagement.plist
deleted file mode 100644
index af24838..0000000
--- a/Accelerometer-Soup/Accelerometer.xcodeproj/xcuserdata/linda.xcuserdatad/xcschemes/xcschememanagement.plist
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
- SchemeUserState
-
- Accelerometer.xcscheme
-
- orderHint
- 0
-
-
- SuppressBuildableAutocreation
-
- BFE82E9B1B14202B008B6981
-
- primary
-
-
- BFE82EB41B14202B008B6981
-
- primary
-
-
-
-
-
diff --git a/Accelerometer-Soup/Accelerometer/GameScene.swift b/Accelerometer-Soup/Accelerometer/GameScene.swift
index 13f62ec..ececabe 100644
--- a/Accelerometer-Soup/Accelerometer/GameScene.swift
+++ b/Accelerometer-Soup/Accelerometer/GameScene.swift
@@ -10,7 +10,7 @@ import SpriteKit
import CoreMotion
extension Array {
- func sample() -> T {
+ func sample() -> Element {
let randomIndex = Int(rand()) % count
return self[randomIndex]
}
@@ -21,46 +21,45 @@ class GameScene: SKScene, SKPhysicsContactDelegate {
let motionManager: CMMotionManager = CMMotionManager()
// Shape Colors
- let colorArray = [ SKColor(red: 0 / 255, green: 64 / 255, blue: 170 / 240, alpha: 1 ),
+ let colorArray = [
+ SKColor(red: 0 / 255, green: 64 / 255, blue: 170 / 240, alpha: 1 ),
SKColor(red: 255 / 255, green: 250 / 255, blue: 233 / 240, alpha: 1 ),
- SKColor(red: 245 / 255, green: 122 / 255, blue: 99 / 240, alpha: 1 )]
+ SKColor(red: 245 / 255, green: 122 / 255, blue: 99 / 240, alpha: 1 )
+ ]
override func didMoveToView(view: SKView) {
// Add physics to the borders of the screen
let borderBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
borderBody.friction = 0
- self.physicsBody = borderBody
+ physicsBody = borderBody
// Add gravity to the scene
- self.physicsWorld.gravity = CGVectorMake(0, 0)
- self.physicsWorld.contactDelegate = self
- self.physicsBody?.contactTestBitMask = 0
+ physicsWorld.gravity = CGVectorMake(0, 0)
+ physicsWorld.contactDelegate = self
+ physicsBody?.contactTestBitMask = 0
self.backgroundColor = SKColor(red: 255 / 255, green: 191 / 255, blue: 180 / 240, alpha: 1 )
// Create Shapes
let maxShapes = 15
- for i in 0.. SKSpriteNode {
// Chooses a random image for the shape
- var randomShape = String("")
- let shapes = ["triangle", "squiggle", "circle"]
+ let shapes = [ "triangle", "squiggle", "circle" ]
let randomIndex = Int(arc4random_uniform(UInt32(shapes.count)))
let shape = SKSpriteNode(imageNamed: shapes[randomIndex])
// Places shapes randomly within the bounds of the screen
- var pointX = CGFloat(UInt(arc4random() % UInt32(UInt(self.frame.width - 100))))
- var pointY = CGFloat(UInt(arc4random() % UInt32(UInt(self.frame.height - 100))))
+ let pointX = CGFloat(UInt(arc4random() % UInt32(UInt(frame.width - 100))))
+ let pointY = CGFloat(UInt(arc4random() % UInt32(UInt(frame.height - 100))))
shape.position = CGPointMake(pointX, pointY)
shape.name = "shape"
@@ -69,7 +68,7 @@ class GameScene: SKScene, SKPhysicsContactDelegate {
shape.colorBlendFactor = 1.0
// Adds physics properties to the shapes
- shape.physicsBody = SKPhysicsBody(texture: shape.texture, size: shape.size)
+ shape.physicsBody = SKPhysicsBody(texture: shape.texture!, size: shape.size)
shape.physicsBody?.dynamic = true
shape.physicsBody?.restitution = 0.5
shape.physicsBody?.mass = 0.9
@@ -85,14 +84,13 @@ class GameScene: SKScene, SKPhysicsContactDelegate {
// Changes the velocity of the scene's gravity based on the accelerometer
if let data = motionManager.accelerometerData {
self.physicsWorld.gravity = CGVectorMake(10 * CGFloat(data.acceleration.x), 10 * CGFloat(data.acceleration.y))
-
}
}
override func didSimulatePhysics() {
// For those pesky shapes that fall out of the scene
- self.enumerateChildNodesWithName("shape", usingBlock: { (node: SKNode!, stop: UnsafeMutablePointer) -> Void in
+ self.enumerateChildNodesWithName("shape", usingBlock: { (node: SKNode, stop: UnsafeMutablePointer) -> Void in
if node.position.y < 10 || node.position.x < 10 {
node.removeFromParent()
}
@@ -102,6 +100,4 @@ class GameScene: SKScene, SKPhysicsContactDelegate {
override func update(currentTime: CFTimeInterval) {
processUserMotionForUpdate(currentTime)
}
-
-
}
diff --git a/Accelerometer-Soup/Accelerometer/GameViewController.swift b/Accelerometer-Soup/Accelerometer/GameViewController.swift
index 4b8cf6d..88dfa3a 100644
--- a/Accelerometer-Soup/Accelerometer/GameViewController.swift
+++ b/Accelerometer-Soup/Accelerometer/GameViewController.swift
@@ -11,17 +11,21 @@ import SpriteKit
extension SKNode {
class func unarchiveFromFile(file : String) -> SKNode? {
- if let path = NSBundle.mainBundle().pathForResource(file, ofType: "sks") {
- var sceneData = NSData(contentsOfFile: path, options: .DataReadingMappedIfSafe, error: nil)!
- var archiver = NSKeyedUnarchiver(forReadingWithData: sceneData)
-
- archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene")
- let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as! GameScene
- archiver.finishDecoding()
- return scene
- } else {
+ guard let path = NSBundle.mainBundle().pathForResource(file, ofType: "sks") else {
+ return nil
+ }
+
+ guard let sceneData = try? NSData(contentsOfFile: path, options: .DataReadingMappedIfSafe) else {
return nil
}
+
+ let archiver = NSKeyedUnarchiver(forReadingWithData: sceneData)
+
+ archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene")
+ let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as! GameScene
+ archiver.finishDecoding()
+
+ return scene
}
}
@@ -30,41 +34,38 @@ class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
- if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
- // Configure the view.
- let skView = self.view as! SKView
-// skView.showsFPS = true
-// skView.showsNodeCount = true
-// skView.showsPhysics = false
-
- /* Sprite Kit applies additional optimizations to improve rendering performance */
- skView.ignoresSiblingOrder = true
-
- /* Set the scale mode to scale to fit the window */
- scene.scaleMode = .ResizeFill
- scene.size = skView.bounds.size
-
- skView.presentScene(scene)
+ guard let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene else {
+ return
}
+
+ // Configure the view.
+ let skView = self.view as! SKView
+// skView.showsFPS = true
+// skView.showsNodeCount = true
+// skView.showsPhysics = false
+
+ /* Sprite Kit applies additional optimizations to improve rendering performance */
+ skView.ignoresSiblingOrder = true
+
+ /* Set the scale mode to scale to fit the window */
+ scene.scaleMode = .ResizeFill
+ scene.size = skView.bounds.size
+
+ skView.presentScene(scene)
}
override func shouldAutorotate() -> Bool {
return true
}
- override func supportedInterfaceOrientations() -> Int {
+ override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
- return Int(UIInterfaceOrientationMask.AllButUpsideDown.rawValue)
+ return UIInterfaceOrientationMask.AllButUpsideDown
} else {
- return Int(UIInterfaceOrientationMask.All.rawValue)
+ return UIInterfaceOrientationMask.All
}
}
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Release any cached data, images, etc that aren't in use.
- }
-
override func prefersStatusBarHidden() -> Bool {
return true
}
diff --git a/Accelerometer-Soup/Accelerometer/Info.plist b/Accelerometer-Soup/Accelerometer/Info.plist
index 200fa71..44468d2 100644
--- a/Accelerometer-Soup/Accelerometer/Info.plist
+++ b/Accelerometer-Soup/Accelerometer/Info.plist
@@ -7,7 +7,7 @@
CFBundleExecutable
$(EXECUTABLE_NAME)
CFBundleIdentifier
- lindadong.$(PRODUCT_NAME:rfc1034identifier)
+ $(PRODUCT_BUNDLE_IDENTIFIER)
CFBundleInfoDictionaryVersion
6.0
CFBundleName
diff --git a/Accelerometer-Soup/AccelerometerTests/Info.plist b/Accelerometer-Soup/AccelerometerTests/Info.plist
index fdde08f..ba72822 100644
--- a/Accelerometer-Soup/AccelerometerTests/Info.plist
+++ b/Accelerometer-Soup/AccelerometerTests/Info.plist
@@ -7,7 +7,7 @@
CFBundleExecutable
$(EXECUTABLE_NAME)
CFBundleIdentifier
- lindadong.$(PRODUCT_NAME:rfc1034identifier)
+ $(PRODUCT_BUNDLE_IDENTIFIER)
CFBundleInfoDictionaryVersion
6.0
CFBundleName
diff --git a/Follow-My-Finger/.gitignore b/Follow-My-Finger/.gitignore
new file mode 100644
index 0000000..988d2da
--- /dev/null
+++ b/Follow-My-Finger/.gitignore
@@ -0,0 +1,43 @@
+# Xcode
+#
+# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
+
+## Build generated
+build/
+DerivedData
+
+## Various settings
+*.pbxuser
+!default.pbxuser
+*.mode1v3
+!default.mode1v3
+*.mode2v3
+!default.mode2v3
+*.perspectivev3
+!default.perspectivev3
+xcuserdata
+
+## Other
+*.xccheckout
+*.moved-aside
+*.xcuserstate
+*.xcscmblueprint
+
+## Obj-C/Swift specific
+*.hmap
+*.ipa
+
+# CocoaPods
+#
+# We recommend against adding the Pods directory to your .gitignore. However
+# you should judge for yourself, the pros and cons are mentioned at:
+# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
+#
+# Pods/
+
+# Carthage
+#
+# Add this line if you want to avoid checking in source code from Carthage dependencies.
+# Carthage/Checkouts
+
+Carthage/Build
\ No newline at end of file
diff --git a/Follow-My-Finger/FollowMyFinger.xcodeproj/project.pbxproj b/Follow-My-Finger/FollowMyFinger.xcodeproj/project.pbxproj
index 92ee69e..4bde38f 100644
--- a/Follow-My-Finger/FollowMyFinger.xcodeproj/project.pbxproj
+++ b/Follow-My-Finger/FollowMyFinger.xcodeproj/project.pbxproj
@@ -156,7 +156,9 @@
BF93D0A01B96530A0069610C /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 0640;
+ LastSwiftMigration = 0700;
+ LastSwiftUpdateCheck = 0700;
+ LastUpgradeCheck = 0700;
ORGANIZATIONNAME = "Linda Dong";
TargetAttributes = {
BF93D0A71B96530A0069610C = {
@@ -276,6 +278,7 @@
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
@@ -344,6 +347,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = FollowMyFinger/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = "lindadong.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
@@ -354,6 +358,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = FollowMyFinger/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = "lindadong.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
@@ -372,6 +377,7 @@
);
INFOPLIST_FILE = FollowMyFingerTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = "lindadong.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/FollowMyFinger.app/FollowMyFinger";
};
@@ -387,6 +393,7 @@
);
INFOPLIST_FILE = FollowMyFingerTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = "lindadong.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/FollowMyFinger.app/FollowMyFinger";
};
@@ -411,6 +418,7 @@
BF93D0C91B96530A0069610C /* Release */,
);
defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
};
BF93D0CA1B96530A0069610C /* Build configuration list for PBXNativeTarget "FollowMyFingerTests" */ = {
isa = XCConfigurationList;
@@ -419,6 +427,7 @@
BF93D0CC1B96530A0069610C /* Release */,
);
defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
diff --git a/Follow-My-Finger/FollowMyFinger.xcodeproj/project.xcworkspace/xcuserdata/linda.xcuserdatad/UserInterfaceState.xcuserstate b/Follow-My-Finger/FollowMyFinger.xcodeproj/project.xcworkspace/xcuserdata/linda.xcuserdatad/UserInterfaceState.xcuserstate
deleted file mode 100644
index cf44485..0000000
Binary files a/Follow-My-Finger/FollowMyFinger.xcodeproj/project.xcworkspace/xcuserdata/linda.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ
diff --git a/Follow-My-Finger/FollowMyFinger.xcodeproj/xcuserdata/linda.xcuserdatad/xcschemes/FollowMyFinger.xcscheme b/Follow-My-Finger/FollowMyFinger.xcodeproj/xcuserdata/linda.xcuserdatad/xcschemes/FollowMyFinger.xcscheme
deleted file mode 100644
index ee89d73..0000000
--- a/Follow-My-Finger/FollowMyFinger.xcodeproj/xcuserdata/linda.xcuserdatad/xcschemes/FollowMyFinger.xcscheme
+++ /dev/null
@@ -1,112 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/Follow-My-Finger/FollowMyFinger.xcodeproj/xcuserdata/linda.xcuserdatad/xcschemes/xcschememanagement.plist b/Follow-My-Finger/FollowMyFinger.xcodeproj/xcuserdata/linda.xcuserdatad/xcschemes/xcschememanagement.plist
deleted file mode 100644
index 8ec7463..0000000
--- a/Follow-My-Finger/FollowMyFinger.xcodeproj/xcuserdata/linda.xcuserdatad/xcschemes/xcschememanagement.plist
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
-
- SchemeUserState
-
- FollowMyFinger.xcscheme
-
- orderHint
- 0
-
-
- SuppressBuildableAutocreation
-
- BF93D0A71B96530A0069610C
-
- primary
-
-
- BF93D0BC1B96530A0069610C
-
- primary
-
-
-
-
-
diff --git a/Follow-My-Finger/FollowMyFinger/Info.plist b/Follow-My-Finger/FollowMyFinger/Info.plist
index 02f2c2f..9803469 100644
--- a/Follow-My-Finger/FollowMyFinger/Info.plist
+++ b/Follow-My-Finger/FollowMyFinger/Info.plist
@@ -7,7 +7,7 @@
CFBundleExecutable
$(EXECUTABLE_NAME)
CFBundleIdentifier
- lindadong.$(PRODUCT_NAME:rfc1034identifier)
+ $(PRODUCT_BUNDLE_IDENTIFIER)
CFBundleInfoDictionaryVersion
6.0
CFBundleName
diff --git a/Follow-My-Finger/FollowMyFinger/ViewController.swift b/Follow-My-Finger/FollowMyFinger/ViewController.swift
index 5d2e18c..17f5080 100644
--- a/Follow-My-Finger/FollowMyFinger/ViewController.swift
+++ b/Follow-My-Finger/FollowMyFinger/ViewController.swift
@@ -13,69 +13,57 @@ class ViewController: UIViewController {
@IBOutlet weak var leftPupil: UIImageView!
@IBOutlet weak var rightPupil: UIImageView!
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- }
-
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
-
- override func touchesBegan(touches: Set, withEvent event: UIEvent) {
- if let touch:UITouch = touches.first as? UITouch {
-
- var touchPosition = touch.locationInView(self.view)
-
- // Gets the eye's center
- let currentPositionL = leftPupil.frame.origin
- let currentPositionR = rightPupil.frame.origin
-
- // Calculates angle between touch position and the eyes
- var angleL = atan2(currentPositionL.y - touchPosition.y, currentPositionL.x - touchPosition.x)
- var angleR = atan2(currentPositionR.y - touchPosition.y, currentPositionR.x - touchPosition.x)
-
- let duration : NSTimeInterval = 1.0
- let delay :NSTimeInterval = 1.0
- let damping : CGFloat = 0.3
- let animationVelocity : CGFloat = 0.5
+ func handleTouch(touch: UITouch, animated: Bool) {
+ // Get the touch position
+ let touchPosition = touch.locationInView(self.view)
+
+ // Gets the eye's center
+ let currentPositionL = leftPupil.frame.origin
+ let currentPositionR = rightPupil.frame.origin
+
+ // Calculates angle between touch position and the eyes
+ let angleL = atan2(currentPositionL.y - touchPosition.y, currentPositionL.x - touchPosition.x)
+ let angleR = atan2(currentPositionR.y - touchPosition.y, currentPositionR.x - touchPosition.x)
+
+ // Perform or animate
+ let operations = {
+ self.leftPupil.transform = CGAffineTransformMakeRotation(angleL + CGFloat(M_PI/2))
+ self.rightPupil.transform = CGAffineTransformMakeRotation(angleR + CGFloat(M_PI/2))
+ }
+
+ if animated {
+ let duration: NSTimeInterval = 1.0
+ let delay: NSTimeInterval = 0.0
+ let damping: CGFloat = 0.3
+ let animationVelocity: CGFloat = 0.5
- // usingSpringWithDamping
UIView.animateWithDuration(duration,
- delay: 0.0,
+ delay: delay,
usingSpringWithDamping: damping,
initialSpringVelocity: animationVelocity,
- options: .CurveEaseInOut,
- animations: {
- self.leftPupil.transform = CGAffineTransformMakeRotation(angleL + CGFloat(M_PI/2))
- self.rightPupil.transform = CGAffineTransformMakeRotation(angleR + CGFloat(M_PI/2))
- },
- completion: {success in })
-
-
+ options: .CurveEaseInOut,
+ animations: operations,
+ completion: { success in })
+ } else {
+ operations()
}
}
- override func touchesMoved(touches: Set, withEvent event: UIEvent) {
- if let touch:UITouch = touches.first as? UITouch {
-
- var touchPosition = touch.locationInView(self.view)
-
- let currentPositionL = leftPupil.frame.origin
- let currentPositionR = rightPupil.frame.origin
-
- var angleL = atan2(currentPositionL.y - touchPosition.y, currentPositionL.x - touchPosition.x)
- var angleR = atan2(currentPositionR.y - touchPosition.y, currentPositionR.x - touchPosition.x)
-
- leftPupil.transform = CGAffineTransformMakeRotation(angleL + CGFloat(M_PI/2))
- rightPupil.transform = CGAffineTransformMakeRotation(angleR + CGFloat(M_PI/2))
-
-
+ override func touchesBegan(touches: Set, withEvent event: UIEvent?) {
+ guard let touch = touches.first else {
+ return
}
+
+ handleTouch(touch, animated: true)
}
-
-
+
+ override func touchesMoved(touches: Set, withEvent event: UIEvent?) {
+ guard let touch = touches.first else {
+ return
+ }
+
+ handleTouch(touch, animated: false)
+ }
+
}
diff --git a/Follow-My-Finger/FollowMyFingerTests/Info.plist b/Follow-My-Finger/FollowMyFingerTests/Info.plist
index fdde08f..ba72822 100644
--- a/Follow-My-Finger/FollowMyFingerTests/Info.plist
+++ b/Follow-My-Finger/FollowMyFingerTests/Info.plist
@@ -7,7 +7,7 @@
CFBundleExecutable
$(EXECUTABLE_NAME)
CFBundleIdentifier
- lindadong.$(PRODUCT_NAME:rfc1034identifier)
+ $(PRODUCT_BUNDLE_IDENTIFIER)
CFBundleInfoDictionaryVersion
6.0
CFBundleName