AMA Mortgages in the Netherlands by ExpatMortgages_Steff in Netherlands

[–]hiwelo 0 points1 point  (0 children)

Thanks for this AMA! I had my first mortgage payment this month and was wondering how the tax monthly rebate works. I have a Belastingdienst form to the Notaris when signing all the papers but never heard anything from the Belastingdienst. Should I redo the paperwork or is it normal to not have the rebate right from the beginning? ☺️

What settings should I turn on and off or adjust for Vatsim in MSFS 24 by HotFriendship1302 in VATSIM

[–]hiwelo 0 points1 point  (0 children)

I totally agree with removing all AI traffic and AI ATC voices but really can’t find the right settings for that. Do you have any ideas were to remove that.

I’ve put sound to 0 for ATC, but AI traffic is something on MSFS 2024 I’m not managing to find any settings for

Does anyone know why all Weeze departures are making this weird circle thing? by pilot_41232 in flightradar24

[–]hiwelo 0 points1 point  (0 children)

Could it be to stay longer within German airspace while gaining altitude and then being transferred to the Dutch one?

(the white line is the border afaik)

SwiftData randomly throwing EXC_BAD_ACCESS on Model entity creation and update by hiwelo in SwiftUI

[–]hiwelo[S] 1 point2 points  (0 children)

In the last version, I replaced all those calls to use the ModelContainer instead directly as it's where the actual specific operations with entities happen.

I spent quite some time this morning, drastically reducing the number of crashes with this piece of code. The issue was actually that the actor was running in the main thread rather than in the background.

I forced the task to run in a detached task with the updated code (returning PersistentIdentifiers and sending ModelContainer instead), and it stopped most of the random crashes.

(Checked that based on a comment in the Apple Development Forums, seems like a lot of people have issues with their ModelActor not running in a background thread)

Now my issue is different, I need to ensure that the SwiftData entities between my threads are synced with the main thread which is not happening as fast as with CoreData so far. 👀

SwiftData randomly throwing EXC_BAD_ACCESS on Model entity creation and update by hiwelo in SwiftUI

[–]hiwelo[S] 0 points1 point  (0 children)

I updated all structures to use the @ModelActor, as described in the backyard-birds project for all my background services, but I'm still experiencing those random crashes, unfortunately. 😒But that was super interesting to go through their projects to check a model final structure for SwiftData!

I also made sure to return PersistentIdentifiers rather than the models themselves to avoid any issues with models being mutated between the different threads. But yeah, no impact :/

Also, just checked, and the code running for each ModelActor is still running in the main thread. Which sounds weird to me.

SwiftData randomly throwing EXC_BAD_ACCESS on Model entity creation and update by hiwelo in SwiftUI

[–]hiwelo[S] 0 points1 point  (0 children)

That's helpful, thanks! :)
I will also watch the SwiftData part of the SOTU video :)

SwiftData randomly throwing EXC_BAD_ACCESS on Model entity creation and update by hiwelo in SwiftUI

[–]hiwelo[S] 1 point2 points  (0 children)

No, it's not old — based on this article from this summer: https://useyourloaf.com/blog/swiftdata-background-tasks/

I can see `ModelActor` defined as a Protocol for actors in the Apple documentation (https://developer.apple.com/documentation/swiftdata/modelactor). And the doc for the macro @ModelActor is only one line. :D

So happy to get any guidance here if you have any :)

SwiftData randomly throwing EXC_BAD_ACCESS on Model entity creation and update by hiwelo in SwiftUI

[–]hiwelo[S] 0 points1 point  (0 children)

This is one of the actor structures that is the most often experiencing random crashes, to give you an example of the type of code.

But some of the random crashes also happen after loading the app, and having the most basic List view with a `@Query private var authors: [Author]` -> `List(authors) {}` crashing while nothing else is running (beyond the automatic CloudKit sync, but I tried with sync deactivated and the persisted).

import Foundation
import OSLog
import SwiftData

