SwiftDateTimeExtensions icon indicating copy to clipboard operation
SwiftDateTimeExtensions copied to clipboard

Build fails on XCode 6.2

Open ArminGrau opened this issue 10 years ago • 2 comments

Hi, I'm trying to build the timeDateExtensions.swift with xcode 6.2 for iOS 8.2 and getting a lot of conversion errors:

func combineComponents(left: NSDateComponents, right: NSDateComponents, multiplier: Int) -> NSDateComponents { let comps = NSDateComponents() comps.second = ((left.second != NSDateComponentUndefined ? left.second : 0) + (right.second != NSDateComponentUndefined ? right.second : 0) * multiplier) ... <'Int' is not convertible to 'NSDateComponents'>

Any idea what's wrong? As far as I see it NSDateComponents.secont still is an int.

by the way: love how this extensions make working with dates more readable!

Armin

ArminGrau avatar Mar 11 '15 14:03 ArminGrau

obviously NSDateComponentUndefined is a UInt, thereas NSDateComponents are int. Don't know what Apple thought when they did that... My solution would be

let undefined = Int(NSUndefinedDateComponent) ... comps.second = ((left.second != undefined ? left.second : 0) + (right.second != undefined ? right.second : 0) * multiplier)

ArminGrau avatar Mar 11 '15 14:03 ArminGrau

@ArminGrau, Maybe you would like to see the improved version? See Datify.

hemangshah avatar Jun 06 '17 10:06 hemangshah