Coder Social home page Coder Social logo

parse-nscoding's Introduction

Parse-NSCoding

This library adds NSCoding support to instances or subclasses of PFObject and PFUser so that they can be serialized and deserialized (for custom caching, for example). All properties will be serialized, including Parse properties (those marked @dynamic), as well as non-Parse properties (those marked @synthesize). This library also serializes the related PFACL and PFFile classes. If your PFFile object contains NSData (isDataAvailable == YES), that too will be serialized.

##Sample Usage

Just install this library in your project. That's it. No header files to import! The Objective-C runtime will automatically send NSCoding messages to your Parse objects when you attempt to serialize them, and the category methods in this library will be invoked.

##Installation

Easiest installation is using CocoaPods:

pod 'Parse+NSCoding', '~> 0.1.4'

Otherwise you must manually copy the .h and .m files from this repo. Obviously you must also have the Parse SDK installed. Enjoy!

##Credits

Much of the code in this library came from:

https://parse.com/questions/persistent-store-of-pfobject-pffile

https://github.com/greenisus/NSObject-NSCoding

parse-nscoding's People

Contributors

eladb avatar martinrybak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

parse-nscoding's Issues

Loaded PFObject with NSCoding are not marked as dirty

Hello,
I'm trying to use Parse-NSCoding to implement a local storage functionality in my Parse iOS project, and I try to sync the data at launch:

  • I load PFObjects from NSUserDefaults
  • I load PFObjects from parse
  • I compare & update

I have an issue when I delete a PFObject from parse (for example with another device of the same user, or with a webapp):

  • I load the object from NSUserDefaults
  • I found nothing in Parse
  • I want to save it again in Parse, but I can't because the PFObject loaded from NSUserDefaults is not marked as Dirty... so Parse considered it to be already saved...

Do you think a PFObject created through NSUserDefaults loading should be dirty or not?

Thanks

Unrecognized Selector

I installed your framework using cocoa pods and for some reason I think my project isn't recognizing it because it's throwing the unrecognized selector on [PFObject encodeWithCoder:] so that means that my project isn't recognizing your extension. I've tried deleting it and re-install the pod again but no luck. Any suggestions?

Issues with PFFile(NSCoding) after updating to Parse iOS SDK v1.2.19

Since I updated the Parse iOS SDK to v1.2.19 and the Facebook iOS SDK to v3.13.1 I'm getting exceptions thrown when NSCoding PFFiles. Based on the change log for Parse they fixed a memory leak in this release ... any chance that might be the cause?

Here's the exception I get:

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

And here's the traceback:

*** First throw call stack:
(
    0   CoreFoundation                      0x039531e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x0352d8e5 objc_exception_throw + 44
    2   CoreFoundation                      0x039e2fe1 -[NSException raise] + 17
    3   Foundation                          0x0162cd9e -[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
    4   Foundation                          0x015991d7 _NSSetUsingKeyValueSetter + 88
    5   Foundation                          0x01598731 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
    6   Pesi                                0x001ed8ce -[PFFile(NSCoding) initWithCoder:] + 686
    7   Foundation                          0x0157f01a _decodeObjectBinary + 3498
    8   Foundation                          0x0157e106 _decodeObject + 340
    9   Foundation                          0x0157dfaa -[NSKeyedUnarchiver decodeObjectForKey:] + 181
    10  Pesi                                0x001ee610 -[PFObject(NSCoding) initWithCoder:] + 1024
    11  Foundation                          0x0157f01a _decodeObjectBinary + 3498
    12  Foundation                          0x0157e106 _decodeObject + 340
    13  Foundation                          0x0157dfaa -[NSKeyedUnarchiver decodeObjectForKey:] + 181
    14  Pesi                                0x001ee610 -[PFObject(NSCoding) initWithCoder:] + 1024
    15  Foundation                          0x0157f01a _decodeObjectBinary + 3498
    16  Foundation                          0x015804d7 -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:] + 2204
    17  Foundation                          0x01580746 -[NSArray(NSArray) initWithCoder:] + 255
    18  Foundation                          0x0157f01a _decodeObjectBinary + 3498
    19  Foundation                          0x015804d7 -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:] + 2204
    20  Foundation                          0x0158cff1 -[NSDictionary(NSDictionary) initWithCoder:] + 261
    21  Foundation                          0x0157f01a _decodeObjectBinary + 3498
    22  Foundation                          0x0157e106 _decodeObject + 340
    23  Foundation                          0x0157dfaa -[NSKeyedUnarchiver decodeObjectForKey:] + 181
    24  Foundation                          0x0155a6c4 +[NSKeyedUnarchiver unarchiveObjectWithFile:] + 173
    25  Pesi                                0x002118df __34-[TMDiskCache objectForKey:block:]_block_invoke + 335
    26  libdispatch.dylib                   0x03c527b8 _dispatch_call_block_and_release + 15
    27  libdispatch.dylib                   0x03c674d0 _dispatch_client_callout + 14
    28  libdispatch.dylib                   0x03c55047 _dispatch_queue_drain + 452
    29  libdispatch.dylib                   0x03c54e42 _dispatch_queue_invoke + 128
    30  libdispatch.dylib                   0x03c55de2 _dispatch_root_queue_drain + 78
    31  libdispatch.dylib                   0x03c56127 _dispatch_worker_thread2 + 39
    32  libsystem_pthread.dylib             0x03f96dab _pthread_wqthread + 336
    33  libsystem_pthread.dylib             0x03f9acce start_wqthread + 30
)

