0

I have a requirement where I am reading a list of dates in which I need to extract the seconds from each date to perform some logic. This is being done on the Watch. The following example is taking up approximately 50mb of memory which is not acceptable.

for count in 1 ... 500000 {
    let currentDate = NSDate()

    let now = Calendar.current.component(.second, from: currentDate as Date)
    print(now)
}

Is there a more memory friendly way of extracting the seconds from a Date?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
majors44
  • 113
  • 1
  • 8
  • 2
    Have a look at https://stackoverflow.com/q/25860942/1187415 – Martin R Jul 12 '18 at 17:33
  • To be more specific, this is just an example. I have approximately 500,000 accelerometer records (instances of CMRecordedAccelerometerData). As the recording is 60hz a second, I have a lot of data to process. – majors44 Jul 12 '18 at 17:34
  • @MartinR - Your suggestion worked. Thank you so much! – majors44 Jul 12 '18 at 17:51

0 Answers0