Class 没有初始值设定项 (Xcode 6.3)
Class has no initializers (Xcode 6.3)
更新到 Xcode 6.3 后尝试找出错误。我有一个 class 出现错误 'Class has no initializers' 谁能告诉我如何解决这个问题?
class TodayViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, BWWalkthroughViewControllerDelegate {
var events: [EKEvent] = []
let eventStore = EKEventStore()
var pttCalendar: EKCalendar?
let walkthroughVC : BWWalkthroughViewController?
@IBOutlet weak var tableView: UITableView!
var dateFormatter = NSDateFormatter()
override func viewDidLoad() {
super.viewDidLoad()
requestCalendarAccess()
let firstLaunch = NSUserDefaults.standardUserDefaults().boolForKey("FirstLaunch")
if firstLaunch {
println("Not first launch.")
}
else {
showWalkthrough()
println("First launch, setting NSUserDefault.")
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "FirstLaunch")
}
self.tableView.rowHeight = 50
dateFormatter.dateFormat = "EE, MMM dd"
let dateForLabel = dateFormatter.stringFromDate(NSDate())
self.title = dateForLabel
}
您忘记了覆盖 func init()
您需要一个初始化程序来设置值
let walkthroughVC : BWWalkthroughViewController?
将其设置为 var
将消除错误。它当然会默认为 nil
.
更新到 Xcode 6.3 后尝试找出错误。我有一个 class 出现错误 'Class has no initializers' 谁能告诉我如何解决这个问题?
class TodayViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, BWWalkthroughViewControllerDelegate {
var events: [EKEvent] = []
let eventStore = EKEventStore()
var pttCalendar: EKCalendar?
let walkthroughVC : BWWalkthroughViewController?
@IBOutlet weak var tableView: UITableView!
var dateFormatter = NSDateFormatter()
override func viewDidLoad() {
super.viewDidLoad()
requestCalendarAccess()
let firstLaunch = NSUserDefaults.standardUserDefaults().boolForKey("FirstLaunch")
if firstLaunch {
println("Not first launch.")
}
else {
showWalkthrough()
println("First launch, setting NSUserDefault.")
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "FirstLaunch")
}
self.tableView.rowHeight = 50
dateFormatter.dateFormat = "EE, MMM dd"
let dateForLabel = dateFormatter.stringFromDate(NSDate())
self.title = dateForLabel
}
您忘记了覆盖 func init()
您需要一个初始化程序来设置值
let walkthroughVC : BWWalkthroughViewController?
将其设置为 var
将消除错误。它当然会默认为 nil
.