Your Second iOS and SwiftUI App · Section Views | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5662524-your-second-ios-and-swiftui-app/lessons/26

Jessy,

For this part of the course, I continued with the .enumeration line of code rather than the extended files. However, I cannot build because of "Cannot convert value of type ‘[TaskStore.PrioritizedTasks]’ to expected argument type ‘Range’ " in the content view. Did I need to do some additional work when moving the ForEach from ContentView to SectionView?

Hi Daniel,

I’m not sure what you mean by

.enumeration line of code rather than the extended files

It sounds to me like you’re trying to use an unsupported ForEach overload. If that’s the case, you either need my extension, or this alternative.

Jessy,

Thanks for the response, apologize for being vague. When I said “.enumeration line” I was referring to the alternative you have linked here.

When I moved the alternative from ContentView to SectionView, I received the error. Code was working fine until I copy-pasted.

Thanks again for the help.

I can’t replicate the problem. Upload your version and I’ll have a look!

Jessy,

You and your teammates here are amazing! Thanks. I wasn’t sure of the best way to upload so zipped the whole thing and attached below.

As an additional aside, let’s say I wanted to use a SQL database for a task vice an array in the Model and wanted to avoid CoreData. Knowing that I would need a wrapper, where do I run the queries…in the model or viewmodel? Would I use combine as demonstrated here to monitor state and then insert or update the database when marked as completed or deleted? While learning before, I made a brute force objective-c app that updated the database with a Save button then requeried in a function in viewDidLoad(), what’s the best way with SwiftUI?

Thanks again!
TaskList.zip (83.4 KB)

.zip attachments are a great way to share here. :+1:


Your issue is that you were still trying to use my overload even though it wasn’t in the project. Instead, you need to switch to the same overload that you did in SectionView.

ForEach(
  Array( taskStore.prioritizedTasks.enumerated() ),
  id: \.element.id
) { index, _ in
  SectionView(prioritizedTasks: self.$taskStore.prioritizedTasks[index])
}

As for SQL + SwitftUI, the best solution is probably going to look a lot like what Core Data + SwiftUI looks like. We don’t have content available on either yet, but here’s a concise article on the latter. If I had to tackle this, I’d probably start with creating the SQL equivalent of the FetchRequest property wrapper and FetchedResults structure. (Which are, sadly, poorly documented this first year!)

@jessycatterwaul, how do we define wether we need a preview or not?
And what is the function of preview? When does it actually work for the app?=)

If you find that rendering a preview for a view is useful, then use a preview! Sometimes, it’s not worth the trouble to preview a single view, when it’s going to always be contained by other views, e.g. in a List.

And what is the function of preview? When does it actually work for the app?=)

I’m not sure what you’re asking here. Possibly my answer above covers it?

1 Like

Yes! That’s what I wanted to hear exactly =)

1 Like

Hi @jessycatterwaul,

I am seeing an error when I create a RowView.
Here is the error -

Generic parameter ‘Subject’ could not be inferred

I am not able to upload my files here ( I get an error saying new users cannot upload) and when I paste my code, it is pretty badly formatted and unreadable. So, I created a gist in github and added my code for SectionView.swift and TaskStore.PrioritizedTasks.swift - SectionView.swift · GitHub

It would be great if you could help me out with what I am missing.
P.S. I downloaded the materials for that course section and I don’t see any errors there. I compared it with the code I have and I dont see any difference.

That error message, as is common with SwiftUI right now, is not helpful at all! :joy_cat:

You just need to make your TaskStore.PrioritizedTasks.tasks mutable. i.e. use var instead of let.

oh dang!! I missed that!
thank you @jessycatterwaul

1 Like

In ContentView.swift, when using the ForEach I have the error message: Cannot convert value of type 'Array<TaskStore.PrioritizedTasks>' to expected argument type 'Range<Int>'

I have been checking the project provided and mine and most of the code looks the same.
I wonder if I didn’t added properly the extension files provided in a previous video properly.

Edit:
I have copied the extension into the ContentView.swift file and it still shows the error.

Edit 2:
ApparentIy the code was ok but I had to delete the derived data for making it work.

Screen Shot 2020-10-13 at 9.20.26 PM
Can anyone help me ,here?

I’m not seeing that error with the uploaded materials. Upload your version, and I’ll have a look!

@mrossi Really glad you sorted it out!

@ruizkalvin Do you still have issues with this?