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

Changes to support swift3 #64

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions Example/MaterialKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,13 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Le Van Nghia";
TargetAttributes = {
8C4D638D1A160C95003629F6 = {
CreatedOnToolsVersion = 6.1;
DevelopmentTeam = PZK4944X96;
DevelopmentTeam = EA6VV6W3P4;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -350,8 +351,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 @@ -360,6 +363,7 @@
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",
Expand Down Expand Up @@ -393,15 +397,18 @@
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 = YES;
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;
Expand All @@ -411,6 +418,7 @@
IPHONEOS_DEPLOYMENT_TARGET = 8.1;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand All @@ -421,12 +429,14 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = EA6VV6W3P4;
INFOPLIST_FILE = MaterialKit/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.nghialv.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = com.fares.MaterialKit;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -436,12 +446,14 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = EA6VV6W3P4;
INFOPLIST_FILE = MaterialKit/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.nghialv.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = com.fares.MaterialKit;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion Example/MaterialKit/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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
}
Expand Down
184 changes: 91 additions & 93 deletions Example/MaterialKit/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Example/MaterialKit/MyCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ class MyCell : MKTableViewCell {
@IBOutlet var messageLabel: UILabel!

override var layoutMargins: UIEdgeInsets {
get { return UIEdgeInsetsZero }
get { return UIEdgeInsets.zero }
set(newVal) {}
}

func setMessage(message: String) {
func setMessage(_ message: String) {
messageLabel.text = message
}
}
16 changes: 8 additions & 8 deletions Example/MaterialKit/TableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@ class TableViewController: UIViewController, UITableViewDelegate, UITableViewDat
})
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 100
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 65.0
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("MyCell") as! MyCell
cell.setMessage(labels[indexPath.row % labels.count])
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell") as! MyCell
cell.setMessage(labels[(indexPath as NSIndexPath).row % labels.count])

let index = indexPath.row % circleColors.count
let index = (indexPath as NSIndexPath).row % circleColors.count
cell.rippleLayerColor = circleColors[index]

return cell
}

func tableViewRefresh() {
NSLog("Refresh Block")
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), { () -> Void in
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(5 * NSEC_PER_SEC)) / Double(NSEC_PER_SEC), execute: { () -> Void in
NSLog("End refreshing")
self.refreshView!.endRefreshing()
})
}
}
}
6 changes: 3 additions & 3 deletions Example/MaterialKit/TextFieldViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ class TextFieldViewController: UIViewController {
@IBOutlet weak var textField1: MKTextField!

override func viewDidLoad() {
textField1.layer.borderColor = UIColor.clearColor().CGColor
textField1.layer.borderColor = UIColor.clear.cgColor
}

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
}
}
10 changes: 5 additions & 5 deletions Example/MaterialKit/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import UIKit

