Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode debug watch @Published as expresion

Tags:

swiftui

I have a published property in SwiftUI declared thus:

import SwiftUI

class UserData: ObservableObject  {

    @Published var showLoginButton = true

In the debugger at a breakpoint I cannot see the value of this property. I can see the value of properties that are not decorated as @Published.

xcode screenshot showing @Published property without value

What expression do I need to see the current value of a published property when debugging SwiftUI?

like image 349
dumbledad Avatar asked Nov 15 '25 14:11

dumbledad


2 Answers

@Published is a property wrapper, so you see its storage. To get value just print property, so here it is

(lldb) e _showLoginButton
(Published<Bool>) $R0 = {}
(lldb) e self.showLoginButton
(Bool) $R2 = true
like image 151
Asperi Avatar answered Nov 18 '25 21:11

Asperi


Make sure your source code (tests included) includes import Combine. In the Xcode debugger you can then use the print description button (icon is a circle with an 'i' in the center) to view the current value. Without the import the console will show "error: cannot find type 'Combine' in scope".

like image 40
Norman Avatar answered Nov 18 '25 19:11

Norman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!