Skip to content

Commit

Permalink
Fix instantiating NSMutableAttributeString with attributes on Xcode 1…
Browse files Browse the repository at this point in the history
…0's Swift compiler

When instantiating an `NSMutableAttributedString` in a target that imports SwiftyAttributes on Xcode 10 the compiler was getting confused on which initializer to use. The convenience initializer added to `NSAttributedString` seems to be throwing the compiler out of whack. This updates argument names to give a clearer distinction and resolves the issue.

See issue eddiekaiger#29 for more details.
  • Loading branch information
ketzusaka committed Jun 25, 2018
1 parent 68ab023 commit 655c2d7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion SwiftyAttributes.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Pod::Spec.new do |s|

s.name = "SwiftyAttributes"
s.version = "4.3.0"
s.version = "5.0.0"
s.summary = "A Swifty API for attributed strings."

s.description = <<-DESC
Expand Down
2 changes: 1 addition & 1 deletion SwiftyAttributes/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>3.1.0</string>
<string>5.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ extension NSAttributedString {
/**
Creates a new `NSAttributedString` with the specified attributes.

- parameter str: The string for the new attributed string.
- parameter attributes: The attributes for the new attributed string.
- parameter str: The string for the new attributed string.
- parameter swiftyAttributes: The attributes for the new attributed string.
*/
public convenience init(string str: String, attributes: [Attribute]) {
self.init(string: str, attributes: dictionary(from: attributes))
public convenience init(string str: String, swiftyAttributes attrs: [Attribute]) {
self.init(string: str, attributes: dictionary(from: attrs))
}

/**
Expand Down
2 changes: 1 addition & 1 deletion SwiftyAttributesTests/NSAttributedString_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SwiftyAttributes
class NSAttributedString_Tests: XCTestCase {

func testInit_withStringAndAttributes() {
let subject = NSAttributedString(string: "Hello World", attributes: [.strokeColor(.green), .strokeWidth(3)])
let subject = NSAttributedString(string: "Hello World", swiftyAttributes: [.strokeColor(.green), .strokeWidth(3)])
#if swift(>=4.0)
let expected = NSAttributedString(string: "Hello World", attributes: [.strokeColor: Color.green, .strokeWidth: 3])
#else
Expand Down
10 changes: 10 additions & 0 deletions SwiftyAttributesTests/NSMutableAttributedString_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import XCTest
import SwiftyAttributes

class NSMutableAttributedString_Tests: XCTestCase {

func testInitMutable_withStringAndAttributes() {
let subject = NSMutableAttributedString(string: "Hello World", swiftyAttributes: [.strokeColor(.green), .strokeWidth(3)])
#if swift(>=4.0)
let expected = NSMutableAttributedString(string: "Hello World", attributes: [.strokeColor: Color.green, .strokeWidth: 3])
#else
let expected = NSMutableAttributedString(string: "Hello World", attributes: [NSStrokeColorAttributeName: Color.green, NSStrokeWidthAttributeName: 3])
#endif
XCTAssertEqual(subject, expected)
}

func testAddAttributes_usingSwiftRange() {
let subject = "Hello".withTextColor(.orange)
Expand Down

0 comments on commit 655c2d7

Please sign in to comment.