-1

I have private var remark: AttributedString?, I want to check is remark is notEmpty then Show the View.

While debugging, I'm getting this

(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>

Want to check if remark: AttributedString? is empty or not?

3

1 Answer 1

0

You can check the number of characters in the AttributedString. So in your case, to check if the remark is not empty, do this:

if !remark.characters.isEmpty {
  // show your view
}
Sign up to request clarification or add additional context in comments.

3 Comments

(lldb) po remark?.characters.count ▿ Optional<Int> - some : 3
it will always return false because remark have 3 spaces
That does not make sense. Why does it have 3 spaces? This works fine: swift var string = AttributedString("hello") print(string.characters.count) // returns 5 string = AttributedString("") print(string.characters.count) // returns 0 If you know that it has 3 spaces, just check whether all characters are 3 spaces and take a decision based on that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.