0

I added a column location of Object type in _User class. I'm assuming that means NSData type in iOS. Not exactly sure what's the correct way of doing this. I'm getting an error when assigning an NSData to self.location. Any help is greatly appreciated.

Error Domain=Parse Code=111 "invalid type for key location, expected map, but got bytes" UserInfo=0x1740f9a00 {code=111, originalError=Error Domain=NSURLErrorDomain Code=-1011 "The operation couldn’t be completed. (NSURLErrorDomain error -1011.)", temporary=0, error=invalid type for key location, expected map, but got bytes, NSLocalizedDescription=invalid type for key location, expected map, but got bytes}

BYFUser.h

#import <Parse/Parse.h>

@interface BYFUser : PFUser <PFSubclassing>

@property (nonatomic, strong) NSData *location;

@property (nonatomic, strong) CLLocation *cllocation;

@end

BYFUser.m

@implementation BYFUser

@dynamic location;

+ (void)load
{
    [BYFUser registerSubclass];
}

- (void)setCllocation:(CLLocation *)cllocation
{
    if ([cllocation isKindOfClass:[CLLocation class]]) {
        self.location = [NSKeyedArchiver archivedDataWithRootObject:cllocation];
    }
}

- (CLLocation *)cllocation
{
    if ([self.location isKindOfClass:[NSData class]]) {
        return [NSKeyedUnarchiver unarchiveObjectWithData:self.location];
    }
    return nil;
}

@end
docchang
  • 1,115
  • 15
  • 32

1 Answers1

0

Make the column a geopoint type and access it from iOS using the PFGeoPoint class. PFGeoPoint can be instantiated with a CLLocation.

danh
  • 62,181
  • 10
  • 95
  • 136
  • I'm aware of the PFGeoPoint data type, but I'm more interested in finding out how to saving other data types. E.g. NSData? – docchang Jun 04 '15 at 02:51
  • NSData needs to be converted to a transmittable format to use over the network and on parse. Probably the most straight forward would be to encode as UTF8 string to save, and do the reverse when getting the data back. NSData only makes sense in the context of the client. – danh Jun 04 '15 at 03:53
  • Is there a way to save NSData bytes to parse? – docchang Jun 05 '15 at 07:52
  • Yes. A few, but the best way depends on what the NSData represents. What's in the data, and roughly how big is it? – danh Jun 05 '15 at 15:24
  • I converted the CLLocation to NSData and i have a zipped data size of 585 bytes – docchang Jun 05 '15 at 19:40