Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TestDataTaskRepository in View Preview #2

Closed
cytrix86 opened this issue Mar 22, 2020 · 2 comments
Closed

Use TestDataTaskRepository in View Preview #2

cytrix86 opened this issue Mar 22, 2020 · 2 comments
Labels
question A reader had a question about the code.

Comments

@cytrix86
Copy link

Hi,

first of all thanks for your great work. It is really a massive help for someone just starting with SwiftUI and Firebase.

I was looking for a solution to keep the TestDataTaskRepository providing the Data for the preview of the TaskListView so making changes to the cell still becomes visible while running the app uses the Firebase repository - as I am quite new to SwiftUI and especially Resolver if couldn't figure it out.

Thank you in advance.

Kind reagards

@peterfriese
Copy link
Owner

Hi @cytrix86 - thanks for the kind words!

To achieve this, you can change the PreviewProvider in TaskListView, like so:

struct TaskListView_Previews: PreviewProvider {
  static var previews: some View {
    let vm = TaskListViewModel()
    vm.taskRepository = TestDataTaskRepository()
    return TaskListView(taskListVM: vm)
  }
}

Hope this helps.

Cheers,
Peter

@peterfriese peterfriese added the question A reader had a question about the code. label Mar 22, 2020
@cytrix86
Copy link
Author

Hi Peter,

Thanks for your help. It does not work instantly because of the change in the Tasks id for Firebase. I changed the test data accordingly:

#if DEBUG let testDataTasks = [ Task(id: UUID().uuidString, title: "Implement UI", priority: .medium, completed: true), Task(id: UUID().uuidString, title: "Connect to Firebase", priority: .medium, completed: false), Task(id: UUID().uuidString, title: "????", priority: .high, completed: false), Task(id: UUID().uuidString, title: "PROFIT!!!", priority: .high, completed: false) ] #endif

I also tried to change the Resolver injection with and conditional #if DEBUG but that affects the Simulator as well. At the moment I am changing it manually - can you think of a more elegant solution?

Cheers,
Fabian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question A reader had a question about the code.
Projects
None yet
Development

No branches or pull requests

2 participants