Swift - cannot call '-' with argument list like (NSNumber, NSTimeinterval)

I am trying to get the current time from a specific point from the starting point of the application.

var startTime = NSDate.timeIntervalSinceReferenceDate()
     var currentTime: NSNumber = 0

    for var i = 0; i < 10000; i++ {
        if i == 99 {
            currentTime = NSDate.timeIntervalSinceReferenceDate()
            println(i)
        }

    }
    var elapsedTime = currentTime - startTime
    println(Double(elapsedTime))
}

      

and I am getting this error:

Cannot invoke '-' with an argument list of type '(@!Value NSNumber, @!Value NSTimerinerval)

      

I understand this is something with the type I jutt can not, is that all, any suggestions?

+3


source to share


1 answer


startTime

- this NSTimeInterval

, which is not the same as NSNumber

what was declared as currentTime

at the top of this function.

Change your declaration currentTime

to:



 var currentTime: NSTimeInterval = 0

      

+2


source







All Articles