Skip to content

Commit 82d721d

Browse files
authored
Merge pull request #2 from fabioalmeida/dev
Swift 4 migration
2 parents 90d29ab + 821b74c commit 82d721d

File tree

12 files changed

+43
-38
lines changed

12 files changed

+43
-38
lines changed

.swift-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0
1+
4.0

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
# * http://www.objc.io/issue-6/travis-ci.html
33
# * https://github.com/supermarin/xcpretty#usage
44

5-
osx_image: xcode8.3
5+
osx_image: xcode9
66
language: swift
77
cache: cocoapods
88
podfile: Example/Podfile
99
before_install:
1010
- gem install cocoapods # Since Travis is not always on latest version
1111
- pod install --project-directory=Example
1212
script:
13-
- set -o pipefail && xcodebuild test -workspace Example/LabelConfigurator.xcworkspace -scheme LabelConfigurator-Example -destination 'platform=iOS Simulator,name=iPhone 6s,OS=10.3.1' -sdk iphonesimulator10.3 ONLY_ACTIVE_ARCH=NO | xcpretty
13+
- set -o pipefail && xcodebuild test -workspace Example/LabelConfigurator.xcworkspace -scheme LabelConfigurator-Example -destination 'platform=iOS Simulator,name=iPhone 7,OS=11.0' -sdk iphonesimulator11.0 ONLY_ACTIVE_ARCH=NO | xcpretty
1414
- pod lib lint

Example/LabelConfigurator.xcodeproj/project.pbxproj

+8-8
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,11 @@
215215
TargetAttributes = {
216216
607FACCF1AFB9204008FA782 = {
217217
CreatedOnToolsVersion = 6.3.1;
218-
LastSwiftMigration = 0900;
218+
LastSwiftMigration = 0910;
219219
};
220220
607FACE41AFB9204008FA782 = {
221221
CreatedOnToolsVersion = 6.3.1;
222-
LastSwiftMigration = 0900;
222+
LastSwiftMigration = 0910;
223223
TestTargetID = 607FACCF1AFB9204008FA782;
224224
};
225225
};
@@ -466,7 +466,7 @@
466466
ONLY_ACTIVE_ARCH = YES;
467467
SDKROOT = iphoneos;
468468
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
469-
SWIFT_VERSION = 3.0;
469+
SWIFT_VERSION = 4.0;
470470
};
471471
name = Debug;
472472
};
@@ -512,7 +512,7 @@
512512
MTL_ENABLE_DEBUG_INFO = NO;
513513
SDKROOT = iphoneos;
514514
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
515-
SWIFT_VERSION = 3.0;
515+
SWIFT_VERSION = 4.0;
516516
VALIDATE_PRODUCT = YES;
517517
};
518518
name = Release;
@@ -529,7 +529,7 @@
529529
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
530530
PRODUCT_NAME = "$(TARGET_NAME)";
531531
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
532-
SWIFT_VERSION = 3.0;
532+
SWIFT_VERSION = 4.0;
533533
};
534534
name = Debug;
535535
};
@@ -545,7 +545,7 @@
545545
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
546546
PRODUCT_NAME = "$(TARGET_NAME)";
547547
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
548-
SWIFT_VERSION = 3.0;
548+
SWIFT_VERSION = 4.0;
549549
};
550550
name = Release;
551551
};
@@ -566,7 +566,7 @@
566566
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
567567
PRODUCT_NAME = "$(TARGET_NAME)";
568568
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
569-
SWIFT_VERSION = 3.0;
569+
SWIFT_VERSION = 4.0;
570570
};
571571
name = Debug;
572572
};
@@ -583,7 +583,7 @@
583583
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
584584
PRODUCT_NAME = "$(TARGET_NAME)";
585585
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
586-
SWIFT_VERSION = 3.0;
586+
SWIFT_VERSION = 4.0;
587587
};
588588
name = Release;
589589
};

Example/LabelConfigurator.xcodeproj/xcshareddata/xcschemes/LabelConfigurator-Example.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0900"
3+
LastUpgradeVersion = "0910"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict/>
5+
</plist>

