1

Let's say I'm creating a workout app and need to let the user to create new workouts and exercises.

We'll get the following view controllers: Workouts -> New Workout -> Choose existing or Create new -> Create a new workout -> Choose exercises or Create new -> Create a new exercise -> Sets & Reps.

The user should be able to go back and forth between those views while creating a new workout. So the workout parameters should be saved somewhere temporary until the user is happy with everything and clicks "Save workout" button which finally saves it to sql database/coredata.

Should I be passing workout parameters between views using segues and delegates or should I create and use "NewWorkout" and "NewExercise" singletons here? Will singleton approach work fine if my user needs to create another workout? Can I just destroy the first instance and create a new one?

I've already started with segues and it's a mess. Want to refactor my code until it's not too late.

Community
  • 1
  • 1
Maklaus
  • 384
  • 1
  • 8
  • 31
  • How about creating a temporary workout in core data and pass the workout id between controllers? – Jano Aug 10 '15 at 08:42
  • That's actually an option too. But I kind of like singleton more here. Since I don't want to end up with a garbage collector for unfinished workouts hanging in CoreData. – Maklaus Aug 17 '15 at 03:18

2 Answers2

3

I don't think the draft workout would be a good singleton. You could create a singleton for the management of all workouts. You could give that object a draftWorkout field. And a clearDraft and saveDraft methods.

Raymond
  • 3,510
  • 2
  • 17
  • 22
  • That what I was thinking about, thanks. Anything bad I should avoid here not to step onto one of singleton anti-patterns? – Maklaus Aug 10 '15 at 13:31
0

singletons - it's bad decision, normally you should crate some kind of "Workout" object on first step and move it through all the steps...

Igor
  • 1,517
  • 10
  • 12