Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Futhark

macrumors 65816
Original poster
Jun 12, 2011
1,238
179
Northern Ireland
Hi all, I have a function that worked perfectly in Xcode 7 written for iOS 9 but when I try to get it to work in Xcode 8 Beta 4 written for iOS 10 converted to Swift 3 syntax I get an error "Extra argument in call"

I will show my working code first then the broken code:

Swift 2:

Code:
func getTime() -> (hour:Int, minute:Int, second:Int) {
        let currentDateTime = NSDate()
        let calendar = NSCalendar.currentCalendar()
        let component = calendar.components([.Hour,.Minute,.Second], fromDate: currentDateTime)
        let hour = component.hour
        let minute = component.minute
        let second = component.second
        return (hour,minute,second)
    }

Swift 3:

Code:
func getTime() -> (hour:Int, minute:Int, second:Int) {
        let currentDateTime = NSDate()
        let calendar = NSCalendar.current
        let component = calendar.component(.hour, .minute, .second, from: currentDateTime)
        let hour = component.hour
        let minute = component.minute
        let second = component.second
        return (hour,minute,second)
    }

This is the line I get the error:

Code:
let component = calendar.component(.hour, .minute, .second, from: currentDateTime)

Any help would be much appreciated :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.