& NSKeyedUnarchiver
일부 복잡한 데이터를 Core-Data
에 저장하고 나중에 내 앱에서 검색하는 데 사용하고 있습니다. 이것은 지금까지 완벽하게 작동했지만 마이그레이션 후 Swift 3.0
은 내 코드에 만족스럽지 않습니다. NSKeyedArchiver & NSKeyedUnarchiver/Swift 3.0
나는 일찍 내 코드에서 이것을했습니다 : 여기
let masterArray = [firstArray, secondArray] as [Any]
let dataForApp:NSData = NSKeyedArchiver.archivedData(withRootObject: masterArray) as NSData
entityFieldsDico = ["dataForAppArray":dataForApp]
// Use entityFieldsDico to save dataForApp in Core-Data under the key "dataForAppArray".
코드를 검색하는 방법은 다음과 같습니다
var firstArray = [Int](), secondArray = [CGFloat]()
.......
// stores some values in firstArray and also in secondArray.
.......
다음
는 데이터를 저장하는 코드가 같은 모습입니다 데이터는 다음과 같습니다 :
if let archiveData = dbRecord.value(forKey: "dataForAppArray") {
let archiveArray = NSKeyedUnarchiver.unarchiveObject(with: archiveData as! Data)
firstArray = (archiveArray as! Array)[0] as [Int]
secondArray = (archiveArray as! Array)[1] as [CGFloat]
}
데이터를 검색하는 코드에 문제가있는 것 같습니다. 그것은 빌드시에 단순히 충돌합니다.
나는 그 두 라인을 주석 경우
//firstArray = (archiveArray as! Array)[0] as [Int]
//secondArray = (archiveArray as! Array)[1] as [CGFloat]
이 프로그램은 사용할 수 없습니다 firstArray를 &의 데이터가 (분명히)는 사실을 제외하고 작동합니다.
내가 코멘트를하지 않는다면, 아래에있는 것과 같은 것으로 끝나는 매우 긴 메시지로 끝나는 크래시가 발생합니다. (나는 메시지를 단축하기 위해 몇 가지 ... (점)를 추가합니다.)
.............
0 swift 0x000000010d71fa3d PrintStackTraceSignalHandler(void*) + 45
1 swift 0x000000010d71f466 SignalHandler(int) + 470
2 libsystem_platform.dylib 0x00007fffa0c5a52a _sigtramp + 26
3 libsystem_platform.dylib 0x0000000000000003 _sigtramp + 1597659891
4 swift 0x000000010b25b4e3 swift::constraints::ConstraintGraphScope::~ConstraintGraphScope() + 899
5 swift 0x000000010b2f45f4 swift::constraints::ConstraintSystem::solveSimplified(llvm::SmallVectorImpl<swift::constraints::Solution>&, swift::FreeTypeVariableBinding) + 24868
...........
Objects-normal/arm64/UP_ViewController.dia -emit-dependencies-path /Users/me/Library/Developer/Xcode/DerivedData/TheApp-dszaazmmftlmwbicuwcwaplkjdfs/Build/Intermediates/TheApp.build/Debug-iphoneos/TheApp.build/Objects-normal/arm64/UP_ViewController.d -emit-reference-dependencies-path /Users/me/Library/Developer/Xcode/DerivedData/TheApp-dszaazmmftlmwbicuwcwaplkjdfs/Build/Intermediates/TheApp.build/Debug-iphoneos/TheApp.build/Objects-normal/arm64/UP_ViewController.swiftdeps -o /Users/me/Library/Developer/Xcode/DerivedData/TheApp-dszaazmmftlmwbicuwcwaplkjdfs/Build/Intermediates/TheApp.build/Debug-iphoneos/TheApp.build/Objects-normal/arm64/UP_ViewController.o -embed-bitcode-marker
1. While type-checking 'computeFunction' at /Users/me/Documents/iOS/TheApp/TheApp/UP_ViewController.swift:184:5
2. While type-checking expression at [/Users/me/Documents/iOS/TheApp/TheApp/UP_ViewController.swift:235:17 - line:235:66] RangeText="firstArray = (archiveArray as! Array)[0] as [Int]"
나는 사람이 이런 종류의 문제를 경험하고, 나에게 당신이 그것을 해결하는 방법을 알려 주시기 바랍니다.
내 대답을 체크 아웃 –