Skip to content

Commit

Permalink
Update to Swift 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Domas Nutautas committed Feb 10, 2017
1 parent 077fe0a commit 87c689a
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 30 deletions.
8 changes: 5 additions & 3 deletions TextStyle.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
};
D36852C91DAE4A1B00EDFCA1 = {
CreatedOnToolsVersion = 8.0;
LastSwiftMigration = 0800;
LastSwiftMigration = 0820;
ProvisioningStyle = Automatic;
};
};
Expand Down Expand Up @@ -352,7 +352,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -398,7 +398,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -422,6 +422,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -440,6 +441,7 @@
PRODUCT_BUNDLE_IDENTIFIER = Trafi.TextStyle;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
8 changes: 4 additions & 4 deletions TextStyle/Source/Extensions/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
import Foundation

extension String {
public func with(textStyle textStyle: TextStyle) -> NSAttributedString {
public func with(textStyle: TextStyle) -> NSAttributedString {
return NSAttributedString(string: self, attributes: textStyle.attributes)
}
public func with(textStyle textStyle: TextStyle, forRange range: NSRange) -> NSAttributedString {
public func with(textStyle: TextStyle, forRange range: NSRange) -> NSAttributedString {
return NSAttributedString(string: self).with(textStyle: textStyle, forRange: range)
}
}

extension NSAttributedString {
public func with(textStyle textStyle: TextStyle) -> NSAttributedString {
public func with(textStyle: TextStyle) -> NSAttributedString {
return string.with(textStyle: textStyle)
}
public func with(textStyle textStyle: TextStyle, forRange range: NSRange) -> NSAttributedString {
public func with(textStyle: TextStyle, forRange range: NSRange) -> NSAttributedString {
let mutable = self as? NSMutableAttributedString ?? NSMutableAttributedString(attributedString: self)
mutable.setAttributes(textStyle.attributes, range: range)
return mutable
Expand Down
4 changes: 2 additions & 2 deletions TextStyle/Source/Extensions/UIButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import UIKit
// MARK: TextStylable

extension UIButton: TextStylable {
public func set(textStyle textStyle: TextStyle) {
public func set(textStyle: TextStyle) {
if let color = textStyle.color {
setTitleColor(color, forState: .Normal)
setTitleColor(color, for: UIControlState())
}
titleLabel?.set(textStyle: textStyle)
}
Expand Down
2 changes: 1 addition & 1 deletion TextStyle/Source/Extensions/UILabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit
// MARK: TextStylable

extension UILabel: TextStylable {
public func set(textStyle textStyle: TextStyle) {
public func set(textStyle: TextStyle) {
if let textColor = textStyle.color {
self.textColor = textColor
}
Expand Down
2 changes: 1 addition & 1 deletion TextStyle/Source/Extensions/UITextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit
// MARK: TextStylable

extension UITextField: TextStylable {
public func set(textStyle textStyle: TextStyle) {
public func set(textStyle: TextStyle) {
if let textColor = textStyle.color {
self.textColor = textColor
}
Expand Down
2 changes: 1 addition & 1 deletion TextStyle/Source/Extensions/UITextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import UIKit
// MARK: TextStylable

extension UITextView: TextStylable {
public func set(textStyle textStyle: TextStyle) {
public func set(textStyle: TextStyle) {
if let textColor = textStyle.color {
self.textColor = textColor
}
Expand Down
2 changes: 1 addition & 1 deletion TextStyle/Source/TextStylable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
import Foundation

public protocol TextStylable {
func set(textStyle textStyle: TextStyle)
func set(textStyle: TextStyle)
}
14 changes: 7 additions & 7 deletions TextStyle/Source/TextStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ public struct TextStyle {
}

public extension TextStyle {
private func with(@noescape changes: (inout TextStyle) -> ()) -> TextStyle {
private func with(_ changes: (inout TextStyle) -> ()) -> TextStyle {
var changedTextStyle = self
changes(&changedTextStyle)
return changedTextStyle
}

func with(font font: UIFont) -> TextStyle {
return with{ $0.font = font }
func with(font: UIFont) -> TextStyle {
return with({ $0.font = font })
}
func with(color color: UIColor) -> TextStyle {
return with{ $0.color = color }
func with(color: UIColor) -> TextStyle {
return with({ $0.color = color })
}
func with(alignment alignment: NSTextAlignment) -> TextStyle {
return with{ $0.alignment = alignment }
func with(alignment: NSTextAlignment) -> TextStyle {
return with({ $0.alignment = alignment })
}
}
12 changes: 6 additions & 6 deletions TextStyleExample/TextStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import TextStyle

extension TextStyle {
static let header = TextStyle()
.with(font: .boldSystemFontOfSize(18))
.with(color: .redColor())
.with(alignment: .Center)
.with(font: .boldSystemFont(ofSize: 18))
.with(color: .red)
.with(alignment: .center)

static let body = TextStyle()
.with(font: .systemFontOfSize(16))
.with(font: .systemFont(ofSize: 16))

static let footer = TextStyle()
.with(font: .italicSystemFontOfSize(12))
.with(color: .grayColor())
.with(font: .italicSystemFont(ofSize: 12))
.with(color: .gray)
}

extension TextStyle: IBInspectable {
Expand Down
8 changes: 4 additions & 4 deletions TextStyleExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ class ViewController: UIViewController {

@IBOutlet var label: UILabel! {
didSet {
label.set(textStyle: TextStyle.header.with(color: .blueColor()))
label.set(textStyle: TextStyle.header.with(color: .blue))
label.text = "From code"
}
}

@IBOutlet var attributedLabel: UILabel! {
didSet {
let style = TextStyle()
.with(font: .italicSystemFontOfSize(18))
.with(color: .grayColor())
.with(alignment: .Right)
.with(font: .italicSystemFont(ofSize: 18))
.with(color: .gray)
.with(alignment: .right)

attributedLabel.attributedText = "Attributed string\nFrom code".with(textStyle: style)
}
Expand Down

0 comments on commit 87c689a

Please sign in to comment.