Skip to content

Commit 2bc1023

Browse files
committed
#60 Fixes for macOS compilation
1 parent 35f168a commit 2bc1023

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

Sources/SwiftRichString/Attributes/DynamicText.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// Copyright © 2019 SwiftRichString. All rights reserved.
77
//
88

9+
#if os(tvOS) || os(watchOS) || os(iOS)
910
import UIKit
1011

1112
/// DynamicText encapsulate the attributes for fonts to automatically scale to match the current Dynamic Type settings. It uses UIFontMetrics.
@@ -38,3 +39,5 @@ public class DynamicText {
3839
handler?(self)
3940
}
4041
}
42+
43+
#endif

Sources/SwiftRichString/Attributes/FontData.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ public class FontData {
2727

2828
/// Font object
2929
var font: FontConvertible? { didSet { self.style?.invalidateCache() } }
30-
30+
31+
#if os(tvOS) || os(watchOS) || os(iOS)
3132
// Dynamic text atributes
3233
public var dynamicText: DynamicText? { didSet { self.style?.invalidateCache() } }
33-
34+
3435
/// Returns if font should adapt to dynamic type
3536
private var adpatsToDynamicType: Bool? { return dynamicText != nil }
36-
37+
#endif
38+
3739
/// Size of the font
3840
var size: CGFloat? { didSet { self.style?.invalidateCache() } }
3941

@@ -189,17 +191,22 @@ public class FontData {
189191
finalAttributes[.kern] = tracking.kerning(for: finalFont)
190192
}
191193
#endif
192-
194+
195+
#if os(tvOS) || os(watchOS) || os(iOS)
193196
// set scalable custom font if adapts to dynamic type
194197
if #available(iOS 11.0, watchOS 4.0, tvOS 11.0, *), adpatsToDynamicType == true {
195198
finalAttributes[.font] = scalableFont(from: finalFont)
196199
} else {
197200
finalAttributes[.font] = finalFont
198201
}
202+
#else
203+
finalAttributes[.font] = finalFont
204+
#endif
199205

200206
return finalAttributes
201207
}
202-
208+
209+
#if os(tvOS) || os(watchOS) || os(iOS)
203210
/// Returns a custom scalable font based on the received font
204211
///
205212
/// - Parameter font: font in which the custom font will be based
@@ -217,4 +224,6 @@ public class FontData {
217224
return (fontMetrics ?? UIFontMetrics.default).scaledFont(for: font, maximumPointSize: dynamicText?.maximumSize ?? 0.0)
218225
#endif
219226
}
227+
#endif
228+
220229
}

Sources/SwiftRichString/Style/Style.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,16 @@ public class Style: StyleProtocol {
8686
return self.fontData?.font
8787
}
8888
}
89-
89+
90+
#if os(tvOS) || os(watchOS) || os(iOS)
9091
/// Set the dynamic text attributes to adapt the font/text to the current Dynamic Type settings.
9192
/// **Note**: in order to be used you must also set the `.font`/`.size` attribute of the style.
9293
@available(iOS 11.0, tvOS 11.0, iOSApplicationExtension 11.0, watchOS 4, *)
9394
public var dynamicText: DynamicText? {
9495
set { self.fontData?.dynamicText = newValue }
9596
get { return self.fontData?.dynamicText }
9697
}
98+
#endif
9799

98100
/// Set the text color of the style.
99101
/// You can pass any `ColorConvertible` conform object, it will be transformed to a valid `UIColor`/`NSColor`

0 commit comments

Comments
 (0)