gpt4 book ai didi

ios - 取消存档数据报告错误: Thread 1:EXC_BREAKPOINT(code=EXC_BREAKPOINT,子代码=xxxx)

转载 作者:行者123 更新时间:2023-11-30 12:50:00 28 4
gpt4 key购买 nike

当我归档我的数据时,出现了一个问题,我从未遇到过:

The issue

线程信息:

 0xda5434 <+120>: bl     0xc7a6f0                  
; function signature specialization <preserving fragile attribute,
Arg[1] = [Closure Propagated : reabstraction thunk helper from
@callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>)
-> () to @callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>) ->
(@out ()), Argument Types : [@callee_owned (@unowned Swift.UnsafeBufferPointer<Swift.UInt8>)
-> ()]> of generic specialization <preserving fragile attribute,
()> of Swift.StaticString.withUTF8Buffer <A> ((Swift.UnsafeBufferPointer<Swift.UInt8>) -> A) -> A
-> 0xda5438 <+124>: trap

The console log:

fatal error: unexpectedly found nil while unwrapping an Optional value

我的userStatic的一部分,归档取消归档数据是userStatic:

import UIKit

enum UserType: Int {
case terant
case normalUser
case normalUserFinancialer
}

@objc(UserStaticSwift)
class UserStaticSwift:NSObject, NSCoding {

//static let sharedInstance = UserStaticSwift()

var islogin: Bool = false

var type:UserType? {

didSet {

if type == .terant {
forOcType = 1
}else if type == .normalUser {

forOcType = 2
}else {
forOcType = 3
}
}
}
var forOcType:Int = 0
var username:String = ""
var password:String = ""
var userId: String = ""

// swiftSharedInstance is not accessible from ObjC
class var swiftSharedInstance: UserStaticSwift {
struct UserStatic {
static let instance = UserStaticSwift()
}
return UserStatic.instance
}

// the sharedInstance class method can be reached from ObjC
class func sharedInstance() -> UserStaticSwift {
return UserStaticSwift.swiftSharedInstance
}

...
// MARK: - coder
required init(coder aDecoder: NSCoder) {
super.init()

islogin = aDecoder.decodeObject(forKey: "islogin") as! Bool
//type = aDecoder.decodeObject(forKey: "type") as? UserType
// type = UserType(rawValue: aDecoder.decodeObject(forKey: "type") as! Int)!
/*if let type = UserTypeaDecoder.decodeObjectForKey("namesListArray") as? [String] {
namesListArray = namesList
} else {
namesListArray = [String]
}*/
if let temp_type = aDecoder.decodeObject(forKey: "type") as? Int {

type = UserType(rawValue: temp_type )
}else {

type = nil
}
forOcType = aDecoder.decodeObject(forKey: "forOcType") as! Int
username = aDecoder.decodeObject(forKey: "username") as! String
...

func encode(with aCoder: NSCoder) {

aCoder.encode(islogin, forKey: "islogin")
aCoder.encode(type!.rawValue, forKey: "type")
aCoder.encode(forOcType, forKey: "forOcType")
aCoder.encode(username, forKey: "username")
aCoder.encode(password, forKey: "password")
aCoder.encode(userId, forKey: "userId")
....

func addUserInfo(type:UserType, dic:[String: Any], closure:(Void)->Void) {


if type == .terant {

self.ter_status = UtilSwift.getIntFromAny(dic["status"] ?? "")
self.ter_logo = UtilSwift.getStrFromAny(dic["logo"])
self.ter_orgPhoto = UtilSwift.getStrFromAny(dic["orgPhoto"])
...

closure()
}

取消存档数据的位置:

let paths:NSArray = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) as NSArray
let path = paths.firstObject
let homePath = "\(path!)/\(Global.archive_userStaticData)"

print("unarchive_path:\(homePath)")

var userStatic:UserStaticSwift? = nil

if let loaded:Any = NSKeyedUnarchiver.unarchiveObject(withFile: homePath){

userStatic = (loaded as? UserStaticSwift)!
}else {

}

if userStatic == nil {

return
}

有人遇到同样的问题吗?我对问题很笨拙,从来没有遇到过信息。

最佳答案

init(coder aDecoder: NSCoder)方法中试试这个

required init(coder aDecoder: NSCoder) {

islogin = aDecoder.decodeBool(forKey: "islogin")
forOcType = aDecoder.decodeInteger(forKey: "forOcType") as! Int
if let temp_type = aDecoder.decodeInteger(forKey: "type") as? Int {

type = UserType(rawValue: temp_type )
}else {

type = nil
}

username = aDecoder.decodeObject(forKey: "username") as! String
password = aDecoder.decodeObject(forKey: "password") as! String
userId = aDecoder.decodeObject(forKey: "userId") as! String


}

我想这会对你有帮助

关于ios - 取消存档数据报告错误: Thread 1:EXC_BREAKPOINT(code=EXC_BREAKPOINT,子代码=xxxx),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41118866/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com