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
Showing posts with label @Published. Show all posts
Showing posts with label @Published. Show all posts

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)
}
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Older Posts Home

Search This Blog

Popular Posts

  • Git ignore vs Git exclude
  • Keynote Tutorial Character Style , How to use a character style in Keynote
  • If you can't get OAuth Token by SFSafariViewController...?
  • Bitbucket authentication error, Invalid username and password
  • OmniFocus Review Perspective action using Launch Center Pro

Blog Archive

  • ▼  2020 (2)
    • ▼  January (2)
      • Error- helm docker-registry does not have any acti...
      • How to clean up none docker images
  • ►  2019 (21)
    • ►  December (2)
    • ►  November (6)
    • ►  October (5)
    • ►  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