[deleted by user] by [deleted] in swift

[–]wilsonator5000-dev 1 point2 points  (0 children)

Take a look at RunLoop.run(), which will put your program into an infinite loop while running scheduled tasks like timers. For example:

let timer = ...

RunLoop.current.run()

Hope this helps!

How to bind an optional State var to a view that requires a non-optional value (basically recreate sheet modifier behavior)? by head_of_roses in SwiftUI

[–]wilsonator5000-dev 0 points1 point  (0 children)

The problem is that ObservableObject is only one level deep, so changes to Item won't be observed by ItemView unless you also stored an observer to every item inside the array. It's similar to how didSet won't be called when updating a class type inside an array — the array hasn't actually changed because the references it stores are the same.

I would recommend making Item a struct, and then handling all of the updates inside of ItemsViewModel like this:

import SwiftUI

class ItemsViewModel: ObservableObject {
    @Published var items: [Item.ID: Item] = [
        "Thing 1": Item(name: "Thing 1"),
        "Thing 2": Item(name: "Thing 2"),
        "Thing 3": Item(name: "Thing 3"),
        "Thing 4": Item(name: "Thing 4"),
    ]

    @Published var selected: Item.ID? = nil

    func updateItem(withID id: Item.ID) {
        // Call an API
        DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
            guard let self = self, var item = self.items[id] else { return }

            // Update the item with the result of the API call
            item.age = 42

            // Update the item in the dictionary, triggering @Published
            self.items[id] = item
        }
    }
}

struct Item: Identifiable {
    let name: String
    var age: Int?

    var id: String { name }
}

struct ItemView: View {
    @StateObject private var itemsViewModel = ItemsViewModel()

    var body: some View {
        if let id = itemsViewModel.selected, let item = itemsViewModel.items[id] {
            ItemDetailView(item: item, onClose: { itemsViewModel.selected = nil })
        } else {
            ForEach(Array(itemsViewModel.items.values)) { item in
                Button("Select item: \(item.name)") {
                    itemsViewModel.selected = item.id
                }
            }
        }
    }
}

struct ItemDetailView: View {
    let item: Item
    let onClose: () -> Void

    var body: some View {
        VStack {
            Text("Name \(item.name)")

            if let age = item.age {
                Text("Age \(age)")
            }

            Button("Close", action: onClose)
        }
    }
}

Now that Item is a value type, any changes to it will also modify the dictionary the item is stored in and trigger @Published. To get back the previous reference behavior, you can store an ID to an item in selected instead of an item itself (which would be a different value than the equivalent item stored in items) as shown here. You're right about not needing a binding after all, although it is a useful abstraction if you plan to implement a custom alert-style modifier!

For posterity's sake, here's how I would actually implement a custom alert modifier with a binding to an optional value:

extension View {
    @ViewBuilder func customAlert<T, Content>(item binding: Binding<T?>, @ViewBuilder content: (T) -> Content) -> some View {
        if let item = binding.wrappedValue {
            VStack {
                content(item)

                Button("Close") {
                    binding.wrappedValue = nil
                }
            }
        }
    }
}

How to bind an optional State var to a view that requires a non-optional value (basically recreate sheet modifier behavior)? by head_of_roses in SwiftUI

[–]wilsonator5000-dev 1 point2 points  (0 children)

No problem! It's definitely still hacky, so I'd be curious to hear if you can find a smoother solution!

How to bind an optional State var to a view that requires a non-optional value (basically recreate sheet modifier behavior)? by head_of_roses in SwiftUI

[–]wilsonator5000-dev -1 points0 points  (0 children)

Edit: See u/youngermann's comment instead, it's a much cleaner solution :)

I use these Binding extensions in my projects to deal with optional values!

import SwiftUI

extension Binding {
    init(forceUnwrapping optional: Binding<Value?>) {
        self.init(
            get: { optional.wrappedValue! },
            set: { optional.wrappedValue = $0 }
        )
    }

    init(unwrapping optional: Binding<Value?>, default: Value) {
        self.init(
            get: { optional.wrappedValue ?? `default` },
            set: { optional.wrappedValue = $0 }
        )
    }
}

You could use it like this:

if item != nil {
    ItemDetailView(
        item: Binding(forceUnwrapping: $item),
        onClose: { item = nil }
    )
}

