Tawa / TNTutorialManager

Tutorial Handler that helps you implement interactive on boarding and tutorials inside your iOS Apps.
MIT License
108 stars 6 forks source link

Documentation needed for updateTutorial(), shouldDisplayTutorial(), and behaviour of UserDefaults #3

Closed shirakaba closed 6 years ago

shirakaba commented 6 years ago

updateTutorial()

I'm mostly unsure of what updateTutorial() does (I can't really read Obj-C, so would have to study it for a bit). Some documentation would help.

shouldDisplayTutorial()

Seems that shouldDisplayTutorial() merely checks whether the stored index is 0, which I think makes it a poorly named function; perhaps this check should instead just be left to the user, by exposing currentIndex (which I've done in pull request #4). Could even remove shouldDisplayTutorial() thereafter.

Behaviour regarding UserDefaults

This was a major adoption issue for me; After completing a tutorial once, I could only ever getTMTutorialManager to appear again if I were to instantiate it without the delegate on a re-run of the app. Turns out that it was persisting state in UserDefaults! I feel instinctively like this should be more the responsibility of the user, but as long as it's documented, I'm happy enough to have it abstracted away from me.

To restart the tutorial from the beginning again (by clearing the last-stored reached stage of the tutorial), in Swift:

// Where "mainVC" matches the identifier returned by TNTutorialManagerDelegate's 
// `tutorialIdentifier()` optional function.
UserDefaults.standard.removeObject(forKey: "TNTutorial"+"mainVC")

... And in Obj-C:

// Where "mainVC" matches the identifier returned by TNTutorialManagerDelegate's 
// `tutorialIdentifier()` optional function.
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"TNTTutorialmainVC"]

(Could be written a bit more clearly; just that I don't know how to do string concatenation in Obj-C).

I guess that this wasn't the intended usage, so I've created a pull request #4 to allow resetting of the tutorial stage back to zero so that TNTutorialManager can manage its UserDefaults all by itself.

Tawa commented 6 years ago

This is fixed in version 1.3.1