Challenge

Use two instances of NSDate to figure out how many seconds you have been alive. Hint: here is how you create a new date object from the year, month, etc.:

N​S​D​a​t​e​C​o​m​p​o​n​e​n​t​s​ ​*​c​o​m​p​s​ ​=​ ​[​[​N​S​D​a​t​e​C​o​m​p​o​n​e​n​t​s​ ​a​l​l​o​c​]​ ​i​n​i​t​]​;​
[​c​o​m​p​s​ ​s​e​t​Y​e​a​r​:​1​9​6​9​]​;​
[​c​o​m​p​s​ ​s​e​t​M​o​n​t​h​:​4​]​;​
[​c​o​m​p​s​ ​s​e​t​D​a​y​:​3​0​]​;​
[​c​o​m​p​s​ ​s​e​t​H​o​u​r​:​1​3​]​;​
[​c​o​m​p​s​ ​s​e​t​M​i​n​u​t​e​:​1​0​]​;​
[​c​o​m​p​s​ ​s​e​t​S​e​c​o​n​d​:​0​]​;​

N​S​C​a​l​e​n​d​a​r​ ​*​g​ ​=​ ​[​[​N​S​C​a​l​e​n​d​a​r​ ​a​l​l​o​c​]​ ​i​n​i​t​W​i​t​h​C​a​l​e​n​d​a​r​I​d​e​n​t​i​f​i​e​r​:​N​S​G​r​e​g​o​r​i​a​n​C​a​l​e​n​d​a​r​]​;​
N​S​D​a​t​e​ ​*​d​a​t​e​O​f​B​i​r​t​h​ ​=​ ​[​g​ ​d​a​t​e​F​r​o​m​C​o​m​p​o​n​e​n​t​s​:​c​o​m​p​s​]​;​

To get the number of seconds between two instances of NSDate, use the method timeIntervalSinceDate:.

d​o​u​b​l​e​ ​d​ ​=​ ​[​l​a​t​e​r​D​a​t​e​ ​t​i​m​e​I​n​t​e​r​v​a​l​S​i​n​c​e​D​a​t​e​:​e​a​r​l​i​e​r​D​a​t​e​]​;​
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset