当我尝试将代码输入游乐场时,我正在关注KVC和KVO的教程,但它不会运行。我收到错误"以NSException"类型的未捕获异常终止。我甚至尝试创建一个应用程序应用程序并将信息输入到viewController中以查看发生了什么,但仍然无法构建,这提供了对象不符合密钥编码的错误。我真的很想看到这项工作,我做错了什么?
import UIKit
import Foundation
//this is a reference object which means when it is copied, it will copy a reference to the same instance and not a brand new value like a value type does
class Student: NSObject {
var name: String = ""
var gradeLevel: Int = 0
}
let seat1 = Student()
seat1.setValue("Kelly", forKey: "name")
答案 0 :(得分:1)
你的问题不是游乐场。您的问题是,要使用Objective-C KVC机制,您需要使用void foo1(char** arr) { cout << arr << endl; }
void foo2(char* arr[]) { cout << arr << endl; }
int main() {
char *arr[] = {"a", "b"};
cout << arr << endl;
foo1(arr);
foo2(arr);
return 0;
}
标记该属性。
let motionManager = CMMotionManager()
if motionManager.isDeviceMotionAvailable {
motionManager.deviceMotionUpdateInterval = 0.1
motionManager.startDeviceMotionUpdates(to: OperationQueue()) { [weak self] (motion, error) -> Void in
if let attitude = motion?.attitude {
print(attitude.pitch * 180 / Double.pi)
DispatchQueue.main.async{
// Update UI
}
}
}
print("Device motion started")
}
else {
print("Device motion unavailable")
}
添加它将解决崩溃问题。