在Swift中使用var方法时得到“EXC_BAD_ACCESS”

时间:2015-02-01 06:27:50

标签: swift compiler-errors

enter image description here

我不知道下面的代码有什么问题。我认为它应该有效。我得到的错误是EXC_BAD_ACCESS

// Playground - noun: a place where people can play

import UIKit

extension NSCalendar {
    func nextDay(date:NSDate) -> NSDate {
        var dateComponents = self.components(.YearCalendarUnit | .MonthCalendarUnit | .DayCalendarUnit, fromDate: date)
        dateComponents.day += 1
        let nextDate = self.dateFromComponents(dateComponents)!

        return nextDate
    }

    func getNextDay(date:NSDate) -> NSDate {
        var method = nextDay
        let tomorrow = method(date)

        return tomorrow
    }
}

![enter image description here][2]let calendar = NSCalendar.currentCalendar()
let today = NSDate()

let tomorrow = calendar.getNextDay(today)

0 个答案:

没有答案