Skip to content
Permalink
Browse files

update to swift 4

  • Loading branch information
ezefranca committed Aug 18, 2018
1 parent d7750c5 commit 284a6ace3c57e10e975e726c0bc1d7c914afb7c4
@@ -19,6 +19,7 @@ import CoreMotion
/// - shakeSensibilityHardest: Hardest shake sensibility
enum ShakeSensibility: Double {
typealias RawValue = Double
case shakeSensibilitySoftest = 0.1
case shakeSensibilitySoft = 0.7
case shakeSensibilityNormal = 1.0
@@ -32,7 +33,7 @@ protocol WatchShakerDelegate
/// Called when Apple Watch are shaked
///
/// - Parameter watchShaker: the watch shaker instance
func watchShakerDidShake(_ watchShaker: WatchShaker)
func watchShaker(_ watchShaker: WatchShaker, didShakeWith sensibility:ShakeSensibility)

/// Called when Something are wrong
///
@@ -59,14 +60,15 @@ extension WatchShaker {
}


class WatchShaker
class WatchShaker : NSObject
{
public var delegate: WatchShakerDelegate?

fileprivate var motionManager: CMMotionManager!
fileprivate var lastShakeDate: Date?
// The threshold for how much acceleration needs to happen before an event will register.
fileprivate var threshold:Double
fileprivate var sensibility:ShakeSensibility
// Time between shakes
fileprivate var delay:Double = 0.1

@@ -79,6 +81,7 @@ class WatchShaker
init(shakeSensibility to:ShakeSensibility, delay time:Double) {
self.threshold = to.rawValue
self.delay = time
self.sensibility = to
self.motionManager = CMMotionManager()
}

@@ -118,13 +121,13 @@ class WatchShaker
if Date().compare(lastDate.addingTimeInterval(self.delay)) == .orderedDescending
{
self.lastShakeDate = Date()
self.delegate?.watchShakerDidShake(self)
self.delegate?.watchShaker(self, didShakeWith: self.sensibility)
}
return
}

self.lastShakeDate = Date()
self.delegate?.watchShakerDidShake(self)
self.delegate?.watchShaker(self, didShakeWith: self.sensibility)
}
}
}
@@ -1,18 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="12121" systemVersion="16G1036" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="AgC-eL-Hgc">
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="14113" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="AgC-eL-Hgc">
<device id="watch38" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="watchOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="12029"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="14033"/>
</dependencies>
<scenes>
<!--Interface Controller-->
<scene sceneID="aou-V4-d1y">
<objects>
<controller id="AgC-eL-Hgc" customClass="InterfaceController" customModule="WatchShaker_WatchKit_App" customModuleProvider="target"/>
<controller id="AgC-eL-Hgc" customClass="InterfaceController" customModule="WatchShaker_WatchKit_App" customModuleProvider="target">
<items>
<group width="1" height="1" alignment="left" id="ncX-kr-CuE">
<items>
<label alignment="center" verticalAlignment="center" id="oU8-rf-Reh"/>
</items>
</group>
</items>
<connections>
<outlet property="infoLabel" destination="oU8-rf-Reh" id="PPf-em-zv3"/>
</connections>
</controller>
</objects>
<point key="canvasLocation" x="220" y="345"/>
</scene>
@@ -19,6 +19,7 @@ class InterfaceController: WKInterfaceController {

var shaker:WatchShaker = WatchShaker(shakeSensibility: .shakeSensibilityNormal, delay: 0.2)

@IBOutlet var infoLabel: WKInterfaceLabel!
override func willActivate() {

super.willActivate()
@@ -33,15 +34,26 @@ class InterfaceController: WKInterfaceController {

}

func printInfo(_ string:String) {
self.infoLabel.setText(string)
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
self.infoLabel.setText("")
}
}

}

extension InterfaceController: WatchShakerDelegate
{
func watchShakerDidShake(_ watchShaker: WatchShaker) {
print("YOU HAVE SHAKEN YOUR ⌚️⌚️⌚️")
func watchShaker(_ watchShaker: WatchShaker, didShakeWith sensibility: ShakeSensibility) {
let message = "YOU HAVE SHAKEN YOUR ⌚️⌚️⌚️"
print(message)
printInfo(message)

}

func watchShaker(_ watchShaker: WatchShaker, didFailWith error: Error) {
print(error.localizedDescription)
printInfo(error.localizedDescription)
}
}
@@ -267,7 +267,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0810;
LastUpgradeCheck = 0810;
LastUpgradeCheck = 0940;
ORGANIZATIONNAME = "Ezequiel França @ezefranca";
TargetAttributes = {
8B2227831DFB90E100C09475 = {
@@ -278,17 +278,20 @@
8B2227971DFB90E200C09475 = {
CreatedOnToolsVersion = 8.1;
DevelopmentTeam = 54JDK55DR5;
LastSwiftMigration = 0940;
ProvisioningStyle = Automatic;
TestTargetID = 8B2227831DFB90E100C09475;
};
8B2227A01DFB90E200C09475 = {
CreatedOnToolsVersion = 8.1;
DevelopmentTeam = 54JDK55DR5;
LastSwiftMigration = 0940;
ProvisioningStyle = Automatic;
};
8B2227AF1DFB90E200C09475 = {
CreatedOnToolsVersion = 8.1;
DevelopmentTeam = 54JDK55DR5;
LastSwiftMigration = 0940;
ProvisioningStyle = Automatic;
};
};
@@ -436,15 +439,24 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -485,15 +497,24 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -529,7 +550,8 @@
PRODUCT_NAME = "${TARGET_NAME}";
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 3.1;
};
@@ -546,7 +568,8 @@
PRODUCT_NAME = "${TARGET_NAME}";
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 3.1;
};
@@ -564,7 +587,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 3.1;
};
@@ -582,7 +606,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = watchos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = 4;
WATCHOS_DEPLOYMENT_TARGET = 3.1;
};
@@ -597,7 +622,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.ezefranca.WatchShaker;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
@@ -610,7 +635,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.ezefranca.WatchShaker;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
@@ -624,7 +649,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.ezefranca.WatchShakerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/WatchShaker.app/WatchShaker";
};
name = Debug;
@@ -639,7 +665,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.ezefranca.WatchShakerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/WatchShaker.app/WatchShaker";
};
name = Release;

0 comments on commit 284a6ac

Please sign in to comment.
You can’t perform that action at this time.