1 Reply
      Latest reply on Apr 5, 2020 8:27 PM by mvlad7402
      chps67 Level 1 Level 1 (0 points)

        Hi all,

        I'm having trouble in trying to access the content of a sprite kit particle file in a way that conforms with the recent deprecation of several functions in NSKeyedArchiver.

        Briefly, my project contains a file named "ParticleSmoke.sks", which I used to access easily with the following lines of code:

         

             NSString *smokePath = [[NSBundle mainBundle] pathForResource:@"ParticleSmoke" ofType:@"sks"];

             SKEmitterNode* smoke = [NSKeyedUnarchiver unarchiveObjectWithFile:smokePath];

         

        now that the unarchiving function has been deprecated, I fail to use the (poorly documented)  unarchivedObjectOfClass function. Especially, the code below returns nil.

         

             NSString *smokePath = [[NSBundle mainBundle] pathForResource:@"ParticleSmoke" ofType:@"sks"];

             NSData* smokeData = [NSData dataWithContentsOfFile:smokePath];

             NSError* error=nil;

             Class cls = [SKEmitterNode class];

             SKEmitterNode* smoke = (SKEmitterNode*)[NSKeyedUnarchiver unarchivedObjectOfClass:cls fromData:smokeData error:&error];

         

        Unexpectedly, the content of "error" (code 4864) was

        @"NSDebugDescription" : @"value for key 'NS.objects' was of unexpected class 'NSColor'. Allowed classes are '{(\n    SKKeyframeSequence,\n    NSArray,\n    NSNumber,\n    NSMutableArray\n)}'."

         

        Has anyone an idea to fix this issue?

        Thanks for your help....

        • Re: Failure to unarchive a sprite kit particle file
          mvlad7402 Level 1 Level 1 (0 points)

          The folowing seems to work:

          SKEmitterNode * ret = [NSKeyedUnarchiver unarchivedObjectOfClass:[NSObject class]  fromData: fileData error:&error];

           

          Although security need adjustment:

          2020-04-05 23:24:54.181975-0400 xxxx[82301:1899459] [general] NSSecureCoding allowed classes list contains [NSObject class], which bypasses security by allowing any Objective-C class to be implicitly decoded. Consider reducing the scope of allowed classes during decoding by listing only the classes you expect to decode, or a more specific base class than NSObject.

          2020-04-05 23:24:54.186331-0400 xxxx[82301:1899459] Data has loaded successfully - Projecti