ios - Save time (NSDate) in NSUserDefaults -


i trying save time once "user" reachs limit. limit 10 example , once reachs limit, want save current time. has wait 1 hour continue playing. started doing this, error, when try this:

var currenttime = nsdate() currenttime = nsuserdefaults.standarduserdefaults() 

error:

cannot assign value of type 'nsuserdefaults' type 'nsdate'

it seems swift cannot save 'nsdate' 'nsuserdefault'.

nsuserdefaults.standarduserdefaults() kind of dictionary, dont use dictionary date, set date value 1 of keys:

 let userdefaults = nsuserdefaults.standarduserdefaults()       // save user defaults  userdefaults.setobject(nsdate(), forkey: "limitreachedondate")   // retrieve user defaults  let limitdate = userdefaults.objectforkey("limitreachedondate") as? nsdate ?? nsdate.distantfuture() 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -