hivesolutions / cameo Goto Github PK
View Code? Open in Web Editor NEWA generic framework for iOS interaction
Home Page: http://cameo.hive.pt
License: Apache License 2.0
A generic framework for iOS interaction
Home Page: http://cameo.hive.pt
License: Apache License 2.0
Here's an example on how caching is configured in AFNetworking:
AFHTTPRequestOperationManager *manager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:baseUrl];
client.requestSerializer = AFHTTPRequestSerializer.serializer;
client.requestSerializer.cachePolicy = NSURLRequestReturnCacheDataElseLoad;
Need a way to perform actions right after an image is loaded with the setImageWithURL method in the ImageView category (for example: fading in an image right after it's loaded). There's currently no callback support, here is the link to the current category implementation: https://github.com/hivesolutions/cameo/blob/master/src/classes/UIImageView%2BHMImageViewUtil.m
When a key exists in the json map and not in the object, the HMJSONSerializer crashes. Here is a sample error:
'NSUnknownKeyException', reason: '[<Bagger.Category 0x7f9612490130> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key image_url.'
The expected behaviour would be to fail silently and just ignore that attribute (the server may send a lot of values but we may only care about a subset of them).
The only types of request I have available are HMJsonRequest
and HMProxyRequest
, and neither of these work for retrieving an image.
Need a method that merges the contents of one dictionary into another recursively. This would be a category of NSDictionary.
- (NSMutableDictionary *)mergedWithDictionary:(NSDictionary *)dictionary1 {
// creates a mutable copy of the dictionary
// into which the contents are going to be merged
// (otherwise the dictionary may not be editable)
NSMutableDictionary *dictionary2 = self.mutableCopy;
// merges each entry of the dictionary
for(NSString *key in dictionary1) {
// retrieves the values from both
// dictionaries for the current key
id value1 = dictionary1[key];
id value2 = dictionary2[key];
// in case both dictionary values are dictionaries
// then calls this method recursively to merge them
BOOL isValue1Dict = [value1 isKindOfClass:NSDictionary.class];
BOOL isValue2Dict = value2 != nil && [value2 isKindOfClass:NSDictionary.class];
if(isValue1Dict && isValue2Dict) {
dictionary2[key] = [value2 mergeDictionary:value1];
}
// otherwise assigns the first dictionary's
// value into the second dictionary
else {
dictionary2[key] = value1;
}
}
// returns the merged dictionary
return dictionary2;
}
The callback for retrieval methods has a "response" and an "error" variable. When the response serializer fails (in this case the json serializer), the error is not forwarded to the callback, and the handling code is faced with an unexpected situation where there is no error but there's also no response (in this case it was causing a code crash). I think the error should be forwarded to the callback, otherwise I would have to do two different tests for errors instead of having a unified way of doing so.
Here is the culprit in HMJsonSerializer, notice that it's not returning the error:
- (id)loads:(NSData *)data error:(NSError *)error {
id object = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:&error];
if (error == nil && self.mapper) {
object = [self map:object error:error];
}
return object;
}
Currently images can bet set like this for example:
[self.imageView_ setImageWithURLString:product.imageUrl proxy:BaggerAPI.singleton.proxy];
There should be a method signature that doesn't require passing the proxy as an argument.
It would be very helpful to be able to specify which class one wants to have a json response applied to, and have the request methods returns instances of that class instead. For example, if the response was this:
[
{
"name" : "test1",
"price" : 10
},
{
"name" : "test2",
"price" : 20
}
]
If I told the method that I wanted that data applied to "Product.class", then I would receive two instances of that class with those values applied to them.
It's sometimes helpful to be able to programatically retrieve a dark or a lighter version of a color. These are good candidates for category methods. Here is an example:
- (UIColor *)lighterByPercentage:(CGFloat)percentage {
CGFloat red, green, blue, alpha;
[color getRed:&red green:&green blue:&blue alpha:&alpha];
red = MIN(red + percentage, 1.0);
green = MIN(green + percentage, 1.0);
blue = MIN(blue + percentage, 1.0);
return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}
- (UIColor *)darkerByPercentage:(CGFloat)percentage {
CGFloat red, green, blue, alpha;
[color getRed:&red green:&green blue:&blue alpha:&alpha];
red = MAX(red - percentage, 0.0);
green = MAX(green - percentage, 0.0);
blue = MAX(blue - percentage, 0.0);
return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}
A GET request of a big image with the HMDataSerializer causes a delay on the main thread before invoking the callback.
[self.proxy get:url
parameters:params
useSession:YES
serializer:HMDataSerializer.singleton
callback:^(NSData *response, NSError *error) {
UIImage *image = [UIImage imageWithData:response];
callback(image, error);
}];
HMJsonRequest has the following methods:
โ initWithUrlString:callback:
โ initWithUrlString:parameters:
But it doesn't have a initWithUrlString:parameters:callback method, which forces the user to manually encode the GET parameters in the URL string when he wants to use a callback.
When a request responds with a redirect, the retriever is not following that redirect.
To be able to simplify the process of creating an API client in Objective-C it's relevant to have an abstract class that handles, things like:
The creation of this feature is heavily inspired by the Appier API class.
#import "UIColor+Utils.h"
@implementation UIColor(Utils)
+ (UIColor *)colorWithHex:(NSInteger)hex {
NSInteger red = (hex & 0xFF0000) >> 16;
NSInteger green = (hex & 0xFF00) >> 8;
NSInteger blue = (hex & 0xFF);
UIColor *color = [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:1.0];
return color;
}
- (NSString *)hexString {
CGFloat red, green, blue, alpha;
[self getRed:&red green:&green blue:&blue alpha:&alpha];
NSInteger redI = (NSUInteger)(255.0 * red);
NSInteger greenI = (NSUInteger)(255.0 * green);
NSInteger blueI = (NSUInteger)(255.0 * blue);
NSString *hexString = [NSString stringWithFormat:@"%02lx%02lx%02lx", (long)redI, (long)greenI, (long)blueI];
return hexString;
}
@end
Should be able to know if I'm connected to the internet or not, and what kind of connection I have. Here's AFNetworking's implementation: https://github.com/AFNetworking/AFNetworking/blob/d3391e6618a181a6e1f0b14acf2cb014cc69b121/AFNetworking/AFNetworkReachabilityManager.m
Buttons only support [button setBackgroundImage:forState:]. The following category method can be added to UIButton to solve this:
- (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state {
UIImage *image = [UIImage imageWithColor:backgroundColor];
[self setBackgroundImage:image forState:state];
}
And the following to UIImage:
+ (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0, 0.0, 1.0, 1.0);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Currently the parameters provided to requests only support strings, meaning that I can't send a map like this:
{
"number" : @1
}
A simple way to allow all object datatypes and have them all converted to string is to pass them all through this method:
NSString *parameter = [NSString stringWithFormat:@"%@", parameter];
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.