class ViewController: UIViewController {

override func viewWillAppear(animated: Bool) {
override func viewWillAppear(_ animated: Bool) {
let hamburgerButton = MKButton(frame: CGRect(x: 0, y: 0, width: 44, height: 32))
hamburgerButton.setImage(UIImage(named: "uibaritem_icon.png"), forState: .Normal)
hamburgerButton.setImage(UIImage(named: "uibaritem_icon.png"), for: UIControlState())
hamburgerButton.maskEnabled = false
hamburgerButton.backgroundAnimationEnabled = false
hamburgerButton.rippleDuration = 0.15
hamburgerButton.addTarget(self, action: Selector("toggleDrawer"), forControlEvents: UIControlEvents.TouchUpInside)
hamburgerButton.addTarget(self, action: #selector(ViewController.toggleDrawer), for: UIControlEvents.touchUpInside)
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: hamburgerButton)
}

Expand All @@ -26,7 +26,7 @@ class ViewController: UIViewController {
}
}

@IBAction func cardViewClicked(sender: AnyObject) {
@IBAction func cardViewClicked(_ sender: AnyObject) {
let snackbar = MKSnackbar(
withTitle: "You clicked on CardView\nThis is a SnackBar :)",
withDuration: nil,
Expand All @@ -35,4 +35,4 @@ class ViewController: UIViewController {
withActionButtonColor: UIColor.MKColor.Red.P100)
snackbar.show()
}
}
}
54 changes: 27 additions & 27 deletions Source/MKActivityIndicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
import UIKit

@IBDesignable
public class MKActivityIndicator: UIView {
open class MKActivityIndicator: UIView {

private let drawableLayer = CAShapeLayer()
private var animating = false
fileprivate let drawableLayer = CAShapeLayer()
fileprivate var animating = false

@IBInspectable public var color: UIColor = UIColor.MKColor.Blue.P500 {
@IBInspectable open var color: UIColor = UIColor.MKColor.Blue.P500 {
didSet {
drawableLayer.strokeColor = self.color.CGColor
drawableLayer.strokeColor = self.color.cgColor
}
}

@IBInspectable public var lineWidth: CGFloat = 6 {
@IBInspectable open var lineWidth: CGFloat = 6 {
didSet {
drawableLayer.lineWidth = self.lineWidth
self.updatePath()
Expand All @@ -37,73 +37,73 @@ public class MKActivityIndicator: UIView {
setup()
}

public override var bounds: CGRect {
open override var bounds: CGRect {
didSet {
updateFrame()
updatePath()
}
}

public override func layoutSubviews() {
open override func layoutSubviews() {
super.layoutSubviews()
updateFrame()
updatePath()
}

public func startAnimating() {
open func startAnimating() {
if self.animating {
return
}

self.animating = true
self.hidden = false
self.isHidden = false
self.resetAnimations()
}

public func stopAnimating() {
open func stopAnimating() {
self.drawableLayer.removeAllAnimations()
self.animating = false
self.hidden = true
self.isHidden = true
}

private func setup() {
self.hidden = true
fileprivate func setup() {
self.isHidden = true
self.layer.addSublayer(self.drawableLayer)
self.drawableLayer.strokeColor = self.color.CGColor
self.drawableLayer.strokeColor = self.color.cgColor
self.drawableLayer.lineWidth = self.lineWidth
self.drawableLayer.fillColor = UIColor.clearColor().CGColor
self.drawableLayer.fillColor = UIColor.clear.cgColor
self.drawableLayer.lineCap = kCALineJoinRound
self.drawableLayer.strokeStart = 0.99
self.drawableLayer.strokeEnd = 1
updateFrame()
updatePath()
}

private func updateFrame() {
self.drawableLayer.frame = CGRectMake(0, 0, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds))
fileprivate func updateFrame() {
self.drawableLayer.frame = CGRect(x: 0, y: 0, width: self.bounds.width, height: self.bounds.height)
}

private func updatePath() {
let center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds))
let radius = min(CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)) / 2 - self.lineWidth
fileprivate func updatePath() {
let center = CGPoint(x: self.bounds.midX, y: self.bounds.midY)
let radius = min(self.bounds.width, self.bounds.height) / 2 - self.lineWidth
self.drawableLayer.path = UIBezierPath(
arcCenter: center,
radius: radius,
startAngle: 0,
endAngle: CGFloat(2 * M_PI),
clockwise: true)
.CGPath
.cgPath
}

private func resetAnimations() {
fileprivate func resetAnimations() {
drawableLayer.removeAllAnimations()

let rotationAnim = CABasicAnimation(keyPath: "transform.rotation")
rotationAnim.fromValue = 0
rotationAnim.duration = 4
rotationAnim.toValue = 2 * M_PI
rotationAnim.repeatCount = Float.infinity
rotationAnim.removedOnCompletion = false
rotationAnim.isRemovedOnCompletion = false

let startHeadAnim = CABasicAnimation(keyPath: "strokeStart")
startHeadAnim.beginTime = 0.1
Expand Down Expand Up @@ -137,9 +137,9 @@ public class MKActivityIndicator: UIView {
strokeAnimGroup.duration = 1.5
strokeAnimGroup.animations = [startHeadAnim, startTailAnim, endHeadAnim, endTailAnim]
strokeAnimGroup.repeatCount = Float.infinity
strokeAnimGroup.removedOnCompletion = false
strokeAnimGroup.isRemovedOnCompletion = false

self.drawableLayer.addAnimation(rotationAnim, forKey: "rotation")
self.drawableLayer.addAnimation(strokeAnimGroup, forKey: "stroke")
self.drawableLayer.add(rotationAnim, forKey: "rotation")
self.drawableLayer.add(strokeAnimGroup, forKey: "stroke")
}
}
Loading