Search code examples
iosuibuttonnsuserdefaultsreporting

Disable button taps for duration of time iOS


Concept: When userA reports userB I need to disable the report button for duration of time so that userA can't repeatedly report same user.

Solution: Store data in NSUserDefaults where the key would be a String like report_userBId and value would be a timestamp 24 hours out from current date (of type Double). This way, each time userA attempts to report another user, I check NSUserDefaults to see if userA already reported userB. If so, I check if current time is greater than the stored timestamp, and if so, remove data from NSUserDefaults and allow user to send report.

I have not actually implemented this solution yet, and would like to know if this is the type of problem where NSUserDefaults is the best solution, or should I use something like Core Data?


Solution

  • I definitely agree with @Russel.

    Using CoreData for this task is like kill a mosquito with a rocket!

    If you've already implemented and used it, you may add support, otherwise, just use NSDefaults...