re: Getting started with SwiftUI and Combine. VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Hi I am getting the following error when running app on simulator error: module importing failed: invalid token (rlm_lldb.py, line 37) File "tem...
 

Hey,
I need to update this for the beta 4...
Looks like a realm error (?). Can I see your code ?

 

Same as your sample except TodoListViewModel: changed didChange to willChange per Version 4 beta requirements

import Foundation
import SwiftUI
import Combine

public class TodoListViewModel: BindableObject {
public let willChange = PassthroughSubject()

var todos: Todos = [Todo]() {
    willSet {
        willChange.send(self)
    }
}

func shuffle() {
    self.todos = self.todos.shuffled()
}

func sort() {
    self.todos = self.todos.sorted(by: { ($0.pinned ?? false) && (!($1.pinned ?? false)) })
}

func markDone(id: Int) {
    self.todos.first(where: { $0.id == id })?.completed.toggle()
    self.willChange.send(self)
}

func pin(id: Int) {
    self.todos.first(where: { $0.id == id })?.pinned?.toggle()
    self.sort()
}

func load() {
    guard let url = URL(string: "https://jsonplaceholder.typicode.com/todos/") else { return }
    URLSession.shared.dataTask(with: url) { (data, response, error) in
        do {
            guard let data = data else { return }
            let todos = try JSONDecoder().decode(Todos.self, from: data)
            DispatchQueue.main.async {
                self.todos = todos
            }
        } catch {
            print("Failed To decode: ", error)
        }
    }.resume()
}

}

Replacing didChange to willChange did not raise any error, but I noticed you did not added the satisfying types for output and failures. In my case :

public let willChange = PassthroughSubject<TodoViewModel, Never>()

I have no idea of how you could get that kind of error, but check if that's what you missed.

code of conduct - report abuse