Swift 符合NSCoding的PFFile
我需要在Swift 符合NSCoding的PFFile,swift,parse-platform,nscoding,Swift,Parse Platform,Nscoding,我需要在UserDefaults的帮助下,存储我创建的PFObject子类的一些实例。问题是,它在试图编码(和解码)一个PFFile时崩溃 我查了一下,发现为了归档PFFile,它也应该符合NSCoding协议,显然它不符合。所以我将这些文件添加到我的项目中 现在一切都正常了,除了调用retrieveAdsFromDevice()时。然后我得到这个崩溃: *** Terminating app due to uncaught exception 'NSInvalidArgumentExcepti
UserDefaults
的帮助下,存储我创建的PFObject
子类的一些实例。问题是,它在试图编码(和解码)一个PFFile
时崩溃
我查了一下,发现为了归档PFFile
,它也应该符合NSCoding
协议,显然它不符合。所以我将这些文件添加到我的项目中
现在一切都正常了,除了调用retrieveAdsFromDevice()
时。然后我得到这个崩溃:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PFFile initWithCoder:]: unrecognized selector sent to instance 0x600000c386f0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010e0051bb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010d5ab735 objc_exception_throw + 48
2 CoreFoundation 0x000000010e023f44 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010e009ed6 ___forwarding___ + 1446
4 CoreFoundation 0x000000010e00bda8 _CF_forwarding_prep_0 + 120
5 Foundation 0x00000001099c5685 _decodeObjectBinary + 2409
6 Foundation 0x00000001099c3c67 _decodeObject + 246
7 Foundation 0x00000001099c3b63 -[NSKeyedUnarchiver decodeObjectForKey:] + 205
8 NUP 0x000000010626f768 $S3NUP4NPAdC5coderACSgSo7NSCoderC_tcfc + 3576
9 NUP 0x000000010627015f $S3NUP4NPAdC5coderACSgSo7NSCoderC_tcfcTo + 47
10 Foundation 0x00000001099c5685 _decodeObjectBinary + 2409
11 Foundation 0x00000001099c485f -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:] + 1684
12 Foundation 0x0000000109958c1c -[NSArray(NSArray) initWithCoder:] + 198
13 Foundation 0x00000001099c5685 _decodeObjectBinary + 2409
14 Foundation 0x00000001099c3c67 _decodeObject + 246
15 Foundation 0x00000001099c3b63 -[NSKeyedUnarchiver decodeObjectForKey:] + 205
16 Foundation 0x00000001099c2e64 +[NSKeyedUnarchiver unarchiveObjectWithData:] + 84
17 NUP 0x00000001061d9b87 $S3NUP11NPAdManagerC21retrieveAdsFromDeviceyyF + 887
18 NUP 0x00000001062d2a26 $S3NUP18HomeViewControllerC11viewDidLoadyyF + 438
19 NUP 0x00000001062d2c44 $S3NUP18HomeViewControllerC11viewDidLoadyyFTo + 36
20 UIKitCore 0x0000000116b3f4e1 -[UIViewController loadViewIfRequired] + 1186
21 UIKitCore 0x0000000116b3f940 -[UIViewController view] + 27
22 NUP 0x00000001063349c5 $S3NUP22RootPageViewControllerC21viewDidLayoutSubviewsyyF + 7237
23 NUP 0x0000000106336444 $S3NUP22RootPageViewControllerC21viewDidLayoutSubviewsyyFTo + 36
24 UIKitCore 0x0000000117648914 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1824
25 QuartzCore 0x000000010af8ab19 -[CALayer layoutSublayers] + 175
26 QuartzCore 0x000000010af8f9d3 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 395
27 QuartzCore 0x000000010af087ca _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 342
28 QuartzCore 0x000000010af3f97e _ZN2CA11Transaction6commitEv + 576
29 UIKitCore 0x00000001171792d0 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 139
30 CoreFoundation 0x000000010df6a62c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
31 CoreFoundation 0x000000010df69de0 __CFRunLoopDoBlocks + 336
32 CoreFoundation 0x000000010df64654 __CFRunLoopRun + 1284
33 CoreFoundation 0x000000010df63e11 CFRunLoopRunSpecific + 625
34 GraphicsServices 0x00000001109251dd GSEventRunModal + 62
35 UIKitCore 0x000000011715e81d UIApplicationMain + 140
36 NUP 0x00000001063b8a44 main + 68
37 libdyld.dylib 0x000000010ee27575 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
这是我的班级:
class NPAd: PFObject, NSCoding {
@NSManaged var type: String
@NSManaged var imageFile: PFFile
@NSManaged var link: String
@NSManaged var brandName: String
@NSManaged var brandIcon: PFFile
override init() {
super.init()
}
func encode(with aCoder: NSCoder) {
aCoder.encode(type, forKey: "type")
aCoder.encode(imageFile, forKey: "imageFile")
aCoder.encode(link, forKey: "link")
aCoder.encode(brandName, forKey: "brandName")
aCoder.encode(brandIcon, forKey: "brandIcon")
}
required init?(coder aDecoder: NSCoder) {
super.init()
type = aDecoder.decodeObject(forKey: "type") as! String
imageFile = aDecoder.decodeObject(forKey: "imageFile") as! PFFile
link = aDecoder.decodeObject(forKey: "link") as! String
brandName = aDecoder.decodeObject(forKey: "brandName") as! String
brandIcon = aDecoder.decodeObject(forKey: "brandIcon") as! PFFile
}
}
这就是我存储和检索数据的方式:
func storeAdsToDevice(_ adsToView: [NPAd]) {
let archivedData = NSKeyedArchiver.archivedData(withRootObject: adsToView)
UserDefaults.standard.set(archivedData, forKey: "AdsToView")
}
func retrieveAdsFromDevice() -> [NPAd] {
let archivedData = UserDefaults.standard.object(forKey: "AdsToView")
if let archivedData = archivedData as? Data {
return NSKeyedUnarchiver.unarchiveObject(with: archivedData) as? [NPAd] ?? []
}
return []
}
有什么想法吗?我试图安装你的Pod,但它似乎缺少一个文件:
[!] Error installing Parse-iOS-SDK
[!] /usr/bin/curl -f -L -o /var/folders/73/wg47j7351qx65npm3ncb9nw80000gn/T/d20190927-45089-1q578tl/file.zip http://parse-ios.s3.amazonaws.com/f1992e7a501affcc1906429e3690bae5/parse-library-1.2.21.zip --create-dirs --netrc-optional --retry 2
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (22) The requested URL returned error: 404 Not Found
我错过什么了吗?
在我的播客文件中:
pod 'Parse+NSCoding', '~> 0.1.4'
在没有版本的情况下也尝试过,但遇到了相同的问题 这不是我的吊舱,我刚找到。。。您是否尝试过克隆项目并手动添加文件?