Example/LabelConfigurator/ViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class ViewController: UIViewController {
6767
.set(textColor: .black)
6868
.set(textColor: .red, onSubstring: newPrice)
6969
.set(textColor: .lightGray, onSubstring: oldPrice)
70-
.set(attribute: NSStrikethroughStyleAttributeName, value: NSNumber(value: 1), onSubstring: oldPrice)
70+
.set(attribute: NSAttributedStringKey.strikethroughStyle, value: 1, onSubstring: oldPrice)
7171
.configure()
7272

7373
self.stackView.addArrangedSubview(label4)

Example/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- LabelConfigurator (0.1.2)
2+
- LabelConfigurator (0.3.0)
33

44
DEPENDENCIES:
55
- LabelConfigurator (from `../`)
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
99
:path: ../
1010

1111
SPEC CHECKSUMS:
12-
LabelConfigurator: 0f5235e9a35927dc55233ce511031c4f6f1dbc58
12+
LabelConfigurator: 39ff7b3dcdb2a78945a68ab34650a8f6ca833965
1313

1414
PODFILE CHECKSUM: 08e5c5bb7cf9dbc2a1d76bd7b3cf459830a63839
1515

Example/Pods/Manifest.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LabelConfigurator.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Pod::Spec.new do |s|
33
s.name = 'LabelConfigurator'
4-
s.version = '0.2.0'
4+
s.version = '0.3.0'
55
s.summary = 'The most simple way to configure your UILabels in one go'
66
s.description = <<-DESC
77
The most simple way to configure your UILabels in one go.
@@ -16,7 +16,7 @@ It also helps on the hard task of adding different style to substrings.
1616
s.social_media_url = 'https://twitter.com/fabioacalmeida'
1717

1818
s.ios.deployment_target = '9.0'
19-
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3.0' }
19+
s.pod_target_xcconfig = { 'SWIFT_VERSION' => '4.0' }
2020

2121
s.source_files = 'LabelConfigurator/Classes/**/*'
2222
end

LabelConfigurator/Classes/NSAttributedStringBuilder.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import Foundation
1111
private struct SubstringAttribute {
1212

1313
let substring: String
14-
let attribute: String
15-
let value: AnyObject
14+
let attribute: NSAttributedStringKey
15+
let value: Any
1616
}
1717

1818
private struct RangeAttribute {
1919

2020
let range: NSRange
21-
let attribute: String
22-
let value: AnyObject
21+
let attribute: NSAttributedStringKey
22+
let value: Any
2323
}
2424

2525
open class NSAttributedStringBuilder: NSObject {
@@ -90,19 +90,19 @@ open class NSAttributedStringBuilder: NSObject {
9090
@objc(setFont:onSubstring:)
9191
open func set(font: UIFont?, onSubstring substring: String?) -> NSAttributedStringBuilder {
9292

93-
return self.set(attribute: NSFontAttributeName, value: font, onSubstring: substring)
93+
return self.set(attribute: NSAttributedStringKey.font, value: font, onSubstring: substring)
9494
}
9595

9696
@discardableResult
9797
@objc(setTextColor:onSubstring:)
9898
open func set(textColor color: UIColor?, onSubstring substring: String?) -> NSAttributedStringBuilder {
9999

100-
return self.set(attribute: NSForegroundColorAttributeName, value: color, onSubstring: substring)
100+
return self.set(attribute: NSAttributedStringKey.foregroundColor, value: color, onSubstring: substring)
101101
}
102102

103103
@discardableResult
104104
@objc(setAttribute:value:onSubstring:)
105-
open func set(attribute: String?, value: AnyObject?, onSubstring substring: String?) -> NSAttributedStringBuilder {
105+
open func set(attribute: NSAttributedStringKey?, value: Any?, onSubstring substring: String?) -> NSAttributedStringBuilder {
106106

107107
if let attribute = attribute, let value = value, let substring = substring {
108108

@@ -121,7 +121,7 @@ open class NSAttributedStringBuilder: NSObject {
121121

122122
@discardableResult
123123
@objc(setAttribute:value:onRange:)
124-
open func set(attribute: String?, value: AnyObject?, onRange range: NSRange) -> NSAttributedStringBuilder {
124+
open func set(attribute: NSAttributedStringKey?, value: Any?, onRange range: NSRange) -> NSAttributedStringBuilder {
125125

126126
if let attribute = attribute, let value = value {
127127

@@ -151,17 +151,17 @@ private extension NSAttributedStringBuilder {
151151

152152
if let textColor = self.textColor {
153153

154-
attributedString.addAttribute(NSForegroundColorAttributeName, value: textColor, range: fullRange)
154+
attributedString.addAttribute(NSAttributedStringKey.foregroundColor, value: textColor, range: fullRange)
155155
}
156156

157157
if let textFont = self.textFont {
158158

159-
attributedString.addAttribute(NSFontAttributeName, value: textFont, range: fullRange)
159+
attributedString.addAttribute(NSAttributedStringKey.font, value: textFont, range: fullRange)
160160
}
161161

162162
if let fontTracking = self.fontTracking {
163163

164-
attributedString.addAttribute(NSKernAttributeName, value: fontTracking, range: fullRange)
164+
attributedString.addAttribute(NSAttributedStringKey.kern, value: fontTracking, range: fullRange)
165165
}
166166

167167
var paragraphStyle: NSMutableParagraphStyle?
@@ -184,7 +184,7 @@ private extension NSAttributedStringBuilder {
184184

185185
if let paragraphStyle = paragraphStyle {
186186

187-
attributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: fullRange)
187+
attributedString.addAttribute(NSAttributedStringKey.paragraphStyle, value: paragraphStyle, range: fullRange)
188188
}
189189

190190
if let substringAttributes = self.substringAttributes {

LabelConfigurator/Classes/UILabelBuilder.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ open class UILabelBuilder: NSObject {
117117

118118
@discardableResult
119119
@objc(setAttribute:value:onSubstring:)
120-
open func set(attribute: String, value: AnyObject, onSubstring substring: String) -> UILabelBuilder {
120+
open func set(attribute: NSAttributedStringKey, value: Any, onSubstring substring: String) -> UILabelBuilder {
121121

122122
self.attributedStringBuilder.set(attribute: attribute, value: value, onSubstring: substring)
123123
self.shouldSetAttributedText = true
@@ -126,7 +126,7 @@ open class UILabelBuilder: NSObject {
126126

127127
@discardableResult
128128
@objc(setAttribute:value:onRange:)
129-
open func set(attribute: String, value: AnyObject, onRange range: NSRange) -> UILabelBuilder {
129+
open func set(attribute: NSAttributedStringKey, value: Any, onRange range: NSRange) -> UILabelBuilder {
130130

131131
self.attributedStringBuilder.set(attribute: attribute, value: value, onRange: range)
132132
self.shouldSetAttributedText = true

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ platform :ios, '9.0'
3232
use_frameworks!
3333

3434
target 'TargetName' do
35-
pod 'LabelConfigurator', '~> 0.2.0'
35+
pod 'LabelConfigurator', '~> 0.3.0'
3636
end
3737
```
3838

@@ -46,7 +46,7 @@ After specifying the new dependency on the Podfile, just run `pod install` to ma
4646
To integrate `LabelConfigurator` into your Xcode project using Carthage, specify it in your `Cartfile`:
4747

4848
```ogdl
49-
github "fabioameida/LabelConfigurator" ~> 0.2.0
49+
github "fabioameida/LabelConfigurator" ~> 0.3.0
5050
```
5151

5252
Run `carthage update` to build the framework and drag the built `LabelConfigurator.framework` into your Xcode project.
@@ -107,8 +107,8 @@ The most common customisations done on `UILabels` are covered with helper method
107107
However, not all the possibilities are covered (and we want to keep it that way) on `UILabel` attributes and also `NSAttributedString`.
108108

109109
The good this is that you can add your custom attributes you wanted to add to your `NSAttributedString` using two convenience methods to do so:
110-
- `func set(attribute: String, value: AnyObject, onSubstring substring: String)`
111-
- `func set(attribute: String, value: AnyObject, onRange range: NSRange)`
110+
- `func set(attribute: NSAttributedStringKey, value: Any, onSubstring substring: String)`
111+
- `func set(attribute: NSAttributedStringKey, value: Any, onRange range: NSRange)`
112112

113113
For example, if you want to add a strikethrough attribute to a substring on your `UILabel`, you can do as the following
114114

@@ -121,7 +121,7 @@ self.myLabel.setLabelText("New price \(oldPrice) \(newPrice)")
121121
.set(textColor: .black)
122122
.set(textColor: .red, onSubstring: newPrice)
123123
.set(textColor: .lightGray, onSubstring: oldPrice)
124-
.set(attribute: NSStrikethroughStyleAttributeName, value: NSNumber(value: 1), onSubstring: oldPrice)
124+
.set(attribute: NSAttributedStringKey.strikethroughStyle, value: 1, onSubstring: oldPrice)
125125
.configure()
126126
```
127127

0 commit comments

Comments
 (0)