Skip to content

Commit 11bca4a

Browse files
author
TBXark
committed
support swift 3
1 parent 6c02bcf commit 11bca4a

File tree

14 files changed

+266
-221
lines changed

14 files changed

+266
-221
lines changed

SwitcherCollection.xcodeproj/project.pbxproj

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@
6666
6A3D16ED1BE99A020018C0C4 /* Classes */ = {
6767
isa = PBXGroup;
6868
children = (
69+
6A3D16F01BE99A020018C0C4 /* TKBaseSwitcher.swift */,
6970
6A3D16EE1BE99A020018C0C4 /* TKExchangeSwitch.swift */,
7071
6A3D16EF1BE99A020018C0C4 /* TKLiquidSwitch.swift */,
71-
6A3D16F01BE99A020018C0C4 /* TKBaseSwitcher.swift */,
7272
6A3D16F11BE99A020018C0C4 /* TKSimpleSwitch.swift */,
7373
6A3D16F21BE99A020018C0C4 /* TKSmileSwitch.swift */,
7474
);
@@ -174,11 +174,12 @@
174174
attributes = {
175175
CLASSPREFIX = TK;
176176
LastSwiftUpdateCheck = 0710;
177-
LastUpgradeCheck = 0710;
177+
LastUpgradeCheck = 0800;
178178
ORGANIZATIONNAME = TBXark;
179179
TargetAttributes = {
180180
6A555E961BDCA58700FC36E6 = {
181181
CreatedOnToolsVersion = 7.1;
182+
LastSwiftMigration = 0800;
182183
};
183184
6A9104111D53A8740009451B = {
184185
CreatedOnToolsVersion = 7.3.1;
@@ -287,8 +288,10 @@
287288
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
288289
CLANG_WARN_EMPTY_BODY = YES;
289290
CLANG_WARN_ENUM_CONVERSION = YES;
291+
CLANG_WARN_INFINITE_RECURSION = YES;
290292
CLANG_WARN_INT_CONVERSION = YES;
291293
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
294+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
292295
CLANG_WARN_UNREACHABLE_CODE = YES;
293296
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
294297
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -310,7 +313,7 @@
310313
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
311314
GCC_WARN_UNUSED_FUNCTION = YES;
312315
GCC_WARN_UNUSED_VARIABLE = YES;
313-
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
316+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
314317
MTL_ENABLE_DEBUG_INFO = YES;
315318
ONLY_ACTIVE_ARCH = YES;
316319
SDKROOT = iphoneos;
@@ -331,8 +334,10 @@
331334
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
332335
CLANG_WARN_EMPTY_BODY = YES;
333336
CLANG_WARN_ENUM_CONVERSION = YES;
337+
CLANG_WARN_INFINITE_RECURSION = YES;
334338
CLANG_WARN_INT_CONVERSION = YES;
335339
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
340+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
336341
CLANG_WARN_UNREACHABLE_CODE = YES;
337342
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
338343
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -348,9 +353,10 @@
348353
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
349354
GCC_WARN_UNUSED_FUNCTION = YES;
350355
GCC_WARN_UNUSED_VARIABLE = YES;
351-
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
356+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
352357
MTL_ENABLE_DEBUG_INFO = NO;
353358
SDKROOT = iphoneos;
359+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
354360
VALIDATE_PRODUCT = YES;
355361
};
356362
name = Release;
@@ -360,9 +366,11 @@
360366
buildSettings = {
361367
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
362368
INFOPLIST_FILE = SwitcherCollection/Info.plist;
369+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
363370
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
364371
PRODUCT_BUNDLE_IDENTIFIER = com.TBXark.SwitcherCollection;
365372
PRODUCT_NAME = "$(TARGET_NAME)";
373+
SWIFT_VERSION = 3.0;
366374
};
367375
name = Debug;
368376
};
@@ -371,24 +379,27 @@
371379
buildSettings = {
372380
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
373381
INFOPLIST_FILE = SwitcherCollection/Info.plist;
382+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
374383
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
375384
PRODUCT_BUNDLE_IDENTIFIER = com.TBXark.SwitcherCollection;
376385
PRODUCT_NAME = "$(TARGET_NAME)";
386+
SWIFT_VERSION = 3.0;
377387
};
378388
name = Release;
379389
};
380390
6A9104171D53A8740009451B /* Debug */ = {
381391
isa = XCBuildConfiguration;
382392
buildSettings = {
383393
CLANG_ANALYZER_NONNULL = YES;
394+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
384395
CURRENT_PROJECT_VERSION = 1;
385396
DEFINES_MODULE = YES;
386397
DYLIB_COMPATIBILITY_VERSION = 1;
387398
DYLIB_CURRENT_VERSION = 1;
388399
DYLIB_INSTALL_NAME_BASE = "@rpath";
389400
INFOPLIST_FILE = TKSwitcherCollection/Info.plist;
390401
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
391-
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
402+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
392403
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
393404
PRODUCT_BUNDLE_IDENTIFIER = TBXark.TKSwitcherCollection;
394405
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -403,14 +414,15 @@
403414
isa = XCBuildConfiguration;
404415
buildSettings = {
405416
CLANG_ANALYZER_NONNULL = YES;
417+
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
406418
CURRENT_PROJECT_VERSION = 1;
407419
DEFINES_MODULE = YES;
408420
DYLIB_COMPATIBILITY_VERSION = 1;
409421
DYLIB_CURRENT_VERSION = 1;
410422
DYLIB_INSTALL_NAME_BASE = "@rpath";
411423
INFOPLIST_FILE = TKSwitcherCollection/Info.plist;
412424
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
413-
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
425+
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
414426
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
415427
PRODUCT_BUNDLE_IDENTIFIER = TBXark.TKSwitcherCollection;
416428
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -449,6 +461,7 @@
449461
6A9104181D53A8740009451B /* Release */,
450462
);
451463
defaultConfigurationIsVisible = 0;
464+
defaultConfigurationName = Release;
452465
};
453466
/* End XCConfigurationList section */
454467
};

SwitcherCollection.xcodeproj/xcuserdata/Tbxark.xcuserdatad/xcschemes/SwitcherCollection.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0710"
3+
LastUpgradeVersion = "0800"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

SwitcherCollection.xcodeproj/xcuserdata/Tbxark.xcuserdatad/xcschemes/TKSwitcherCollection.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0730"
3+
LastUpgradeVersion = "0800"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

SwitcherCollection/AppDelegate.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414
var window: UIWindow?
1515

1616

17-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
17+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1818
// Override point for customization after application launch.
1919
return true
2020
}
2121

