필자는 기본 클래스 인 "var"와 원시 정수 값의 배열 또는 CMTime과 같은 구조체의 배열을 가진 Swift 클래스를 얻었습니다. 개체에 NSKeyedArchiver.archiveRootObject를 수행 할 때 인코딩 값을 정수 값인 [CMTime]과 정수 배열 중 가장 작은 값으로 제한하면 모든 것이 잘 동작합니다. (인코딩 할 수 있고 디코드하고 내용의 동일성을 확인할 수 있습니다.) 수수께끼 인 것은 디버거가 이해할 수있는 [UInt16] 인코딩이 100M 미만인 경우 엔 인코딩하는 동안 앱의 메모리 할당이 4Gb로 증가합니다 , 8Gb, 12Gb (여기서 STOP을 누르십시오). coder.encode (aSwiftArray, forKey : "aKey")를 사용하는 데 문제가 있습니까? 가끔씩 작동하지만 다른 곳에서는 사용할 수 없습니까?Swift 3 인코딩이 왜 실행되지 않습니까?
typealias WordSize = UInt16
class PixelHistogram :NSObject, NSCoding {
var pixelCount:Int = 0
var timeAtFrame: [CMTime] = [] // CMTime for each frame
var pixelVsDelta: [UInt] = [] // 256x256 histogram of pixel vs DeltaPixel
var histPixel:[WordSize] = [] // histogram of Y at each pixel [pixelCount][256]
}
// Initializing the various arrays...
histPixel = [WordSize](repeating: 0, count: 256*pixelCount)
pixelVsDelta = [UInt](repeating: 0, count: 256*256)
required convenience init?(coder aDecoder:NSCoder){
self.init()
timeAtFrame = aDecoder.decodeObject(forKey:Slot.timeAtFrame.rawValue) as! [CMTime]
pixelVsDelta = aDecoder.decodeObject(forKey:Slot.pixelVsDelta.rawValue) as! [UInt]
func encode(with coder:NSCoder)
coder.encode(timeAtFrame, forKey: Slot.timeAtFrame.rawValue)
coder.encode(pixelVsDelta, forKey: Slot.pixelVsDelta.rawValue)
}
관련 코드로 [편집] 질문. – rmaddy
필요한 경우 코드 업로드 관련 샘플 보여주기 –