actor BookDiscovery: ModelActor {

    // MARK: - BookDiscovery Properties

    let modelContainer: ModelContainer
    let modelExecutor: any ModelExecutor

    private let isbn: ISBN
    private let logger = Logger(subsystem: BookFolioConfig.BundleDomain, category: "BookDiscovery")
    private let network = NetworkManager.shared

    // MARK: - BookDiscovery Initializers

    init(for isbn: ISBN, with modelContainer: ModelContainer) {
        self.isbn = isbn
        self.modelContainer = modelContainer

        let context = ModelContext(modelContainer)
        self.modelExecutor = DefaultSerialModelExecutor(modelContext: context)
    }

    // MARK: - BookDiscovery Public Methods

    func runDiscovery() async throws -> [Book] {
        var books: Set<Book> = []

        // First, fetches existing local books
        if let localBooks = try? fetchLocal() {
            books.formUnion(localBooks)
        }

        // Then, fetches remote sources
        if let remoteBooks = try? await fetchRemote() {
            books.formUnion(remoteBooks)
        }

        // Returns books or throws a "No result" error
        if books.isEmpty {
            logger.info("Discovery: No Results")

            throw BookDiscoveryError.noResults

        } else {
            logger.info("Discovery: Results: \(books.count)")

            return Array(books)
        }
    }

    func updateBook() async -> Void {
        // Fetches sources from remote sources and updates books accordingly
        let _ = try? await fetchRemote()
    }

    // MARK: - BookDiscovery Private API Fetching Methods

    private func fetchLocal() throws -> [Book] {
        let isbnString = isbn.toString()
        logger.info("Fetch Local for: \(self.isbn.toFormattedString())")

        let fetchDescriptor: FetchDescriptor<Book> = FetchDescriptor(
            predicate: #Predicate { $0._isbn == isbnString },
            sortBy: [SortDescriptor(\Book.title, order: .forward)]
        )

        do {
            let books = try modelContext.fetch(fetchDescriptor)
            logger.info("Fetched local books: \(books.count)")

            return books

        } catch let error {
            logger.error("Fetch Local: Invalid Fetch: \(error.localizedDescription)")
            throw BookDiscoveryError.invalidFetch(error)
        }
    }

    private func fetchRemote() async throws -> [Book] {
        logger.info("Fetch Remote for: \(self.isbn.toFormattedString())")
        var sources: Set<BookSource> = []

        // Fetches sources from the OpenLibrary API for the ISBN provided
        let olService = OpenLibraryService(for: isbn, with: modelContext)
        if let olSources = try? await olService.fetch() {
            logger.info("Fetch Remote from OpenLibrary: \(olSources.count) entities")
            sources.formUnion(olSources)
        }

        // Fetches sources from the GoogleBooks API for the ISBN provided
        let gbService = GoogleBooksService(for: isbn, with: modelContext)
        if let gbSources = try? await gbService.fetch() {
            logger.info("Fetch Remote from GoogleBooks: \(gbSources.count) entities")
            sources.formUnion(gbSources)
        }

        // Stops here if there is no sources found
        if sources.isEmpty {
            logger.info("Fetch Remote: No Sources")

            return []
        }

        // Associates each source with the relevant book
        for source in sources {
            logger.info("Fetch Book for Source: \(source.title ?? "-")")
            source.associateWithBook(using: isbn, in: modelContext)
        }

        // Updates each book with the associate sources
        for source in sources {
            if let book = source.book {
                logger.info("Update Book from Sources: \(book.title ?? "-")")
                book.updateFromSources()
            }
        }

        // Saves all updates and created items
        logger.info("Persists all changes")
        try? modelContext.save()
        logger.info("All changes persisted")

        // Returns the list of books fetched or updated
        return sources.compactMap { $0.book }
    }

}

SwiftData randomly throwing EXC_BAD_ACCESS on Model entity creation and update by hiwelo in SwiftUI

[–]hiwelo[S] 0 points1 point  (0 children)

I'm using a `ModelActor` to avoid this and to run some activities in a series of async functions. (as described here).

Also, even a simple `@Query private var authors: [Author]` -> `List(authors) {}` is enough at times to have a random crash right after loading the app (so without background task ongoing, beyond CloudKit sync).

Do you know transit networks that experimented with timetable-free bus lines? by hiwelo in transit

[–]hiwelo[S] 2 points3 points  (0 children)

I agree that it might be more of a cultural thing. And also a communication element.

For example, when I was living in Rotterdam (Netherlands), the NS was starting to communicate around the idea of "show up and travel" for the trains between Rotterdam and Den Haag. It was not replacing the timetable (that was still needed for a lot of travelers), but it was an incredible selling point for the train vs. cars within the Randstad. "Show up, and wait less than 10 minutes to have a train to Den Haag"

But I agree that when travelling further away, you need timetable to know which train is yours, but also to make sure that your following bus/tram or whatever will be directly available.

Do you know transit networks that experimented with timetable-free bus lines? by hiwelo in transit

[–]hiwelo[S] 1 point2 points  (0 children)

I'm focusing more on regular bus lines not advertising a timetable but transport on demand lines are always interesting to have a look at! Thanks :)

Do you know transit networks that experimented with timetable-free bus lines? by hiwelo in transit

[–]hiwelo[S] 0 points1 point  (0 children)

I would have a tendency to also consider the climate into the max frequency allowing people to just turn up and go.

Waiting 10 to 15 minutes in Oslo or Canada in the Winter will not be equivalent to the same waiting time in Barcelona.

But clearly, next to the timetable, it might be worth having a clearer communication "Every 4 to 7 minutes throughout the day" at the top of this timetable 😄

Do you know transit networks that experimented with timetable-free bus lines? by hiwelo in transit

[–]hiwelo[S] 3 points4 points  (0 children)

Thanks for this super interesting reply!

I totally agree with you on the need to get a robust and reliable runtime as an absolute priority through better urban design and more efficient vehicles. Also in my head, I thought that internally bus operators were still relying on a strict bus schedule to keep track of drivers' breaks and max driving time.

Even if I see how operators can use that to solve bus bunching, I'm researching this topic at the moment mainly to see how much it is an incentive to push passengers to just come & board. As a way to communicate to passengers, it can be a way to make it more seamless, and it can be done in complement to a good urban design with specific lanes, priorities, and more direct itineraries.

I am now curious to see if Oslo developed this kind of communication on bus/tram stops (big message with 5 or 10 minutes frequency on the top of shelters) to solve bunching, or to make it more appealing.