Getting Error When Trying To Store PFObjects in Core Data

I keep getting this error when trying to set PFObjects inside my NSManagedObject:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSObject encodeWithCoder:]: unrecognized selector sent to instance 0x1702151d0'

I have added the CocoaPod to my project, but clearly my PFObjects aren't serializing.

Anyone have a reason as to why this could be happening?

Linker warnings with latest Parse SDK (1.6.2)

I get linker errors when using the library alongside the latest Parse SDK (1.6.2)

ld: warning: instance method 'initWithCoder:' in category from .../libPods-Parse+NSCoding.a(PFACL+NSCoding.o) overrides method from class in .../Pods/Parse/Parse.framework/Parse(PFACL.o)
ld: warning: instance method 'encodeWithCoder:' in category from .../libPods-Parse+NSCoding.a(PFACL+NSCoding.o) overrides method from class in .../Pods/Parse/Parse.framework/Parse(PFACL.o)

Are there any plans to bring this library up to date?
Has anyone forked it and done that?

Add support for PFGeoPoint+NSCoding

Hi,

I include "pod 'Parse+NSCoding', '~> 0.1.3'" in podfile and execute "pod install" but not appears in the project the PFGeoPoint+NSCoding files.

I hope that someone make me a solution

Thanx!!!

NSCoding PFFile

I am trying to encode a PFObject and a PFFile to the disk.However,I get this error after running the code.
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<PFFile 0x7fc1626b02a0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key _url.
My PFFile could not be saved eventhough it saves the file's url.How to solve this?

PFRelation

Have you been able to get this working if one of the PFObjects has a PFRelation associated with it? I wrote a simple PFRelation+NSCoding category to serialize the targetClass property, but when the -initWithCoder: tries to deserialize the PFRelation and set it I get an exception:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'PFObject values may not have class: PFRelation'

Pod installs frameworks I already have installed

I already have the FB/Bolts/Parse trio of frameworks installed in my project but when I install this pod it doesn't see them and installs duplicates in "${PODS_ROOT}/ and this causes all hell to break loose with duplicate symbols.

Issue with Saving PFFile data

See the attached pictures for details. It runs two breakpoints and then crashes my app. It doesn't print out a stack trace, it just crashes.

screen shot 2014-06-21 at 9 12 50 pm
screen shot 2014-06-21 at 9 13 02 pm

Encoding non parse properties causes a problem

Hi, great job on this and the caching framework. I have a problem however that I need some explanation about. Why is is that non-parse properties are serialized? This doesn't seem right (at least for the purpose of caching subclasses of PFObject). The problem is this, if you register your own sub class of PFObject, and it has some read-only properties (which are usually calculated) these may cause problems.

