我正在使用 CoreData 和 JSON 解析与 Decodable 进行后续操作,并在初始化程序末尾遇到错误'self.init' isn't called on all paths before returning from initializer:
import Foundation
import CoreData
extension CodingUserInfoKey {
static let managedObjectContext = CodingUserInfoKey(rawValue: "managedObjectContext")!
}
@objc(Task)
public class Task: NSManagedObject, Decodable {
enum CodingKeys: String, CodingKey {
case diff, title, desc, doc
}
required convenience public init(from decoder: Decoder) throws {
guard let context = decoder.userInfo[CodingUserInfoKey.managedObjectContext] as? NSManagedObjectContext else {
print("Decode context error")
return
}
guard let entity = NSEntityDescription.entity(forEntityName: "Task", …Run Code Online (Sandbox Code Playgroud) 我已经试过了:
myButton.highlight(true)
Run Code Online (Sandbox Code Playgroud)
但这只会将按钮变成深蓝色,这是按钮的“按下状态”。
另外,当我按键盘上的Enter键时,该按钮将不起作用。
按下Enter键后,如何使按钮突出显示(蓝色)并可切换?