Issues While Trying To Recreate SwiftUI-based App From WWDC Session

For this error: //Error: Cannot convert value of type '(Room) -> RoomCell' to expected argument type '(_) -> _' Implement Identifiable protocol to your list model like this,

struct Room: Identifiable

For this one: //Error: Incorrect argument label in call (have 'atOffsets:', expected 'at:') I think it is not your problem :) But you can use something like this,

guard let index = Array(offset).first else { return }
store.rooms.remove(at: index)

And for this one: //Error: Value of type '[Room]' has no member 'move'; did you mean 'remove'? As before, you can use that piece of code for moving

guard let sourceIndex = Array(source).first else { return }
store.rooms.insert(roomStore.rooms.remove(at: sourceIndex), at: destination)

You can check completed source code, https://github.com/ilyadaberdil/iOS-Samples/tree/master/SwiftUI-Sample


Did you try passing Void()?

class RoomStore : BindableObject {
    var rooms: [Room] {
        didSet { didChange.send(Void()) } 
    }
    init(rooms: [Room] = []) {
        self.rooms = rooms
    }
    var didChange = PassthroughSubject<Void, Never>()
}

In Xcode 11 beta 4

The BindableObject protocol’s requirement is now willChange instead of didChange, and should now be sent before the object changes rather than after it changes. This change allows for improved coalescing of change notifications.

class RoomStore: BindableObject {

    var rooms: [Room] {
        didSet { willChange.send() }
    }

    init(rooms: [Room] = []) {
        self.rooms = rooms
    }

    var willChange = PassthroughSubject<Void, Never>()
}

For deleting and moving, use below code.

func delete(at offsets: IndexSet) {
    store.rooms.remove(atOffsets: offsets)
}

func move(from source: IndexSet, to destination: Int) {
    store.rooms.move(fromOffsets: source, toOffset: destination)
}

Tags:

Swift

Swiftui