Skip to content

Commit 9bd72fb

Browse files
committed
updated to swift3 syntax
1 parent 6317eca commit 9bd72fb

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

UIKitExtensions/UIColorExtension.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ public extension UIColor {
1616
- Returns: UIColor
1717
*/
1818
public static func randomColor() -> UIColor {
19-
return UIColor(red: CGFloat(randomFloat(0, upper: 255.0)) / 255.0, green: CGFloat(randomFloat(0, upper: 255.0)) / 255.0, blue: CGFloat(randomFloat(0, upper: 255.0)) / 255.0, alpha: 1)
19+
return UIColor(
20+
red: CGFloat(randomFloat(0, 255.0)) / 255.0,
21+
green: CGFloat(randomFloat(0, 255.0)) / 255.0,
22+
blue: CGFloat(randomFloat(0, 255.0)) / 255.0,
23+
alpha: 1
24+
)
2025
}
2126

2227
/**
@@ -28,7 +33,7 @@ public extension UIColor {
2833

2934
- Returns: UIColor
3035
*/
31-
private static func randomFloat(lower: Float = 0.0, upper: Float = 1.0) -> Float {
36+
fileprivate static func randomFloat(_ lower: Float = 0.0, _ upper: Float = 1.0) -> Float {
3237
let r = Float(arc4random()) / Float(UInt32.max)
3338
return (r * (upper - lower)) + lower
3439
}
@@ -40,12 +45,12 @@ public extension UIColor {
4045

4146
- Returns: UIColor
4247
*/
43-
public static func colorFromHex(hex: String) -> UIColor {
44-
let scanner = NSScanner(string: hex)
45-
scanner.charactersToBeSkipped = NSCharacterSet.alphanumericCharacterSet().invertedSet
48+
public static func colorFromHex(_ hex: String) -> UIColor {
49+
let scanner = Scanner(string: hex)
50+
//scanner.charactersToBeSkipped = NSCharacterSet.alphanumericCharacterSet.invertedSet
4651

4752
var value: UInt32 = 0;
48-
scanner.scanHexInt(&value)
53+
scanner.scanHexInt32(&value)
4954

5055
let red = CGFloat(Float(Int(value >> 16) & 0x000000FF) / 255.0)
5156
let green = CGFloat(Float(Int(value >> 8) & 0x000000FF) / 255.0)

UIKitExtensions/UIFontExtension.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public extension UIFont {
1818

1919
- Return: UIFont
2020
*/
21-
public static func fontNamed(customFontName: String, ofSize fontSize: CGFloat) -> UIFont {
21+
public static func fontNamed(_ customFontName: String, ofSize fontSize: CGFloat) -> UIFont {
2222
return UIFont(name: customFontName, size: fontSize)!
2323
}
2424
}

UIKitExtensions/UIViewExtension.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,42 +21,42 @@ extension UIView {
2121
self.fadeOutNowWithCallback(nil)
2222
}
2323

24-
func fadeInNowWithCallback(completion: AnimationCompletionBlock?) {
25-
UIView.animateWithDuration(0.5, delay: 0, options: .CurveEaseOut, animations: {
24+
func fadeInNowWithCallback(_ completion: AnimationCompletionBlock?) {
25+
UIView.animate(withDuration: 0.5, delay: 0, options: .curveEaseOut, animations: {
2626
self.alpha = 1.0
2727
}, completion: completion)
2828
}
2929

30-
func fadeOutNowWithCallback(completion: AnimationCompletionBlock?) {
31-
UIView.animateWithDuration(0.5, delay: 0, options: .CurveEaseOut, animations: {
30+
func fadeOutNowWithCallback(_ completion: AnimationCompletionBlock?) {
31+
UIView.animate(withDuration: 0.5, delay: 0, options: .curveEaseOut, animations: {
3232
self.alpha = 0.0
3333
}, completion: completion)
3434
}
3535

3636
func flash() {
37-
UIView.animateWithDuration(0.1, delay: 0, options: .CurveEaseOut, animations: { () -> Void in
37+
UIView.animate(withDuration: 0.1, delay: 0, options: .curveEaseOut, animations: { () -> Void in
3838
self.alpha = 1
3939
}) { (param) -> Void in
40-
UIView.animateWithDuration(0.1, delay: 0, options: .CurveEaseOut, animations: {
40+
UIView.animate(withDuration: 0.1, delay: 0, options: .curveEaseOut, animations: {
4141
self.alpha = 0
4242
}, completion: nil)
4343
}
4444
}
4545

4646
// MARK: Resizing animations
47-
func resizeWithFactor(factor: CGFloat) {
47+
func resizeWithFactor(_ factor: CGFloat) {
4848
self.resizeWithFactor(factor, completion: nil)
4949
}
5050

51-
func resizeWithFactor(factor: CGFloat, completion: AnimationCompletionBlock?) {
51+
func resizeWithFactor(_ factor: CGFloat, completion: AnimationCompletionBlock?) {
5252
let currentFrame = self.frame
5353
let width = currentFrame.size.width * factor
5454
let height = currentFrame.size.height * factor
5555
let leftOffset = (currentFrame.origin.x + (currentFrame.size.width * (1.0 - factor))) / 2
5656
let topOffset = (currentFrame.origin.y + (currentFrame.size.height * (1.0 - factor))) / 2
57-
let newFrame : CGRect = CGRectMake(leftOffset, topOffset, width, height)
57+
let newFrame : CGRect = CGRect(x: leftOffset, y: topOffset, width: width, height: height)
5858

59-
UIView.animateWithDuration(0.4, delay: 0, options: .CurveEaseOut, animations: {
59+
UIView.animate(withDuration: 0.4, delay: 0, options: .curveEaseOut, animations: {
6060
self.frame = newFrame
6161
}, completion: completion)
6262
}
@@ -66,11 +66,11 @@ extension UIView {
6666
self.slideUp(nil)
6767
}
6868

69-
func slideUp(completion: ((Bool) -> Void)?) {
70-
let screenBound = UIScreen.mainScreen().bounds
69+
func slideUp(_ completion: ((Bool) -> Void)?) {
70+
let screenBound = UIScreen.main.bounds
7171
let currentFrame = self.frame
72-
let newFrame : CGRect = CGRectMake(currentFrame.origin.x, currentFrame.origin.y - screenBound.size.height, currentFrame.size.width, currentFrame.size.height)
73-
UIView.animateWithDuration(0.3, delay: 0, options: .CurveEaseOut, animations: {
72+
let newFrame : CGRect = CGRect(x: currentFrame.origin.x, y: currentFrame.origin.y - screenBound.size.height, width: currentFrame.size.width, height: currentFrame.size.height)
73+
UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseOut, animations: {
7474
self.frame = newFrame
7575
}, completion: completion)
7676
}
@@ -79,11 +79,11 @@ extension UIView {
7979
self.slideDown(nil)
8080
}
8181

82-
func slideDown(completion: ((Bool) -> Void)?) {
83-
let screenBound = UIScreen.mainScreen().bounds
82+
func slideDown(_ completion: ((Bool) -> Void)?) {
83+
let screenBound = UIScreen.main.bounds
8484
let currentFrame = self.frame
85-
let newFrame : CGRect = CGRectMake(currentFrame.origin.x, currentFrame.origin.y + screenBound.size.height, currentFrame.size.width, currentFrame.size.height)
86-
UIView.animateWithDuration(0.3, delay: 0, options: .CurveEaseOut, animations: {
85+
let newFrame : CGRect = CGRect(x: currentFrame.origin.x, y: currentFrame.origin.y + screenBound.size.height, width: currentFrame.size.width, height: currentFrame.size.height)
86+
UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseOut, animations: {
8787
self.frame = newFrame
8888
}, completion: completion)
8989
}

0 commit comments

Comments
 (0)