Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to Swift 3 #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion Plum-o-Meter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0710;
LastUpgradeCheck = 0710;
LastUpgradeCheck = 0810;
ORGANIZATIONNAME = "Simon Gladman";
TargetAttributes = {
3ECBB7CE1BDBB8AA00328B67 = {
CreatedOnToolsVersion = 7.1;
LastSwiftMigration = 0810;
};
};
};
Expand Down Expand Up @@ -175,8 +176,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";
Expand Down Expand Up @@ -220,8 +223,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";
Expand All @@ -240,6 +245,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
Expand All @@ -253,6 +259,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "uk.co.flexmonkey.Plum-o-Meter";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -264,6 +271,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "uk.co.flexmonkey.Plum-o-Meter";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -286,6 +294,7 @@
3ECBB7E31BDBB8AA00328B67 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
12 changes: 6 additions & 6 deletions Plum-o-Meter/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> 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:.
}

Expand Down
46 changes: 21 additions & 25 deletions Plum-o-Meter/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ class ViewController: UIViewController
{
super.viewDidLoad()

view.multipleTouchEnabled = true
view.isMultipleTouchEnabled = true

label.text = "lay your plums on me."

label.textAlignment = NSTextAlignment.Center
label.textAlignment = NSTextAlignment.center

view.addSubview(label)
}

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?)
{
label.hidden = true
label.isHidden = true

for touch in touches
{
let circle = CircleWithLabel()

circle.drawAtPoint(touch.locationInView(view),
circle.drawAtPoint(touch.location(in: view),
force: touch.force / touch.maximumPossibleForce)

circles[touch] = circle
Expand All @@ -46,38 +46,34 @@ class ViewController: UIViewController
highlightHeaviest()
}

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?)
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?)
{
for touch in touches where circles[touch] != nil
{
let circle = circles[touch]!

circle.drawAtPoint(touch.locationInView(view),
circle.drawAtPoint(touch.location(in: view),
force: touch.force / touch.maximumPossibleForce)
}

highlightHeaviest()
}

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?)
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?)
{
for touch in touches where circles[touch] != nil
{
let circle = circles[touch]!

circles.removeValueForKey(touch)
circles.removeValue(forKey: touch)
circle.removeFromSuperlayer()
}

highlightHeaviest()
}

override func touchesCancelled(touches: Set<UITouch>?, withEvent event: UIEvent?)
override func touchesCancelled(_ touches: Set<UITouch>, with event: UIEvent?)
{
guard let touches = touches else
{
return
}

for touch in touches where circles[touch] != nil
{
Expand All @@ -91,7 +87,7 @@ class ViewController: UIViewController
{
func getMaxTouch() -> UITouch?
{
return circles.sort({
return circles.sorted(by: {
(a: (UITouch, CircleWithLabel), b: (UITouch, CircleWithLabel)) -> Bool in

return a.0.force > b.0.force
Expand All @@ -104,9 +100,9 @@ class ViewController: UIViewController
}
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask
override var supportedInterfaceOrientations : UIInterfaceOrientationMask
{
return UIInterfaceOrientationMask.Landscape
return UIInterfaceOrientationMask.landscape
}

override func viewDidLayoutSubviews()
Expand All @@ -125,16 +121,16 @@ class CircleWithLabel: CAShapeLayer
{
super.init()

text.foregroundColor = UIColor.blueColor().CGColor
text.foregroundColor = UIColor.blue.cgColor
text.alignmentMode = kCAAlignmentCenter
addSublayer(text)

strokeColor = UIColor.blueColor().CGColor
strokeColor = UIColor.blue.cgColor
lineWidth = 5
fillColor = nil
}

override init(layer: AnyObject)
override init(layer: Any)
{
super.init(layer: layer)
}
Expand All @@ -148,18 +144,18 @@ class CircleWithLabel: CAShapeLayer
{
didSet
{
fillColor = isMax ? UIColor.yellowColor().CGColor : nil
fillColor = isMax ? UIColor.yellow.cgColor : nil
}
}

func drawAtPoint(location: CGPoint, force: CGFloat)
func drawAtPoint(_ location: CGPoint, force: CGFloat)
{
let radius = 120 + (force * 120)

path = UIBezierPath(
ovalInRect: CGRect(
ovalIn: CGRect(
origin: location.offset(dx: radius, dy: radius),
size: CGSize(width: radius * 2, height: radius * 2))).CGPath
size: CGSize(width: radius * 2, height: radius * 2))).cgPath

text.string = String(format: "%.1f%%", force * 100)

Expand All @@ -171,7 +167,7 @@ class CircleWithLabel: CAShapeLayer

extension CGPoint
{
func offset(dx dx: CGFloat, dy: CGFloat) -> CGPoint
func offset(dx: CGFloat, dy: CGFloat) -> CGPoint
{
return CGPoint(x: self.x - dx, y: self.y - dy)
}
Expand Down