Search code examples
swiftnsdatanstimeinterval

Convert NSTimeInterval to NSData and back to NSTimeInterval


How do I convert an NSTimeInterval value to NSData?


Solution

  • You may also use NSKeyedArchiver:

        let time = NSTimeInterval(100)
    
        let archivedTime = NSKeyedArchiver.archivedDataWithRootObject(time)
        let unarchivedTime = NSKeyedUnarchiver.unarchiveObjectWithData(archivedTime) as! NSTimeInterval