Skip to content

Commit ef1e887

Browse files
committed
Some minor conditionlal compilation fixes
1 parent e07abe7 commit ef1e887

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

ExampleiOS/Assets.xcassets/rocket.imageset/Contents.json renamed to ExampleiOS/Assets.xcassets/therocket.imageset/Contents.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"images" : [
33
{
44
"idiom" : "universal",
5+
"filename" : "816c77975b4ccce940d41933081b19d7.png",
56
"scale" : "1x"
67
},
78
{
89
"idiom" : "universal",
9-
"filename" : "816c77975b4ccce940d41933081b19d7.png",
1010
"scale" : "2x"
1111
},
1212
{

ExampleiOS/file.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<strong>Parler du don d'organe n'est plus tabou. Je me renseigne, j'en discute avec mes proches,... <rainbow>et je décide!</rainbow></strong>
22

3-
<img named="rocket" rect="0,-50,30,30"/>
3+
<img named="therocket" rect="0,-50,30,30"/>
44

55
<img url="https://www.macitynet.it/wp-content/uploads/2018/05/video_ApplePark_magg18.jpg"/>
66

Sources/SwiftRichString/Extensions/AttributedString+Attachments.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ import AppKit
3636
import UIKit
3737
#endif
3838

39-
#if os(iOS)
40-
4139
public extension AttributedString {
4240

41+
#if os(iOS)
42+
4343
/// Initialize a new text attachment with a remote image resource.
4444
/// Image will be loaded asynchronously after the text appear inside the control.
4545
///
@@ -61,6 +61,10 @@ public extension AttributedString {
6161
self.init(attachment: attachment)
6262
}
6363

64+
#endif
65+
66+
#if os(iOS) || os(OSX)
67+
6468
/// Initialize a new text attachment with local image contained into the assets.
6569
///
6670
/// - Parameters:
@@ -71,8 +75,9 @@ public extension AttributedString {
7175
return nil
7276
}
7377

78+
let image = Image(named: imageNamed)
7479
let boundsRect = CGRect(string: bounds)
75-
self.init(image: Image(named: imageNamed), bounds: boundsRect)
80+
self.init(image: image, bounds: boundsRect)
7681
}
7782

7883
/// Initialize a new attributed string from an image.
@@ -85,20 +90,24 @@ public extension AttributedString {
8590
return nil
8691
}
8792

93+
#if os(OSX)
94+
let attachment = NSTextAttachment(data: image.pngData()!, ofType: "png")
95+
#else
8896
var attachment: NSTextAttachment!
8997
if #available(iOS 13.0, *) {
9098
attachment = NSTextAttachment(image: image)
9199
} else {
92100
attachment = NSTextAttachment(data: image.pngData()!, ofType: "png")
93101
}
102+
#endif
94103

95104
if let bounds = bounds {
96105
attachment.bounds = bounds
97106
}
98107

99108
self.init(attachment: attachment)
100109
}
110+
111+
#endif
101112

102113
}
103-
104-
#endif

Sources/SwiftRichString/Support/XMLDynamicAttributesResolver.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,24 @@ open class StandardXMLAttributesResolver: XMLDynamicAttributesResolver {
8686
case "a": // href support
8787
finalStyleToApply.linkURL = URL(string: attributes?["href"])
8888

89-
#if os(iOS)
9089
case "img":
90+
#if os(iOS)
91+
// Remote Image URL support
9192
if let url = attributes?["url"] {
9293
if let image = AttributedString(imageURL: url, bounds: attributes?["rect"]) {
9394
attributedString.append(image)
9495
}
95-
} else {
96-
if let image = AttributedString(imageNamed: attributes?["named"], bounds: attributes?["rect"]) {
96+
}
97+
#endif
98+
99+
#if os(iOS) || os(OSX)
100+
// Local Image support
101+
if let imageName = attributes?["named"] {
102+
if let image = AttributedString(imageNamed: imageName, bounds: attributes?["rect"]) {
97103
attributedString.append(image)
98104
}
99105
}
100-
#endif
106+
#endif
101107

102108
default:
103109
break

0 commit comments

Comments
 (0)