Assume class A and class B, both subclasses of PFObject. A refers to B, B has a read only property that calculates a value based on a PFObject field. However, when A was loaded, it only loads a pointer to B, and not all of B's fields. When the PFObject+NSCoding tries to encode A, it transitively encodes B, including B's non Parse fields. This means that the readonly property method is called, which tries to read a field that was not loaded and fails with Parse library saying that the field needs to be loaded first.

I worked around this by commenting out the following two lines of PFObject_NSCoding (line 87):

    //Deserialize all non-Parse properties
    NSDictionary* nonParseProperties = [self nonDynamicProperties];
    [self decodeProperties:nonParseProperties withCoder:aDecoder];

It seems that we need a way to turn off serialization of Non-Parse fields, or indicate a property (especially read-only ones) should not be serialized. I'm happy to work on a solution for this, but first I wanted to fully understand the motivation to start with for serializing non-parse fields. My best guess is that PFObject+NSCoding is designed to be a generic serialization mechanism. In all cases, it doesn't make sense to serialize read-only properties since trying to restore them later could only fail.

Please let me know your thoughts.

Depend on Parse 1.4.0 pod

Parse-iOS-SDK pod has been deprecated in favour of Parse. See CocoaPods/Specs#11294.

Please update when convenient!

Parse warning

When using this library I get the following in the output:

Warning: A long-running Parse operation is being executed on the main thread. Break on warnParseOperationOnMainThread() to debug.

Any idea what this is about?

Tries to install Parse-iOS-SDK not Parse

screen shot 2016-07-15 at 9 22 43 am

This seems to cause conflicts. Should this be installed with Parse or does it already include Parse? Also if so, would it include the latest version Parse 1.14.0?

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

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

Use right pod in deps

$ pod outdated
The following updates are available:
- Parse-iOS-SDK 1.2.21 -> 1.3.0
The following pods are deprecated:
- Parse-iOS-SDK (in favor of Parse)

isDataAvailable not responding correctly?

Hi-

First off, thank you for a great library. I'm testing it in a project where I would like to cache a large number of reference objects to disk for later use. Everything seems to be working great, however objects that have been decoded do not return isDataAvailable == YES. This causes some issues in my app and I'm wondering if you've run into this? Is this value not being encoded with the PFObjects?

thank you,
Drew

NSUnknownKeyException [<NSCache 0x10f305700> valueForUndefinedKey:]

I'm trying to save and return a cached (NSCache) subclassed PFObject called Transfer. When storing it (to debug this) I'm trying to fetch it from the cache right after to no avail, like this:

Transfer *transfer = subclassedPFObject;
NSLog(@"Transfer: %@", transfer);
[self.cache setObject:transfer forKey:[NSString stringWithFormat:@"transfer_%@", [transfer objectId]]];
NSLog(@"Cached: %@", [self.cache valueForKey:[NSString stringWithFormat:@"transfer_%@", [transfer objectId]]]);

It saves the cache OK, and I can verify that PFObject+NSCoding is being used to serialize the object. But when I try to return it from the cache, I get this error:

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSCache 0x10f305700> valueForUndefinedKey:]: this class is not key value coding-compliant for the key transfer_eCEyjTqJUc.'

Here's how the object looks like when it gets saved to the cache:

Transfer: <Transfer:eCEyjTqJUc:(null)> {
    amount = 567;
    completedAt = "2014-03-27 06:15:21 +0000";
    from = "<PFUser:SoM3IdF0rUs3R>";
    isCharge = 0;
    isComplete = 1;
    likes =     (
        SoM3IdF0rUs3R
    );
    reason = Some text;
    to = "<PFUser:SoM3IdF0rUs3R>";
}

It doesn't seem to be firing (id)initWithCoder:(NSCoder*)aDecoder at all when fetching the object from the cache. It seems to be failing before it even reaches that method.

Am I missing something here? Any clues as to why it isn't able to fetch the object from the cache?

PS. Thanks for an awesome pod!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.