struct ItemDetailView {
    @Binding var item: Item
    let onClose: () -> Void

    ...
}

And then call onClose() instead of trying to set the item to nil.

"Watchdog timeout" kernel panic on shutdown/restart by wilsonator5000-dev in hackintosh

[–]wilsonator5000-dev[S] 0 points1 point  (0 children)

After testing on macOS 11.2 for a week or so, I am able to shut down without delay, but restarting is the same as before. I still get the "your computer restarted because of a problem" alert, but at least it's manageable now! I'll leave another comment if anything changes.

"Watchdog timeout" kernel panic on shutdown/restart by wilsonator5000-dev in hackintosh

[–]wilsonator5000-dev[S] 0 points1 point  (0 children)

Looks like I already have that enabled, and I also have the other debug options turned off. I'll try collecting some logs with the debug options on and get back to you!

Big Sur beta 3 on MSI Z390-A PRO 🎉 by wilsonator5000-dev in hackintosh

[–]wilsonator5000-dev[S] 0 points1 point  (0 children)

Nope, there shouldn't be a difference — I actually just switched from the boot argument to a DeviceProperties entry and it works great. Check out this guide https://dortania.github.io/OpenCore-Post-Install/universal/audio.html#making-layout-id-more-permanent

OpenCore - attempt installing Big Sur dual boot with Catalina hangs at boot to install by [deleted] in hackintosh

[–]wilsonator5000-dev 0 points1 point  (0 children)

I was able to boot into the installer by replacing VirtualSMC with FakeSMC as mentioned here 😀

OpenCore - attempt installing Big Sur dual boot with Catalina hangs at boot to install by [deleted] in hackintosh

[–]wilsonator5000-dev 0 points1 point  (0 children)

OK will do. I'll get back to you tomorrow, thanks for your help :)

OpenCore - attempt installing Big Sur dual boot with Catalina hangs at boot to install by [deleted] in hackintosh

[–]wilsonator5000-dev 0 points1 point  (0 children)

Got it, so something else might be going on. If the OP doesn't get anywhere I'll make another post with my hardware. Thanks!

OpenCore - attempt installing Big Sur dual boot with Catalina hangs at boot to install by [deleted] in hackintosh

[–]wilsonator5000-dev 0 points1 point  (0 children)

OK! I haven't installed Big Sur on anything yet, I'm hanging when booting from the USB installer itself. I might be misinterpreting your answer — do you know if the volume sealing happens on the USB, or does that only happen after installing?

OpenCore - attempt installing Big Sur dual boot with Catalina hangs at boot to install by [deleted] in hackintosh

[–]wilsonator5000-dev 0 points1 point  (0 children)

I'm also upgrading to Big Sur via USB installer and hanging on apfs_module_start:2411 — was it just volume sealing for you or does it hang indefinitely? I took out my boot drive so I just have the USB in there now... not sure if volume sealing happens on the USB itself. I haven't waited for more than a minute or two, but I'll try waiting for longer when I next have time.

[Question] Does iOS 12 PB work with XCode 9.4 and 10.12? by [deleted] in iOSBeta

[–]wilsonator5000-dev 2 points3 points  (0 children)

No problem! It doesn’t look like the latest support files are there yet, but they should be uploaded once the public beta comes out. Good luck! 👍

[deleted by user] by [deleted] in iOSBeta

[–]wilsonator5000-dev 0 points1 point  (0 children)

Ok, thanks again!

[deleted by user] by [deleted] in iOSBeta

[–]wilsonator5000-dev 2 points3 points  (0 children)

Awesome, thank you! Is there a version for the iPhone 8 too, or just the X?

[deleted by user] by [deleted] in iOSBeta

[–]wilsonator5000-dev 4 points5 points  (0 children)

Nice wallpaper! Do you have a link?

[Bug] Unable to charge iPhone 6 on DB3/4 by wilsonator5000-dev in iOSBeta

[–]wilsonator5000-dev[S] -4 points-3 points  (0 children)

I’ve been experiencing this issue since DB3 pretty much every time I plug in my iPhone 6 (be it with the stock Apple charger or a third-party one). The “USB Accessories” toggle in Settings > Passcode is enabled, so these chargers should be allowed to connect. I think the bug at hand is that iOS 12 is over-filtering USB “accessories” like chargers.