combine

IOS 13 Combine Framework - @Published not working (“Unknown attribute 'Published'”)

微笑、不失礼 提交于 2019-12-08 16:10:29
问题 I watched the WWDC 2019 session "Combine in Practice" (https://developer.apple.com/videos/play/wwdc2019/721/). In the video they used the following syntax to create a publisher: @Published var someName: String = "" They did this so that someName becomes a publisher. However, Xcode doesn't like this syntax and gives me an error: Unknown attribute 'Published I have no idea why. I'm using the Xcode 11 beta on macOS Catalina. Any ideas? 回答1: From the Xcode 11 Beta Release Notes (emphasis added):

How to define a protocol to include a property with @Published property wrapper

瘦欲@ 提交于 2019-12-06 14:35:20
问题 When using @Published property wrapper following current SwiftUI syntax, it seems very hard to define a protocol that includes a property with @Published, or I definitely need help :) As I'm implementing dependency injection between a View and it's ViewModel, I need to define a ViewModelProtocol so to inject mock data to preview easily. This is what I first tried, protocol PersonViewModelProtocol { @Published var person: Person } I get "Property 'person' declared inside a protocol cannot have

Computed (NSObject) Properties in SwiftUI don't update the view

只谈情不闲聊 提交于 2019-12-06 09:24:39
So, I want to have a Text that changes its content based on the contents of my CoreData Model. To do that I used a computed property in Xcode beta 4 but it doesn't seem to work anymore. Either that's a bug or there is some other issue I don't see? The problem I have exactly is that my View (and the computed property) don't seem to get updated when self.objectWillChange.send() is called in my store. I also tried to 'export' my var into the store and get it from there, with the same result... EDIT: I just tried the same with another class and it didn't work with just objectWillChange.send() but

Published works for single object but not for array of objects

六月ゝ 毕业季﹏ 提交于 2019-12-05 04:01:43
问题 I am trying to make individually moveable objects. I am able to successfully do it for one object but once I place it into an array, the objects are not able to move anymore. Model: class SocialStore: ObservableObject { @Published var socials : [Social] init(socials: [Social]){ self.socials = socials } } class Social : ObservableObject{ var id: Int var imageName: String var companyName: String @Published var pos: CGPoint init(id: Int, imageName: String, companyName: String, pos: CGPoint) {

How to bind an array and List if the array is a member of ObservableObject?

若如初见. 提交于 2019-12-04 05:49:49
问题 I want to create MyViewModel which gets data from network and then updates the arrray of results. MyView should subscribe to the $model.results and show List filled with the results. Unfortunately I get an error about "Type of expression is ambiguous without more context". How to properly use ForEach for this case? import SwiftUI import Combine class MyViewModel: ObservableObject { @Published var results: [String] = [] init() { DispatchQueue.main.asyncAfter(deadline: .now() + 1) { self

Published works for single object but not for array of objects

谁说胖子不能爱 提交于 2019-12-03 21:38:28
I am trying to make individually moveable objects. I am able to successfully do it for one object but once I place it into an array, the objects are not able to move anymore. Model: class SocialStore: ObservableObject { @Published var socials : [Social] init(socials: [Social]){ self.socials = socials } } class Social : ObservableObject{ var id: Int var imageName: String var companyName: String @Published var pos: CGPoint init(id: Int, imageName: String, companyName: String, pos: CGPoint) { self.id = id self.imageName = imageName self.companyName = companyName self.pos = pos } var dragGesture :

Create a Timer Publisher using Swift Combine

依然范特西╮ 提交于 2019-12-03 12:38:31
问题 I've been watching the Data Flow Through SwiftUI WWDC talk. They have a slide with a sample code where they use a Timer publisher that gets connected to a SwiftUI View, and updates the UI with the time. I'm working on some code where I want to do the exact same thing, but can't figure out how this PodcastPlayer.currentTimePublisher is implemented, and then hooked to the UI struct. I have also watched all the videos about Combine. How can I achieve this? The sample code: struct PlayerView :

Create a Timer Publisher using Swift Combine

跟風遠走 提交于 2019-12-03 03:59:55
I've been watching the Data Flow Through SwiftUI WWDC talk . They have a slide with a sample code where they use a Timer publisher that gets connected to a SwiftUI View, and updates the UI with the time. I'm working on some code where I want to do the exact same thing, but can't figure out how this PodcastPlayer.currentTimePublisher is implemented, and then hooked to the UI struct. I have also watched all the videos about Combine. How can I achieve this? The sample code: struct PlayerView : View { let episode: Episode @State private var isPlaying: Bool = true @State private var currentTime:

Combine @Published could not be found - Xcode11 Beta 5(11M382q)

萝らか妹 提交于 2019-12-02 15:16:20
问题 I am trying to run a simple project with the following: @Published var currentPlacemark: CLPlacemark? = nil XCode11 Beta5(11M382q) iOS13(17A5556d) Getting the following error: dyld: Symbol not found: _$s7Combine9PublishedV9PublisherCyx_GAadAM Anyone else encountered this? Code example: import SwiftUI import Combine class MyFoo { @Published var bar: String = "" } struct ContentView: View { var body: some View { Text("Hello World") } } #if DEBUG struct ContentView_Previews: PreviewProvider {

How to bind an array and List if the array is a member of ObservableObject?

こ雲淡風輕ζ 提交于 2019-12-02 11:06:18
I want to create MyViewModel which gets data from network and then updates the arrray of results. MyView should subscribe to the $model.results and show List filled with the results. Unfortunately I get an error about "Type of expression is ambiguous without more context". How to properly use ForEach for this case? import SwiftUI import Combine class MyViewModel: ObservableObject { @Published var results: [String] = [] init() { DispatchQueue.main.asyncAfter(deadline: .now() + 1) { self.results = ["Hello", "World", "!!!"] } } } struct MyView: View { @ObservedObject var model: MyViewModel var