Post

Replies

Boosts

Views

Activity

Reply to unexpected nil
I tested in playground in an init, and no crash: class OrderTest { struct Order { var order: Int } var nextOrder: Int? var allItems : [Order] = [] init() { nextOrder = self.allItems.map{$0.order}.max() print("nextOrder", nextOrder) if nextOrder == nil { nextOrder = 0 } print("nextOrder after test", nextOrder) nextOrder! += 1 // <--- Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value } } let orderTest = OrderTest() So problem is somewhere else. Could you show the class or structure where this init() is ? One way I could get it crash was by delaying the allocation of next order with a Dispatch: class OrderTest { struct Order { var order: Int } var nextOrder: Int? var allItems : [Order] = [] init() { nextOrder = self.allItems.map{$0.order}.max() if nextOrder == nil { DispatchQueue.main.async(execute: { // <<-- WITH THIS, IT CRASHES self.nextOrder = 0 }) } nextOrder! += 1 // <--- Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value } } Did you show the exact and complete init() ?
Nov ’24
Reply to unexpected nil
It may be because you do it in the init. I propose to add a return. init() { nextOrder = self.AllItems.map{$0.order}.max() if nextOrder == nil { nextOrder = 0 return // <<-- ADD THIS } nextOrder! += 1 // <--- Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value } or add an else: init() { nextOrder = self.AllItems.map{$0.order}.max() if nextOrder == nil { nextOrder = 0 } else { // <<-- ADD THIS nextOrder! += 1 // <--- Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value } }
Nov ’24
Reply to What should I do when my Development or App Store certificates expire?
Don't worry, no problem with your existing apps. Just needed to submit a new release. You can do it even when certificates have expired. But you can do it now, before it expires. I know at least 2 ways (I prefer the first): First go to Xcode > Settings > accounts select your account and there ask for new certificates if you see they will obsolete soon. that's it Second In Xcode project, select TARGETS In signing and capabilities, you will see the certificate is obsolete. Ask to sign again
Nov ’24
Reply to Binding of an array element property inside a struct not working anymore
You don't show enough code (eg, ContentView) to find out what is the problem. Card is not ObservableObject. That may be the cause of the problem. Try to make it a class and ObservableObject. 2 more comments: why don't you use environmentObject for deck, instead of all the bindings ? in Xcode16, observable is much easier to use than ObservableObject. If needed, get details here: https://medium.com/@vladislavshkodich/remove-observableobject-from-your-swiftui-model-cb455e9572ef
Topic: UI Frameworks SubTopic: SwiftUI
Nov ’24
Reply to Can someone help me fix my xcode.
I was looking for User definition. It is a Firebase class, should be this one: https://firebase.google.com/docs/reference/swift/firebaseauth/api/reference/Protocols/UserInfo.html I suppose error is here: let updatedUser = User( coder: <#NSCoder#>, id: userId, name: name, email: email, phoneNumber: phoneNumber, profilePictureURL: nil, bio: bio ) why do you include coder here ? And what does <#NSCoder#> mean ? Where did you get it ? I understand you have several init for User: either with coder public required convenience init?(coder: NSCoder) or direct declaration with all the properties. So, you'd better study carefully FireBaseAuth documentation.
Nov ’24