Victor Choi

  • Home
  • Business
    • Internet
    • Market
    • Stock
  • Parent Category
    • Child Category 1
      • Sub Child Category 1
      • Sub Child Category 2
      • Sub Child Category 3
    • Child Category 2
    • Child Category 3
    • Child Category 4
  • Featured
  • Health
    • Childcare
    • Doctors
  • Home
  • Business
    • Internet
    • Market
    • Stock
  • Downloads
    • Dvd
    • Games
    • Software
      • Office
  • Parent Category
    • Child Category 1
      • Sub Child Category 1
      • Sub Child Category 2
      • Sub Child Category 3
    • Child Category 2
    • Child Category 3
    • Child Category 4
  • Featured
  • Health
    • Childcare
    • Doctors
  • Uncategorized

10/08/2019

@Published property wrapper in a subclass doesn't send a callback

 6:49 AM     @Published, Combine, objectwillchange, observableobject, observedobject, Swift 5.1, Swift Property Wrapper, SwiftUI     No comments   

I worked on an app using SwiftUI and Combine framework. Then I used @Published property wrapper to publish a stream data from a property in a ViewModel class. By the way when I assign a new value to the property and it doesn’t send a callback to the counterpart SwiftUI view. Then I looked through a similar question in the stack overflow.

Then I followed the answer. But it doesn’t work in my case. So I declared objectWillChange in the subclass and now it works. I think that SwiftUI and Combine framework are not stable yet. So you might have this kind of issue.

// ViewModel 
var objectWillChange = PassthroughSubject<Void, Never>() 

var value: String = "Select" {
  willSet {
    self.objectWillChange.send()
  }
}

// View 
var body: some view {
  Text(self.viewModel.value)
}
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 개의 λŒ“κΈ€:

Post a Comment

Search This Blog

Popular Posts

  • How to put a padding into a UITextField ?
  • Time machine gives error "can't connect to a current time machine backup disk"
  • Keynote Tutorial Text Outline - Make your animation meaningful
  • Keynote Tutorial , Sound is a design,too
  • Keynote Tutorial How to improve your bullets

Blog Archive

  • ►  2020 (2)
    • ►  January (2)
  • ▼  2019 (21)
    • ►  December (2)
    • ►  November (6)
    • ▼  October (5)
      • Updating Godaddy's name servers? Good luck
      • Free iPad Pro Duel screen? Give up using Sidecar
      • Still Touch ID is better than Face ID
      • Apple iPad Pro Sidecar with Mac OS Catalina
      • @Published property wrapper in a subclass doesn't ...
    • ►  September (2)
    • ►  August (3)
    • ►  July (2)
    • ►  June (1)
  • ►  2017 (11)
    • ►  December (2)
    • ►  November (2)
    • ►  July (2)
    • ►  May (1)
    • ►  April (1)
    • ►  March (3)
  • ►  2016 (48)
    • ►  December (3)
    • ►  November (2)
    • ►  September (1)
    • ►  August (10)
    • ►  July (5)
    • ►  June (7)
    • ►  May (2)
    • ►  April (18)
Powered by Blogger.

Navigation Menu

  • Home
  • About
  • Documentation
  • Contact

Contact Us

Name

Email *

Message *

Copyright © Victor Choi | Powered by Blogger
Design by Hardeep Asrani | Blogger Theme by NewBloggerThemes.com | Distributed By Gooyaabi Templates