Skip to content

Commit 93f1b5e

Browse files
committed
完善扩展
1 parent e54a482 commit 93f1b5e

File tree

3 files changed

+105
-9
lines changed

3 files changed

+105
-9
lines changed

AttributedString.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "AttributedString"
4-
s.version = "1.1.1"
4+
s.version = "1.1.2"
55
s.summary = "基于Swift字符串插值快速构建你想要的富文本"
66

77
s.homepage = "https://github.com/lixiang1994/AttributedString"

AttributedString.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@
372372
"@executable_path/Frameworks",
373373
"@loader_path/Frameworks",
374374
);
375-
MARKETING_VERSION = 1.1.1;
375+
MARKETING_VERSION = 1.1.2;
376376
PRODUCT_BUNDLE_IDENTIFIER = com.lee.attributedstring;
377377
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
378378
SKIP_INSTALL = YES;
@@ -400,7 +400,7 @@
400400
"@executable_path/Frameworks",
401401
"@loader_path/Frameworks",
402402
);
403-
MARKETING_VERSION = 1.1.1;
403+
MARKETING_VERSION = 1.1.2;
404404
PRODUCT_BUNDLE_IDENTIFIER = com.lee.attributedstring;
405405
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
406406
SKIP_INSTALL = YES;

Sources/Extension/Extension.swift

Lines changed: 102 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,34 @@ extension AttributedString {
4949
/// Add a AttributedString to another AttributedString and return a new AttributedString instance.
5050
///
5151
/// - Parameters:
52-
/// - lhs: NSAttributedString to add.
53-
/// - rhs: NSAttributedString to add.
54-
/// - Returns: New instance with added NSAttributedString.
52+
/// - lhs: AttributedString to add.
53+
/// - rhs: AttributedString to add.
54+
/// - Returns: New instance with added AttributedString.
5555
public static func + (lhs: AttributedString, rhs: AttributedString) -> AttributedString {
5656
let string = NSMutableAttributedString(attributedString: lhs.value)
5757
string.append(rhs.value)
5858
return .init(string)
5959
}
6060

61-
/// Add a AttributedString to another AttributedString.
61+
/// Add a String to another AttributedString.
6262
///
6363
/// - Parameters:
64-
/// - lhs: NSAttributedString to add to.
64+
/// - lhs: AttributedString to add to.
6565
/// - rhs: String to add.
6666
public static func += (lhs: inout AttributedString, rhs: String) {
6767
lhs += AttributedString(.init(string: rhs))
6868
}
69+
70+
/// Add a AttributedString to another String.
71+
///
72+
/// - Parameters:
73+
/// - lhs: String to add to.
74+
/// - rhs: AttributedString to add.
75+
public static func += (lhs: inout String, rhs: AttributedString) {
76+
lhs += rhs.value.string
77+
}
6978

70-
/// Add a NSAttributedString to another AttributedString and return a new AttributedString instance.
79+
/// Add a String to another AttributedString and return a new AttributedString instance.
7180
///
7281
/// - Parameters:
7382
/// - lhs: AttributedString to add.
@@ -76,4 +85,91 @@ extension AttributedString {
7685
public static func + (lhs: AttributedString, rhs: String) -> AttributedString {
7786
return lhs + AttributedString(.init(string: rhs))
7887
}
88+
89+
/// Add a NSAttributedString to another AttributedString.
90+
///
91+
/// - Parameters:
92+
/// - lhs: AttributedString to add to.
93+
/// - rhs: NSAttributedString to add.
94+
public static func += (lhs: inout AttributedString, rhs: NSAttributedString) {
95+
lhs += AttributedString(rhs)
96+
}
97+
98+
/// Add a AttributedString to another NSMutableAttributedString.
99+
///
100+
/// - Parameters:
101+
/// - lhs: NSMutableAttributedString to add to.
102+
/// - rhs: AttributedString to add.
103+
public static func += (lhs: inout NSMutableAttributedString, rhs: AttributedString) {
104+
lhs.append(rhs.value)
105+
}
106+
107+
/// Add a NSAttributedString to another AttributedString and return a new AttributedString instance.
108+
///
109+
/// - Parameters:
110+
/// - lhs: AttributedString to add.
111+
/// - rhs: NSAttributedString to add.
112+
/// - Returns: New instance with added NSAttributedString.
113+
public static func + (lhs: AttributedString, rhs: NSAttributedString) -> AttributedString {
114+
return lhs + AttributedString(rhs)
115+
}
116+
117+
/// Add a AttributedString.Style to another AttributedString.
118+
///
119+
/// - Parameters:
120+
/// - lhs: AttributedString to add to.
121+
/// - rhs: AttributedString.Style to add.
122+
public static func += (lhs: inout AttributedString, rhs: AttributedString.Style) {
123+
lhs += (rhs, .init(location: 0, length: lhs.value.string.count))
124+
}
125+
126+
/// Add a AttributedString.Style to another AttributedString.
127+
///
128+
/// - Parameters:
129+
/// - lhs: AttributedString to add to.
130+
/// - rhs: AttributedString.Style to add.
131+
public static func += (lhs: inout AttributedString, rhs: (AttributedString.Style, NSRange)) {
132+
lhs += ([rhs.0], rhs.1)
133+
}
134+
135+
/// Add a AttributedString.Style to another AttributedString.
136+
///
137+
/// - Parameters:
138+
/// - lhs: AttributedString to add to.
139+
/// - rhs: AttributedString.Style to add.
140+
public static func += (lhs: inout AttributedString, rhs: ([AttributedString.Style], NSRange)) {
141+
lhs = lhs + rhs
142+
}
143+
144+
/// Add a AttributedString.Style to another AttributedString and return a new AttributedString instance.
145+
///
146+
/// - Parameters:
147+
/// - lhs: AttributedString to add.
148+
/// - rhs: AttributedString.Style to add.
149+
/// - Returns: New instance with added AttributedString.Style.
150+
public static func + (lhs: AttributedString, rhs: AttributedString.Style) -> AttributedString {
151+
return lhs + (rhs, .init(location: 0, length: lhs.value.string.count))
152+
}
153+
154+
/// Add a AttributedString.Style to another AttributedString and return a new AttributedString instance.
155+
///
156+
/// - Parameters:
157+
/// - lhs: AttributedString to add.
158+
/// - rhs: AttributedString.Style to add.
159+
/// - Returns: New instance with added AttributedString.Style.
160+
public static func + (lhs: AttributedString, rhs: (AttributedString.Style, NSRange)) -> AttributedString {
161+
return lhs + ([rhs.0], rhs.1)
162+
}
163+
164+
/// Add a AttributedString.Style to another AttributedString and return a new AttributedString instance.
165+
///
166+
/// - Parameters:
167+
/// - lhs: AttributedString to add.
168+
/// - rhs: AttributedString.Style to add.
169+
/// - Returns: New instance with added AttributedString.Style.
170+
public static func + (lhs: AttributedString, rhs: ([AttributedString.Style], NSRange)) -> AttributedString {
171+
let string = NSMutableAttributedString(attributedString: lhs.value)
172+
rhs.0.forEach { string.addAttributes($0.attributes, range: rhs.1) }
173+
return .init(string)
174+
}
79175
}

0 commit comments

Comments
 (0)