make userData retain so that transient objects don't get referenced after getting dealloc'd. Fix RKParams serialization to handle arrays

This commit is contained in:
jeremy@twotoasters.com
2010-03-09 17:10:45 -05:00
parent a5aef014e2
commit 6a8bfcb8f3
3 changed files with 30 additions and 9 deletions

View File

@@ -274,7 +274,9 @@ static const NSString* kRKModelMapperRailsDateFormatString = @"MM/dd/yyyy";
NSMutableSet* children = [NSMutableSet setWithCapacity:[relationshipElements count]];
for (NSDictionary* childElements in relationshipElements) {
id child = [self createOrUpdateInstanceOfModelClass:class fromElements:childElements];
[children addObject:child];
if (child) {
[children addObject:child];
}
}
[object setValue:children forKey:propertyName];

View File

@@ -94,14 +94,33 @@ static NSString* kRKStringBoundary = @"0xKhTmLbOuNdArY";
int i = 0;
for (id key in _valueData) {
id value = [_valueData valueForKey:key];
NSLog(@"Attempting to add HTTP param named %@ with type %@ and value %@", key, [value class], value);
[HTTPBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key] dataUsingEncoding:NSUTF8StringEncoding]];
// TODO: Can get _PFCachedNumber objects back from valueForKey: from Core Data. Need to figure this out...
if ([value respondsToSelector:@selector(dataUsingEncoding:)]) {
[HTTPBody appendData:[value dataUsingEncoding:NSUTF8StringEncoding]];
if ([value isKindOfClass:[NSArray class]]) {
int j = 0;
for (id object in (NSArray*)value) {
NSString* arrayKey = [NSString stringWithFormat:@"%@[]", key];
NSLog(@"Attempting to add HTTP param named %@ with type %@ and value %@", arrayKey, [object class], object);
[HTTPBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", arrayKey] dataUsingEncoding:NSUTF8StringEncoding]];
// TODO: Can get _PFCachedNumber objects back from valueForKey: from Core Data. Need to figure this out...
if ([object respondsToSelector:@selector(dataUsingEncoding:)]) {
[HTTPBody appendData:[object dataUsingEncoding:NSUTF8StringEncoding]];
} else {
[HTTPBody appendData:[[NSString stringWithFormat:@"%@", object] dataUsingEncoding:NSUTF8StringEncoding]];
}
j++;
if (j != [value count]) {
[HTTPBody appendData:[self endItemBoundary]];
}
}
} else {
[HTTPBody appendData:[[NSString stringWithFormat:@"%@", value] dataUsingEncoding:NSUTF8StringEncoding]];
}
NSLog(@"Attempting to add HTTP param named %@ with type %@ and value %@", key, [value class], value);
[HTTPBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key] dataUsingEncoding:NSUTF8StringEncoding]];
// TODO: Can get _PFCachedNumber objects back from valueForKey: from Core Data. Need to figure this out...
if ([value respondsToSelector:@selector(dataUsingEncoding:)]) {
[HTTPBody appendData:[value dataUsingEncoding:NSUTF8StringEncoding]];
} else {
[HTTPBody appendData:[[NSString stringWithFormat:@"%@", value] dataUsingEncoding:NSUTF8StringEncoding]];
}
}
i++;
// Only add the boundary if this is not the last item in the post body

View File

@@ -55,7 +55,7 @@
/**
* An opaque pointer to associate user defined data with the request.
*/
@property(nonatomic, assign) id userData;
@property(nonatomic, retain) id userData;
/**
* A Dictionary of additional HTTP Headers to send with the request