我有
private var remark: AttributedString?
,我想检查一下备注是否为空然后显示视图。
调试时,我得到了这个
(lldb) po remark
▿ Optional<AttributedString>
▿ some : {
NSStrokeColor = kCGColorSpaceModelRGB 0 0 0 1
NSStrokeWidth = 0.0
NSFont = <UICTFont: 0x7ff5bb43d310> font-family: "Times New Roman"; font-weight: normal; font-style: normal; font-size: 12.00pt
NSColor = kCGColorSpaceModelRGB 0 0 0 1
SwiftUI.Font = Font(provider: SwiftUI.(unknown context at $1248d26b0).FontBox<SwiftUI.Font.(unknown context at $12492b8dc).PlatformFontProvider>)
NSKern = 0.0
NSParagraphStyle = Alignment Natural, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode WordWrapping, Tabs (
), DefaultTabInterval 36, Blocks (
), Lists (
), BaseWritingDirection LeftToRight, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0 LineBreakStrategy 0 PresentationIntents (
) ListIntentOrdinal 0 CodeBlockIntentLanguageHint ''
}
▿ _guts : <Guts: 0x600002446e80>
想检查
remark: AttributedString?
是否为空?
您可以在
AttributedString
中查看字符数。因此,在您的情况下,要检查 remark
是否不为空,请执行以下操作:
if !remark.characters.isEmpty {
// show your view
}