22-
func applicationWillResignActive(application: UIApplication) {
22+
func applicationWillResignActive(_ application: UIApplication) {
2323
// 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.
2424
// 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.
2525
}
2626

27-
func applicationDidEnterBackground(application: UIApplication) {
27+
func applicationDidEnterBackground(_ application: UIApplication) {
2828
// 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.
2929
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
3030
}
3131

32-
func applicationWillEnterForeground(application: UIApplication) {
32+
func applicationWillEnterForeground(_ application: UIApplication) {
3333
// 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.
3434
}
3535

36-
func applicationDidBecomeActive(application: UIApplication) {
36+
func applicationDidBecomeActive(_ application: UIApplication) {
3737
// 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.
3838
}
3939

40-
func applicationWillTerminate(application: UIApplication) {
40+
func applicationWillTerminate(_ application: UIApplication) {
4141
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
4242
}
4343

SwitcherCollection/Classes/TKBaseSwitcher.swift

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,57 @@
88

99
import UIKit
1010

11-
typealias ValueChangeHook = (value:Bool) -> Void
12-
func CGPointScaleMaker(scale: CGFloat) -> ((CGFloat, CGFloat) -> CGPoint) {
11+
public typealias ValueChangeHook = (_ value: Bool) -> Void
12+
internal func CGPointScaleMaker(_ scale: CGFloat) -> ((CGFloat, CGFloat) -> CGPoint) {
1313
return { (x, y) in
14-
return CGPointMake(x * scale ,y * scale)}
14+
return CGPoint(x: x * scale ,y: y * scale)}
1515
}
1616

17+
protocol TKViewScale {}
18+
extension TKViewScale where Self: UIView {
19+
var sizeScale: CGFloat {
20+
return min(self.bounds.width, self.bounds.height)/100.0
21+
}
22+
}
1723

1824
// 自定义 Switch 基类
19-
class TKBaseSwitch: UIControl {
25+
open class TKBaseSwitch: UIControl {
2026

2127
// MARK: - Property
22-
var valueChange : ValueChangeHook?
23-
var on : Bool = true
24-
var animateDuration : Double = 0.4
25-
28+
open var valueChange : ValueChangeHook?
29+
internal var on : Bool = true
30+
open var animateDuration : Double = 0.4
31+
32+
func setOn(_ on: Bool, animate: Bool) {
33+
if on != isOn {
34+
changeValue()
35+
}
36+
}
2637

2738
// MARK: - Getter
28-
var isOn : Bool{
39+
open var isOn : Bool{
2940
return on
3041
}
3142

32-
func setUpView(){
43+
convenience public init() {
44+
self.init(frame: CGRect(x: 0, y: 0, width: 80, height: 40))
45+
}
46+
47+
48+
internal func setUpView(){
3349
let tap = UITapGestureRecognizer(target: self, action: #selector(TKBaseSwitch.changeValue))
3450
self.addGestureRecognizer(tap)
3551
}
3652

37-
func changeValue(){
53+
internal func changeValue(){
3854
if valueChange != nil{
39-
valueChange!(value: isOn)
55+
valueChange!(isOn)
4056
}
41-
sendActionsForControlEvents(UIControlEvents.ValueChanged);
57+
sendActions(for: UIControlEvents.valueChanged);
4258
on = !on
4359
}
4460

4561
}
4662

4763

48-
//活的视图缩放比例
49-
extension UIView{
50-
var sizeScale : CGFloat{
51-
return min(self.bounds.width, self.bounds.height)/100.0
52-
}
53-
}
54-
5564

0 commit comments

Comments
 (0)