Skip to content

Commit d413589

Browse files
committed
Allow nil values for custom attributes.
1 parent 7bb4341 commit d413589

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

Attributed/Functions.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public func Join(strings: [AttributedStringConvertible]) -> AttributedStringConv
3636
- parameter attributes: The attributes to apply.
3737
- parameter strings: The convertible strings.
3838
*/
39-
public func Attributes(attributes: [String:AnyObject], _ strings: AttributedStringConvertible...)
39+
public func Attributes(attributes: [String:AnyObject?], _ strings: AttributedStringConvertible...)
4040
-> AttributedStringConvertible
4141
{
4242
return Attributes(attributes, strings)
@@ -50,7 +50,7 @@ public func Attributes(attributes: [String:AnyObject], _ strings: AttributedStri
5050
- parameter attributes: The attributes to apply.
5151
- parameter strings: The convertible strings.
5252
*/
53-
public func Attributes(attributes: [String:AnyObject], _ strings: [AttributedStringConvertible])
53+
public func Attributes(attributes: [String:AnyObject?], _ strings: [AttributedStringConvertible])
5454
-> AttributedStringConvertible
5555
{
5656
return NestedAttributedString(attributes: attributes, children: strings)
@@ -65,7 +65,7 @@ public func Attributes(attributes: [String:AnyObject], _ strings: [AttributedStr
6565
- parameter value: The attribute value to apply.
6666
- parameter strings: The convertible strings.
6767
*/
68-
public func Attribute(attribute: String, _ value: AnyObject, _ strings: AttributedStringConvertible...)
68+
public func Attribute(attribute: String, _ value: AnyObject?, _ strings: AttributedStringConvertible...)
6969
-> AttributedStringConvertible
7070
{
7171
return Attribute(attribute, value, strings)
@@ -80,7 +80,7 @@ public func Attribute(attribute: String, _ value: AnyObject, _ strings: Attribut
8080
- parameter value: The attribute value to apply.
8181
- parameter strings: The convertible strings.
8282
*/
83-
public func Attribute(attribute: String, _ value: AnyObject, _ strings: [AttributedStringConvertible])
83+
public func Attribute(attribute: String, _ value: AnyObject?, _ strings: [AttributedStringConvertible])
8484
-> AttributedStringConvertible
8585
{
8686
return Attributes([attribute: value], strings)

Attributed/NestedAttributedString.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Foundation
1414
internal struct NestedAttributedString
1515
{
1616
/// The attributes to apply over this string's children.
17-
let attributes: [String:AnyObject]
17+
let attributes: [String:AnyObject?]
1818

1919
/// The children of this attributed string.
2020
let children: [AttributedStringConvertible]

AttributedTests/AttributedTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,21 @@ class AttributedTests: XCTestCase
5959

6060
XCTAssertEqual(attributed, mutable)
6161
}
62+
63+
func testNilValue()
64+
{
65+
let attributed = ColorType.blueColor().foregroundAttribute(
66+
"Test",
67+
Attribute(NSForegroundColorAttributeName, nil,
68+
"Test",
69+
ColorType.greenColor().foregroundAttribute("Test")
70+
)
71+
).attributedString
72+
73+
let mutable = NSMutableAttributedString(string: "TestTestTest")
74+
mutable.addAttribute(NSForegroundColorAttributeName, value: ColorType.blueColor(), range: NSMakeRange(0, 4))
75+
mutable.addAttribute(NSForegroundColorAttributeName, value: ColorType.greenColor(), range: NSMakeRange(8, 4))
76+
77+
XCTAssertEqual(attributed, mutable)
78+
}
6279
}

0 commit comments

Comments
 (0)