How can I reduce the number of if-statements in this (below) situation? I'm aware of switch-statements but can't imagine how that would help in this situation.
Here's what's happening below:
- The first IF safely checks for a date stored in NSDefault, that may or may not exist
- If the date exists (true), it checks if the date is before "now"
- If the date is before "now" (true), it safely checks for a user preference of On/Off in NSDefault, this too may or may not exist
- If it does exist, it checks if that its not equal to off
-
Finally, if #4 was true, the function is called
//Queue up more quote notifications? if let notif_EndDate = (userPref_NSDefault.objectForKey("notification_EndDate")) as? NSDate { if notif_EndDate.isLessThanDate(self.now) { if let quoteNotif_Pref = (userPref_NSDefault.stringForKey("WeeklyQuote_Pref")) { if quoteNotif_Pref != "Off" { quoteNotifications() } else { print("Use has set 'Weekly Quotes' to 'Off'") } } else { quoteNotifications() } } } else { quoteNotifications() }
Aucun commentaire:
Enregistrer un commentaire