diff --git a/Rock Box.xcodeproj/project.pbxproj b/Rock Box.xcodeproj/project.pbxproj
index 476347f..08cf174 100644
--- a/Rock Box.xcodeproj/project.pbxproj
+++ b/Rock Box.xcodeproj/project.pbxproj
@@ -153,14 +153,16 @@
0E4B3320197043F90066AB0A /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 0600;
+ LastUpgradeCheck = 0820;
ORGANIZATIONNAME = "Big Nerd Ranch";
TargetAttributes = {
0E4B3327197043F90066AB0A = {
CreatedOnToolsVersion = 6.0;
+ LastSwiftMigration = 0820;
};
0E4B3339197043F90066AB0A = {
CreatedOnToolsVersion = 6.0;
+ LastSwiftMigration = 0820;
TestTargetID = 0E4B3327197043F90066AB0A;
};
};
@@ -256,15 +258,19 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
+ ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
+ GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
@@ -299,8 +305,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -308,6 +316,7 @@
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
@@ -317,6 +326,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
METAL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
+ SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
@@ -328,9 +338,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
INFOPLIST_FILE = "Rock Box/Info.plist";
- IPHONEOS_DEPLOYMENT_TARGET = 7.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = "com.bignerdranch.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_VERSION = 3.0;
};
name = Debug;
};
@@ -340,9 +352,11 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
INFOPLIST_FILE = "Rock Box/Info.plist";
- IPHONEOS_DEPLOYMENT_TARGET = 7.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
+ PRODUCT_BUNDLE_IDENTIFIER = "com.bignerdranch.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_VERSION = 3.0;
};
name = Release;
};
@@ -361,7 +375,9 @@
INFOPLIST_FILE = "Rock BoxTests/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
METAL_ENABLE_DEBUG_INFO = YES;
+ PRODUCT_BUNDLE_IDENTIFIER = "com.bignerdranch.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUNDLE_LOADER)";
};
name = Debug;
@@ -377,7 +393,9 @@
INFOPLIST_FILE = "Rock BoxTests/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
METAL_ENABLE_DEBUG_INFO = NO;
+ PRODUCT_BUNDLE_IDENTIFIER = "com.bignerdranch.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUNDLE_LOADER)";
};
name = Release;
@@ -401,6 +419,7 @@
0E4B3346197043F90066AB0A /* Release */,
);
defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
};
0E4B3347197043F90066AB0A /* Build configuration list for PBXNativeTarget "Rock BoxTests" */ = {
isa = XCConfigurationList;
@@ -409,6 +428,7 @@
0E4B3349197043F90066AB0A /* Release */,
);
defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
diff --git a/Rock Box.xcodeproj/project.xcworkspace/xcuserdata/Kiran.xcuserdatad/UserInterfaceState.xcuserstate b/Rock Box.xcodeproj/project.xcworkspace/xcuserdata/Kiran.xcuserdatad/UserInterfaceState.xcuserstate
new file mode 100644
index 0000000..9e2844d
Binary files /dev/null and b/Rock Box.xcodeproj/project.xcworkspace/xcuserdata/Kiran.xcuserdatad/UserInterfaceState.xcuserstate differ
diff --git a/Rock Box.xcodeproj/xcuserdata/Kiran.xcuserdatad/xcschemes/Rock Box.xcscheme b/Rock Box.xcodeproj/xcuserdata/Kiran.xcuserdatad/xcschemes/Rock Box.xcscheme
new file mode 100644
index 0000000..542156a
--- /dev/null
+++ b/Rock Box.xcodeproj/xcuserdata/Kiran.xcuserdatad/xcschemes/Rock Box.xcscheme
@@ -0,0 +1,101 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Rock Box.xcodeproj/xcuserdata/Kiran.xcuserdatad/xcschemes/xcschememanagement.plist b/Rock Box.xcodeproj/xcuserdata/Kiran.xcuserdatad/xcschemes/xcschememanagement.plist
new file mode 100644
index 0000000..100d289
--- /dev/null
+++ b/Rock Box.xcodeproj/xcuserdata/Kiran.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -0,0 +1,27 @@
+
+
+
+
+ SchemeUserState
+
+ Rock Box.xcscheme
+
+ orderHint
+ 0
+
+
+ SuppressBuildableAutocreation
+
+ 0E4B3327197043F90066AB0A
+
+ primary
+
+
+ 0E4B3339197043F90066AB0A
+
+ primary
+
+
+
+
+
diff --git a/Rock Box/AppDelegate.swift b/Rock Box/AppDelegate.swift
index 74daad2..81d23ac 100644
--- a/Rock Box/AppDelegate.swift
+++ b/Rock Box/AppDelegate.swift
@@ -10,37 +10,37 @@ import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
-
+
var window: UIWindow?
-
-
- func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
+
+
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
-
- func applicationWillResignActive(application: UIApplication) {
+
+ func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
-
- func applicationDidEnterBackground(application: UIApplication) {
+
+ func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
-
- func applicationWillEnterForeground(application: UIApplication) {
+
+ func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
-
- func applicationDidBecomeActive(application: UIApplication) {
+
+ func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
-
- func applicationWillTerminate(application: UIApplication) {
+
+ func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
-
-
+
+
}
diff --git a/Rock Box/Base.lproj/Main.storyboard b/Rock Box/Base.lproj/Main.storyboard
index 5ee93c5..52b0452 100644
--- a/Rock Box/Base.lproj/Main.storyboard
+++ b/Rock Box/Base.lproj/Main.storyboard
@@ -1,21 +1,26 @@
-
-
+
+
+
+
+
-
+
+
+
-
+
-
+
-
+
diff --git a/Rock Box/Info.plist b/Rock Box/Info.plist
index 87aefaa..af40bba 100644
--- a/Rock Box/Info.plist
+++ b/Rock Box/Info.plist
@@ -7,7 +7,7 @@
CFBundleExecutable
${EXECUTABLE_NAME}
CFBundleIdentifier
- com.bignerdranch.${PRODUCT_NAME:rfc1034identifier}
+ $(PRODUCT_BUNDLE_IDENTIFIER)
CFBundleInfoDictionaryVersion
6.0
CFBundleName
diff --git a/Rock Box/ViewController.swift b/Rock Box/ViewController.swift
index b28568c..b99286b 100644
--- a/Rock Box/ViewController.swift
+++ b/Rock Box/ViewController.swift
@@ -15,11 +15,11 @@ class ViewController: UIViewController {
var maxY : CGFloat = 320;
let boxSize : CGFloat = 30.0
var boxes : Array = []
-
+
// For getting device motion updates
- let motionQueue = NSOperationQueue()
+ let motionQueue = OperationQueue()
let motionManager = CMMotionManager()
-
+
override func viewDidLoad() {
super.viewDidLoad()
maxX = super.view.bounds.size.width - boxSize;
@@ -28,76 +28,76 @@ class ViewController: UIViewController {
createAnimatorStuff()
generateBoxes()
}
-
- override func viewDidAppear(animated: Bool) {
+
+ override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
NSLog("Starting gravity")
- motionManager.startDeviceMotionUpdatesToQueue(motionQueue, withHandler: gravityUpdated)
+ motionManager.startDeviceMotionUpdates(to: motionQueue, withHandler: motionHandler)
}
-
- override func viewDidDisappear(animated: Bool) {
+
+ override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
NSLog("Stopping gravity")
motionManager.stopDeviceMotionUpdates()
}
-
+
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
-
+
func randomColor() -> UIColor {
let red = CGFloat(CGFloat(arc4random()%100000)/100000);
let green = CGFloat(CGFloat(arc4random()%100000)/100000);
let blue = CGFloat(CGFloat(arc4random()%100000)/100000);
-
+
return UIColor(red: red, green: green, blue: blue, alpha: 0.85);
}
-
+
func doesNotCollide(testRect: CGRect) -> Bool {
for box : UIView in boxes {
- var viewRect = box.frame;
- if(CGRectIntersectsRect(testRect, viewRect)) {
+ let viewRect = box.frame;
+ if(testRect.intersects(viewRect)) {
return false
}
}
return true
}
-
+
func randomFrame() -> CGRect {
- var guess = CGRectMake(9, 9, 9, 9)
-
- do {
- let guessX = CGFloat(arc4random()) % maxX
- let guessY = CGFloat(arc4random()) % maxY;
- guess = CGRectMake(guessX, guessY, boxSize, boxSize);
- } while(!doesNotCollide(guess))
-
+ var guess = CGRect(x: 0, y: 0, width: 0, height: 0)
+
+ repeat {
+ let guessX = CGFloat(arc4random()).truncatingRemainder(dividingBy: maxX)
+ let guessY = CGFloat(arc4random()).truncatingRemainder(dividingBy: maxY)
+ guess = CGRect(x: guessX, y: guessY, width: boxSize, height: boxSize)
+ } while(!doesNotCollide(testRect: guess))
+
return guess
}
-
+
func addBox(location: CGRect, color: UIColor) -> UIView {
let newBox = UIView(frame: location)
newBox.backgroundColor = color
-
+
view.addSubview(newBox)
- addBoxToBehaviors(newBox)
- boxes += newBox;
+ addBoxToBehaviors(box: newBox)
+ boxes.append(newBox)
return newBox
}
-
+
func generateBoxes() {
- for i in 0..10 {
- var frame = randomFrame()
- var color = randomColor()
- var newBox = addBox(frame, color: color);
- chainBoxes(newBox)
+ for _ in 0...10 {
+ let frame = randomFrame()
+ let color = randomColor()
+ let newBox = addBox(location: frame, color: color);
+ chainBoxes(box: newBox)
}
}
-
- let startPoint = CGPointMake(50, 50)
+
+ let startPoint = CGPoint(x: 50, y: 50)
var prevBox = UIView()
-
+
func chainBoxes(box: UIView) {
if(prevBox.frame.origin.x == 0) {
let attach = UIAttachmentBehavior(item:box, attachedToAnchor:startPoint)
@@ -106,72 +106,78 @@ class ViewController: UIViewController {
animator?.addBehavior(attach)
prevBox = box
} else {
- let attach = UIAttachmentBehavior(item:box, attachedToItem:prevBox)
+ let attach = UIAttachmentBehavior(item:box, attachedTo:prevBox)
attach.length = 61
attach.damping = 0.5
animator?.addBehavior(attach)
prevBox = box
}
}
-
+
//----------------- UIDynamicAllocator
-
+
var animator:UIDynamicAnimator? = nil;
let gravity = UIGravityBehavior()
let collider = UICollisionBehavior()
let itemBehavior = UIDynamicItemBehavior()
-
+
func createAnimatorStuff() {
animator = UIDynamicAnimator(referenceView:self.view);
-
- gravity.gravityDirection = CGVectorMake(0, 0.8)
+
+ gravity.gravityDirection = CGVector(dx: 0, dy: 0.8)
animator?.addBehavior(gravity);
-
+
// We're bouncin' off the walls
collider.translatesReferenceBoundsIntoBoundary = true
animator?.addBehavior(collider)
-
+
itemBehavior.friction = 0.1;
itemBehavior.elasticity = 0.9
animator?.addBehavior(itemBehavior)
}
-
+
func addBoxToBehaviors(box: UIView) {
gravity.addItem(box)
collider.addItem(box)
itemBehavior.addItem(box)
}
-
+
//----------------- Core Motion
- func gravityUpdated(motion: CMDeviceMotion!, error: NSError!) {
- let grav : CMAcceleration = motion.gravity;
-
+ func gravityUpdated(motion: CMDeviceMotion?, error: Error?) {
+ let grav : CMAcceleration = motion!.gravity;
+
let x = CGFloat(grav.x);
let y = CGFloat(grav.y);
- var p = CGPointMake(x,y)
-
- if error {
+ var p = CGPoint(x: x, y: y)
+
+ if error != nil
+ {
NSLog("\(error)")
}
-
+
// Have to correct for orientation.
- var orientation = UIApplication.sharedApplication().statusBarOrientation;
-
- if(orientation == UIInterfaceOrientation.LandscapeLeft) {
- var t = p.x
+ let orientation = UIApplication.shared.statusBarOrientation;
+
+ if(orientation == UIInterfaceOrientation.landscapeLeft) {
+ let t = p.x
p.x = 0 - p.y
p.y = t
- } else if (orientation == UIInterfaceOrientation.LandscapeRight) {
- var t = p.x
+ } else if (orientation == UIInterfaceOrientation.landscapeRight) {
+ let t = p.x
p.x = p.y
p.y = 0 - t
- } else if (orientation == UIInterfaceOrientation.PortraitUpsideDown) {
+ } else if (orientation == UIInterfaceOrientation.portraitUpsideDown) {
p.x *= -1
p.y *= -1
}
- var v = CGVectorMake(p.x, 0 - p.y);
+ let v = CGVector(dx: p.x, dy: -p.y)
gravity.gravityDirection = v;
}
+
+ lazy var motionHandler : CMDeviceMotionHandler = {
+ (motion,error) in
+ self.gravityUpdated(motion: motion, error: error)
+ }
}
diff --git a/Rock BoxTests/Info.plist b/Rock BoxTests/Info.plist
index d0d081c..6d32c15 100644
--- a/Rock BoxTests/Info.plist
+++ b/Rock BoxTests/Info.plist
@@ -7,7 +7,7 @@
CFBundleExecutable
${EXECUTABLE_NAME}
CFBundleIdentifier
- com.bignerdranch.${PRODUCT_NAME:rfc1034identifier}
+ $(PRODUCT_BUNDLE_IDENTIFIER)
CFBundleInfoDictionaryVersion
6.0
CFBundleName
diff --git a/Rock BoxTests/Rock_BoxTests.swift b/Rock BoxTests/Rock_BoxTests.swift
index 0871ec7..85a1c67 100644
--- a/Rock BoxTests/Rock_BoxTests.swift
+++ b/Rock BoxTests/Rock_BoxTests.swift
@@ -27,7 +27,7 @@ class Rock_BoxTests: XCTestCase {
func testPerformanceExample() {
// This is an example of a performance test case.
- self.measureBlock() {
+ self.measure() {
// Put the code you want to measure the time of here.
}
}