Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-[PFFile initWithCoder:]: unrecognized selector sent to instance #38

Open
Samigos opened this issue Sep 8, 2019 · 3 comments
Open

-[PFFile initWithCoder:]: unrecognized selector sent to instance #38

Samigos opened this issue Sep 8, 2019 · 3 comments

Comments

@Samigos
Copy link

Samigos commented Sep 8, 2019

Whenever I'm trying to unarchive an object like so
image = aDecoder.decodeObject(forKey: "image") as! PFFile
it keeps crashing with the error below! Any idea what's going on?

*** 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

This is my NPAd class

class NPAd: PFObject, NSCoding {
    @NSManaged var type: String
    @NSManaged var keywords: [String]?
    @NSManaged var isPrioritizedUntil: Date?
    @NSManaged var text: String? // if type is post
    @NSManaged var image: PFFile
    @NSManaged var imageDimensions: [String: CGFloat]
    @NSManaged var link: String
    @NSManaged var brandName: String
    @NSManaged var brandIcon: PFFile
    
    override init() {
        super.init()
    }
    
    func encode(with aCoder: NSCoder) {
        aCoder.encode(objectId, forKey: "objectId")
        aCoder.encode(type, forKey: "type")
        
        if let isPrioritizedUntil = isPrioritizedUntil {
            aCoder.encode(isPrioritizedUntil, forKey: "isPrioritizedUntil")
        }
        
        if let text = text {
            aCoder.encode(text, forKey: "text")
        }
        
        if let keywords = keywords {
            aCoder.encode(keywords, forKey: "keywords")
        }
        
        aCoder.encode(image, forKey: "image")
        aCoder.encode(imageDimensions, forKey: "imageDimensions")
        aCoder.encode(link, forKey: "link")
        aCoder.encode(brandName, forKey: "brandName")
        aCoder.encode(brandIcon, forKey: "brandIcon")
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(className: "Ad")
        
        objectId = aDecoder.decodeObject(forKey: "objectId") as? String
        type = aDecoder.decodeObject(forKey: "type") as! String
        keywords = aDecoder.decodeObject(forKey: "keywords") as? [String]
        isPrioritizedUntil = aDecoder.decodeObject(forKey: "isPrioritizedUntil") as? Date
        text = aDecoder.decodeObject(forKey: "text") as? String
        image = aDecoder.decodeObject(forKey: "image") as! PFFile
        imageDimensions = aDecoder.decodeObject(forKey: "imageDimensions") as! [String: CGFloat]
        link = aDecoder.decodeObject(forKey: "link") as! String
        brandName = aDecoder.decodeObject(forKey: "brandName") as! String
        brandIcon = aDecoder.decodeObject(forKey: "brandIcon") as! PFFile
    }
}
@Samigos
Copy link
Author

Samigos commented Sep 20, 2019

With further examination I realized that whenever the decoder tries to decode the data, it finds null.

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not save file data for 309c4db5f6e623ba0286ac891017322d_62237520_372569220283311_350326562345713664_n.jpg : Error Domain=NSCocoaErrorDomain Code=4 "Cannot create a PFFileObject with nil data." UserInfo={NSLocalizedDescription=Cannot create a PFFileObject with nil data.}'

@Samigos
Copy link
Author

Samigos commented Sep 20, 2019

Not sure what I changed but the data doesn't seem to be an issue anymore... now this is what I get:

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<PFFileObject 0x600000b05470> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key _url.'

@Samigos
Copy link
Author

Samigos commented Sep 23, 2019

Anyone here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant