我的代码有问题。任何人都可以帮助我吗?
错误:2015-12-10 19:57:58.890 time[1177:36084] *** 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因: '[<time.ViewController 0x79122de0> setValue:forUndefinedKey:]: 这个 类不符合键显示的键值编码。 *** 首先抛出调用堆栈: ( 0 CoreFoundation 0x001fea14 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x01eafe02 objc_exception_throw + 50 2 核心基础 0x001fe631 -[NSException 引发] + 17 3 基础 0x006501bc -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282 4 基础 0x005aa83a _NSSetUsingKeyValueSetter + 115 5 基础 0x005aa7bf -[NSObject(NSKeyValueCoding) setValue:forKey:] + 295 6 UIKit 0x00ba306d-[UIViewController setValue:forKey:] + 85 7 基础 0x005df01d -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 384 8 UIKit 0x00e16cb4-[UIRuntimeOutletConnection 连接] + 132 9 libobjc.A.dylib 0x01ec400c -[NSObject performSelector:] + 62 10 核心基础 0x0012ef51 -[NSArray makeObjectsPerformSelector:] + 273 11 UIKit 0x00e1534e-[UINib 实例化WithOwner:选项:] + 2102 12 UIKit 0x00baaabc-[UIViewController _loadViewFromNibNamed:bundle:] + 429 13 UIKit 0x00bab4f4-[UIViewController 加载视图] + 189 14 UIKit 0x00bab900 -[UIViewController loadViewIfRequired] + 154 15 UIKit 0x00bac1ed-[UIViewController 视图] + 35 16 UIKit 0x00a59f94 -[UIWindow addRootViewControllerViewIfPossible] + 69 17 UIKit 0x00a5a6b1 -[UIWindow _setHidden:forced:] + 304 18 UIKit 0x00a5aa67 -[UIWindow _orderFrontWithoutMakingKey] + 49 19 UIKit 0x00a6e118 -[UIWindow makeKeyAndVisible] + 80 20 UIKit 0x009d66e7-[UIApplication_callInitializationDelegatesForMainScene:transitionContext:] + 4190 21 UIKit 0x009ddcd6-[UIApplication_runWithMainScene:transitionContext:completion:] + 1989 22 UIKit 0x00a02ee5 __84-[UIApplication_handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke3218 + 68 23 UIKit 0x009da966 -[UIApplication 工作区DidEndTransaction:] + 163 24 FrontBoardServices 0x03c37c76 __37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 71 25 FrontBoardServices 0x03c3774d __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54 26 前板服务 0x03c55173 -[FBSSerialQueue _performNext] + 184 27 前板服务 0x03c555aa -[FBSSerialQueue _performNextFromRunLoopSource] + 52 28 前板服务 0x03c548a6 FBSSerialQueueRunLoopSourceHandler + 33 29 核心基础 0x001186ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15 30 核心基础 0x0010e38b __CFRunLoopDoSources0 + 523 31 核心基础 0x0010d7a8 __CFRunLoopRun + 1032 32 核心基础 0x0010d0e6 CFRunLoopRunSpecific + 470 33 核心基础 0x0010cefb CFRunLoopRunInMode + 123 34 UIKit 0x009da206 -[UIApplication_run] + 540 35 UIKit 0x009dfbfa UIApplicationMain + 160 36 次 0x0001940c 主 + 140 37 libdyld.dylib 0x02913a21 开始 + 1 ) libc++abi.dylib:以 NSException 类型的未捕获异常终止 (lldb)
我的代码是:
//
// ViewController.swift
// time
//
// Created by Marek on 09.12.15.
// Copyright © 2015 Marek. All rights reserved.
//
import CoreFoundation
import CoreGraphics
import Darwin
import Foundation
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var currentTimeLabel: UILabel!
var timer = NSTimer()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.timer = NSTimer.scheduledTimerWithTimeInterval(
1.0,
target: self,
selector: Selector("tick"),
userInfo: nil,
repeats: true)
}
@objc func tick() {
currentTimeLabel.text = NSDateFormatter.localizedStringFromDate(NSDate(),
dateStyle: .MediumStyle,
timeStyle: .MediumStyle)
}
}