问题
I have an endpoint message from Google Cloud Endpoint that I would like to persist in iOS Core Data. The endpoint message look like this
.h
#if GTL_BUILT_AS_FRAMEWORK
#import "GTL/GTLObject.h"
#else
#import "GTLObject.h"
#endif
@class GTLFarmercloudendpointChicken;
@class GTLFarmercloudendpointPig;
@class GTLFarmercloudendpointCow;
// ----------------------------------------------------------------------------
//
// GTLFarmercloudendpointFarmer
//
@interface GTLFarmercloudendpointFarmer : GTLObject
@property (retain) NSArray *chickens; // of GTLFarmercloudendpointChicken
@property (retain) NSArray *pigs; // of GTLFarmercloudendpointPig
@property (retain) NSArray *cows; // of GTLFarmercloudendpointCow
@property (copy) NSString *biography;
@property (retain) NSNumber *userid; // longLongValue
@property (copy) NSString *username;
@end
.m
/* This file was generated by the ServiceGenerator.
* The ServiceGenerator is Copyright (c) 2014 Google Inc.
*/
//
// GTLFarmercloudendpointFarmer.m
//
// ----------------------------------------------------------------------------
// NOTE: This file is generated from Google APIs Discovery Service.
// Service:
// Farmercloudendpoint/1
// Description:
// Farmer API
// Classes:
// GTLFarmercloudendpointFarmer (0 custom class methods, 6 custom properties)
#import "GTLFarmercloudendpointFarmer.h"
#import "GTLFarmercloudendpointChicken.h”
#import "GTLFarmercloudendpointCow.h”
#import "GTLFarmercloudendpointPig.h”
// ----------------------------------------------------------------------------
//
// GTLFarmercloudendpointFarmer
//
@implementation GTLFarmercloudendpointFarmer
@dynamic chickens, pigs, cows, biography, userid, username;
+ (NSDictionary *)arrayPropertyToClassMap {
NSDictionary *map =
[NSDictionary dictionaryWithObjectsAndKeys:
[GTLFarmercloudendpointChicken class], @“chickens”,
[GTLFarmercloudendpointPig class], @“pigs”,
[GTLFarmercloudendpointCow class], @“cows”,
nil];
return map;
}
@end
So that well meaning people do not misunderstand the question: these are messages not App-Engine datastore entities. This means: on the server, after I query the datastore (or a sql db, or whatever, really), I create java POJOs (my server is in Java) and these POJOs are sent to the client using Google Cloud Endpoint. So please avoid discussions of Core Data VS datastore as I saw in a similar question here.
On another note: observe that the message classes that Google Cloud Endpoint generate do not extend NSManagedObject
. So a linking converter is missing so that I could persist my endpoint message in Core Data. Other than meticulously creating a linking for each message myself, any ideas how to accomplish this? For example imagine that class GTLFarmercloudendpointCow
may itself contain an NSArray of Eggs. Manually creating a linker becomes daunting very quickly.
A similar problem exists in fact if I try to save the endpoint message as a file: in that case I need a NSCoder coder/encoder for each nested class in the message else I cannot use NSKeyedArchiver.
来源:https://stackoverflow.com/questions/25817671/appengine-cloud-endpoint-messages-and-ios-core-data