Does not conform to protocol BindableObject - Xcode 11 Beta 4

前端 未结 3 1086
暗喜
暗喜 2021-02-07 03:43

Playing around with examples out there. Found a project that had a class that was a bindableobject and it didn\'t give any errors. Now that Xcode 11 beta 4 is out

3条回答
  •  情话喂你
    2021-02-07 03:58

    in Xcode 11.X, I verify is fine in Xcode 11.2.1, 11.3.

    BindableObject is changed to ObservableObject.

    ObjectBinding is now ObservedObject.

    didChange should be changed to objectWillChange.

    List(dataSource.pictures, id: .self) { }
    

    You can also now get rid of the did/willChange publisher and the .send code and just make pictures @Published

    The rest will be autogenerated for you.

    for example:

    import SwiftUI
    import Combine
    import Foundation
    
    class RoomStore: ObservableObject {
        @Published var rooms: [Room]
        init(rooms: [Room]) {
            self.rooms = rooms
        }
    }
    
    struct ContentView: View {
        @ObservedObject var store = RoomStore(rooms: [])
    }
    

    ref: https://www.reddit.com/r/swift/comments/cu8cqk/getting_the_errors_pictured_below_when_try_to/

提交回复
热议问题