は私data
をアーカイブ、issue
が来る、私は会うことはありません:アーカイブしないデータ・レポート・エラー:スレッド1:EXC_BREAKPOINT(コード= EXC_BREAKPOINT、サブコード= XXXX)
thread
情報:
userStatic
の
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
パート、archive
とunarchive
データがuserStatic
です:
import UIKit
enum UserType: Int {
case terant // 商户 1
case normalUser // 普通用户 2
case normalUserFinancialer // 普通用户的财务 3
}
@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 // 类型,为了方便oc调用
var username:String = ""
var password:String = ""
var userId: String = "" // 用户id
// 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()
}
場所unarchive
データ:
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
}
誰かが同じ問題が発生しますか?私はissue
に不器用です、情報を決して満たすことはありません。
チェックアウト私の答え[http://stackoverflow.com/questions/41116832/when-archive-object-in-を助けるだろうと思い試してみてくださいthe-func-encodewith-acoder-nscoder-method-crashed-with/41116908#41116908](http://stackoverflow.com/questions/41116832/when-archive-object-in-the-func-encodewith-acoder-nscoder -method-crashed-with/41116908#41116908) –
@jignesh Vadadoriya同じことではありませんが、この問題は「アーカイブ解除」が原因です。アーカイブのためです。 – aircraft
checkout私の答え –