Skip to content

Commit 8c9d5b4

Browse files
committed
优化富文本嵌套插值方法
1 parent d5b7a58 commit 8c9d5b4

File tree

6 files changed

+45
-14
lines changed

6 files changed

+45
-14
lines changed

AttributedString.podspec

+1-1
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 = "2.0.0"
4+
s.version = "2.1.0"
55
s.summary = "基于Swift字符串插值快速构建你想要的富文本, 支持点击按住等事件获取, 支持多种类型过滤"
66

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

Demo-Watch/Demo-Watch.xcodeproj/xcshareddata/xcschemes/Demo-Watch WatchKit App.xcscheme

+19-6
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,46 @@
5454
debugDocumentVersioning = "YES"
5555
debugServiceExtension = "internal"
5656
allowLocationSimulation = "YES">
57-
<BuildableProductRunnable
58-
runnableDebuggingMode = "0">
57+
<RemoteRunnable
58+
runnableDebuggingMode = "2"
59+
BundleIdentifier = "com.apple.Carousel"
60+
RemotePath = "/Demo-Watch WatchKit App">
5961
<BuildableReference
6062
BuildableIdentifier = "primary"
6163
BlueprintIdentifier = "9B267B4D24405CFA002F571E"
6264
BuildableName = "Demo-Watch WatchKit App.app"
6365
BlueprintName = "Demo-Watch WatchKit App"
6466
ReferencedContainer = "container:Demo-Watch.xcodeproj">
6567
</BuildableReference>
66-
</BuildableProductRunnable>
68+
</RemoteRunnable>
6769
</LaunchAction>
6870
<ProfileAction
6971
buildConfiguration = "Release"
7072
shouldUseLaunchSchemeArgsEnv = "YES"
7173
savedToolIdentifier = ""
7274
useCustomWorkingDirectory = "NO"
7375
debugDocumentVersioning = "YES">
74-
<BuildableProductRunnable
75-
runnableDebuggingMode = "0">
76+
<RemoteRunnable
77+
runnableDebuggingMode = "2"
78+
BundleIdentifier = "com.apple.Carousel"
79+
RemotePath = "/Demo-Watch WatchKit App">
7680
<BuildableReference
7781
BuildableIdentifier = "primary"
7882
BlueprintIdentifier = "9B267B4D24405CFA002F571E"
7983
BuildableName = "Demo-Watch WatchKit App.app"
8084
BlueprintName = "Demo-Watch WatchKit App"
8185
ReferencedContainer = "container:Demo-Watch.xcodeproj">
8286
</BuildableReference>
83-
</BuildableProductRunnable>
87+
</RemoteRunnable>
88+
<MacroExpansion>
89+
<BuildableReference
90+
BuildableIdentifier = "primary"
91+
BlueprintIdentifier = "9B267B4D24405CFA002F571E"
92+
BuildableName = "Demo-Watch WatchKit App.app"
93+
BlueprintName = "Demo-Watch WatchKit App"
94+
ReferencedContainer = "container:Demo-Watch.xcodeproj">
95+
</BuildableReference>
96+
</MacroExpansion>
8497
</ProfileAction>
8598
<AnalyzeAction
8699
buildConfiguration = "Debug">

Sources/Action.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ extension ASAttributedString {
155155
}
156156
}
157157

158-
extension AttributedStringInterpolation {
158+
extension ASAttributedStringInterpolation {
159159

160160
public typealias Action = ASAttributedString.Action
161161
public typealias Result = Action.Result

Sources/Attachment.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ extension ASAttributedString.Attachment {
211211
}
212212
}
213213

214-
extension AttributedStringInterpolation {
214+
extension ASAttributedStringInterpolation {
215215

216216
public typealias Attachment = ASAttributedString.Attachment
217217
public typealias ImageAttachment = ASAttributedString.ImageAttachment

Sources/Attribute.swift

+17-3
Original file line numberDiff line numberDiff line change
@@ -147,26 +147,40 @@ extension ASAttributedString.Attribute {
147147
}
148148
}
149149

150-
extension AttributedStringInterpolation {
150+
extension ASAttributedStringInterpolation {
151151

152152
public typealias Attribute = ASAttributedString.Attribute
153153
public typealias WrapMode = ASAttributedString.WrapMode
154154

155155
public mutating func appendInterpolation<T>(_ value: T, _ attributes: Attribute...) {
156156
appendInterpolation(value, with: attributes)
157157
}
158-
159158
public mutating func appendInterpolation<T>(_ value: T, with attributes: [Attribute]) {
160159
self.value.append(ASAttributedString("\(value)", with: attributes).value)
161160
}
162161

162+
public mutating func appendInterpolation(_ value: NSAttributedString, _ attributes: Attribute...) {
163+
appendInterpolation(value, with: attributes)
164+
}
165+
public mutating func appendInterpolation(_ value: NSAttributedString, with attributes: [Attribute]) {
166+
self.value.append(ASAttributedString(value, with: attributes).value)
167+
}
168+
169+
public mutating func appendInterpolation(_ value: ASAttributedString, _ attributes: Attribute...) {
170+
appendInterpolation(value, with: attributes)
171+
}
172+
public mutating func appendInterpolation(_ value: ASAttributedString, with attributes: [Attribute]) {
173+
self.value.append(ASAttributedString(value, with: attributes).value)
174+
}
175+
163176
// 嵌套包装
164177
public mutating func appendInterpolation(wrap string: ASAttributedString, _ attributes: Attribute...) {
165178
appendInterpolation(wrap: string, with: attributes)
166179
}
167180
public mutating func appendInterpolation(wrap string: ASAttributedString, with attributes: [Attribute]) {
168-
self.value.append(ASAttributedString(wrap: .embedding(string), with: attributes).value)
181+
self.value.append(ASAttributedString(string, with: attributes).value)
169182
}
183+
170184
public mutating func appendInterpolation(wrap mode: WrapMode, _ attributes: Attribute...) {
171185
appendInterpolation(wrap: mode, with: attributes)
172186
}

Sources/Interpolation.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import UIKit
1919

2020
extension ASAttributedString: ExpressibleByStringInterpolation {
2121

22-
public init(stringInterpolation: AttributedStringInterpolation) {
22+
public init(stringInterpolation: ASAttributedStringInterpolation) {
2323
self.value = .init(attributedString: stringInterpolation.value)
2424
}
2525
}
2626

27-
public struct AttributedStringInterpolation : StringInterpolationProtocol {
27+
public struct ASAttributedStringInterpolation : StringInterpolationProtocol {
2828

2929
let value: NSMutableAttributedString
3030

@@ -40,6 +40,10 @@ public struct AttributedStringInterpolation : StringInterpolationProtocol {
4040
self.value.append(value)
4141
}
4242

43+
public mutating func appendInterpolation(_ value: ASAttributedString) {
44+
self.value.append(value.value)
45+
}
46+
4347
/// Interpolates the given value's textual representation into the
4448
/// attributed string literal being created.
4549
///

0 commit comments

Comments
 (0)