Fatal error: Unexpectedly found nil while unwrapping an Optional value.
It happens on my View (myStore.product!.title)
Post
Replies
Boosts
Views
Activity
Nice thx
Nice thx
The problem is when I am inside my formatDate function, if I debug mousing over the dateString variable, I can see the value "3000-01-01T08:00:00-08:00".
But when it reaches the line "let finalDate = dateFormatter.date(from: dateString)!", it returns me the error "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value"
The question is how it found nil, if when I mouse over the dateString variable, I can see the value in there ?
func formatDate(dateString: String) -> Date {
//first I dont know why my parameter gets here nil
let dateFormatter = ISO8601DateFormatter()
//at the dateFormatter, doesnt matter the options I set, the return is always the same.
dateFormatter.formatOptions = [
.withFullDate,
.withFullTime,
]
let finalDate = dateFormatter.date(from: dateString)!
return finalDate
}
There is no view since it's all done on the info.plist file
The problem was cache on my old computer :(
I tried to do that, but somehow the MyViewB (actually it's a list view) is opened but not active.
What I mean by that is the listview is loaded inside (Sheet/FullScreenCover) but you can't select anything on it.
You're right. I am doing in init.
But if I remove from init, how can I create the loop to create the navigation links in body?
struct MyListView: View {
var category: categoryModel
@ObservedObject var store = MyStore()
init(category: CategoryModel) {
self.category = category
store.getItemsByCategoryId: category.id)
}
var body: some View {
List(store.categories.indices, id:\.self) { categoryIndex in
let category = store.categories[categoryIndex]
NavigationLink(destination:
CategoryView(categoryId: category.id)
)
{
CategoryRow(category: category)
}
}
}
If I do this way I will have "Argument passed to call that takes no arguments"
I also tried:
store.getHomeItems() { () -> in
This is the signature for the method:
func getHomeItems() {
...
}
I dont want to do differently.
But when I do this way, self.callApi2(id) doesnt wait for self.callApi1 to finish.
self.callApi2(id) is triggered at the same time and because doesnt have an ID yet, it fails.
var id = self.callApi1()
self.callApi2(id)
Here what I've figured out:
If a picker is inside a Form, it's going to be frozen and not selectable
Form {
Picker("Choose a number", selection: $selection) {
ForEach(0 ..< data.count, id: \.self) { index in
Text(data[index])
}
}
}
If I wrap this form in a NavigationView, it's going to work perfectly.
NavigationView {
Form {
Picker("Choose a number", selection: $selection) {
ForEach(0 ..< data.count, id: \.self) { index in
Text(data[index])
}
}
}
However for my current design, I can't have a NavigationView on this View.
Is there a solution for that ?
Thx
Found a solution.
Replace the form with ScrollView instead of NavigationView and the picker will work :)