Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #6 from gwk/master

arrayFromJSONWithError: plus small fixes for Mac
  • Loading branch information...
commit 305a5f4c994ead35166b662947d506e25ab52013 2 parents 53ed137 + ed3ac84
@adamalix authored
View
BIN  FSNDemo-iOS/Default-568h@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
7 FSNDemo-iOS/FSNDemo-iOS.xcodeproj/project.pbxproj
@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
+ EC197DE9167FB04300AFFE5F /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = EC197DE8167FB04300AFFE5F /* Default-568h@2x.png */; };
EC35031815A358BE0044F27F /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = EC35031215A358BE0044F27F /* AppDelegate.m */; };
EC35031915A358BE0044F27F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = EC35031415A358BE0044F27F /* main.m */; };
EC35031A15A358BE0044F27F /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = EC35031615A358BE0044F27F /* ViewController.m */; };
@@ -20,6 +21,7 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
+ EC197DE8167FB04300AFFE5F /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
EC2B34B715AE409100292F41 /* FSNDemo-iOS-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FSNDemo-iOS-Prefix.pch"; sourceTree = "<group>"; };
EC35031115A358BE0044F27F /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
EC35031215A358BE0044F27F /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
@@ -83,6 +85,7 @@
EC76F55F15A1EFD100EBDC76 = {
isa = PBXGroup;
children = (
+ EC197DE8167FB04300AFFE5F /* Default-568h@2x.png */,
EC35030B15A358A10044F27F /* FSNDemo-iOS */,
ECF5C3DE15A36F43009D4013 /* license.txt */,
ECF5C3DF15A36F43009D4013 /* README.md */,
@@ -175,6 +178,7 @@
buildActionMask = 2147483647;
files = (
EC35031B15A358BE0044F27F /* ViewController.xib in Resources */,
+ EC197DE9167FB04300AFFE5F /* Default-568h@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -202,7 +206,6 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
- "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: George King (GM8K932DTT)";
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
@@ -217,7 +220,6 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 5.1;
- "PROVISIONING_PROFILE[sdk=iphoneos*]" = "8CBDAF7F-F863-4FDA-98C8-189BFE49DAC6";
SDKROOT = iphoneos;
};
name = Debug;
@@ -227,7 +229,6 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
- "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_VERSION = "";
View
10 FSNDemo-mac/FSNDemo-mac.xcodeproj/project.pbxproj
@@ -126,7 +126,7 @@
EC1FD47815B44F8A00A26A2F /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 0430;
+ LastUpgradeCheck = 0460;
ORGANIZATIONNAME = "Foursquare Labs, Inc";
};
buildConfigurationList = EC1FD47B15B44F8A00A26A2F /* Build configuration list for PBXProject "FSNDemo-mac" */;
@@ -167,6 +167,10 @@
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
@@ -194,6 +198,10 @@
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_C_LANGUAGE_STANDARD = gnu99;
View
4 src/FSNConnection.m
@@ -365,10 +365,12 @@ - (void)setMethod:(FSNRequestMethod)method {
}
+#if TARGET_OS_IPHONE
- (void)setShouldRunInBackground:(BOOL)shouldRunInBackground {
ASSERT_UNSTARTED;
_shouldRunInBackground = shouldRunInBackground;
}
+#endif
- (void)setHeaders:(NSDictionary *)headers {
@@ -801,7 +803,7 @@ - (NSURLRequest*)makeNSURLRequest {
contentType = @"application/x-www-form-urlencoded";
}
- NSString *contentLength = [NSString stringWithFormat:@"%u", body.length];
+ NSString *contentLength = [NSString stringWithFormat:@"%lu", (unsigned long)body.length];
SET_HEADER(@"Content-Type", contentType);
SET_HEADER(@"Content-Length", contentLength);
View
4 src/FSNData.m
@@ -34,8 +34,8 @@ @implementation FSNData
- (id)description {
NSString *fn = self.fileName ? [NSString stringWithFormat:@"; fileName=%@", self.fileName] : @"";
- return [NSString stringWithFormat:@"<FSNData: %p; data: %p; length: %u; mimeType: %@%@>",
- self, _data, _data.length, self.mimeTypeString, fn];
+ return [NSString stringWithFormat:@"<FSNData: %p; data: %p; length: %lu; mimeType: %@%@>",
+ self, _data, (unsigned long)_data.length, self.mimeTypeString, fn];
}
View
9 src/FSN_categories.h
@@ -181,8 +181,9 @@ BOOL httpCodeIsOfClass(int httpCode, FSNHTTPCodeClass httpClass);
@interface NSData (FSN)
-// convenience method to ensure that top-level json object is a dictionary
+// convenience methods to ensure that top-level json objects are of the expected container type
- (id)dictionaryFromJSONWithError:(NSError **)error; // error pointer must not be nil
+- (id)arrayFromJSONWithError:(NSError **)error; // error pointer must not be nil
- (NSString *)stringFromUTF8;
@@ -212,6 +213,12 @@ BOOL httpCodeIsOfClass(int httpCode, FSNHTTPCodeClass httpClass);
@end
+@interface NSNumber (FSN)
+
+- (NSString*)urlEncodedString; // just returns stringValue
+
+@end
+
@interface NSURLResponse (FSN)
View
75 src/FSN_categories.m
@@ -22,37 +22,32 @@ BOOL httpCodeIsOfClass(int httpCode, FSNHTTPCodeClass httpClass) {
@implementation NSDictionary (FSN)
-- (NSString *)urlQueryString {
+BOOL isValueAcceptable(id val) {
+ static NSArray* acceptableValueClasses = nil;
+ if (!acceptableValueClasses) {
+ acceptableValueClasses = @[[NSArray class], [NSNumber class], [NSString class]];
+ }
+ for (Class klass in acceptableValueClasses) {
+ if ([val isKindOfClass:klass])
+ return YES;
+ }
+ return NO;
+};
+
+- (NSString *)urlQueryString {
NSMutableString *string = [NSMutableString string];
BOOL first = YES;
- NSArray *acceptableValueClasses = @[[NSArray class],
- [NSNumber class],
- [NSString class]];
-
- BOOL (^isValueAcceptable)(id) = ^(id val) {
- for (Class klass in acceptableValueClasses) {
- if ([val isKindOfClass:klass])
- return YES;
- }
- return NO;
- };
for (id key in self) {
id val = [self objectForKey:key];
-
if (![key isKindOfClass:[NSString class]] || !isValueAcceptable(val)) {
FSNLogError(@"skipping bad parameter: key class: %@ key: %@; value class: %@; value: %@",
[key class], key, [val class], val);
NSAssert(0, @"bad parameter type");
continue;
}
-
- [string appendFormat:@"%@%@=%@",
- (first ? @"" : @"&"),
- [key urlEncodedString],
- [([val isKindOfClass:[NSNumber class]] ? [val stringValue] : val) urlEncodedString]];
-
+ [string appendFormat:@"%@%@=%@", (first ? @"" : @"&"), [key urlEncodedString], [val urlEncodedString]];
first = NO;
}
return string;
@@ -92,6 +87,34 @@ - (id)dictionaryFromJSONWithError:(NSError **)error {
}
+- (id)arrayFromJSONWithError:(NSError **)error {
+
+ NSAssert(error, @"nil error pointer");
+
+ NSDictionary *array = [NSJSONSerialization JSONObjectWithData:self options:0 error:error];
+
+ if (*error) {
+ return nil;
+ }
+
+ if (![array isKindOfClass:[NSArray class]]) {
+ NSDictionary* userInfo =
+ [NSDictionary dictionaryWithObjectsAndKeys:
+ [NSString stringWithFormat:@"JSON result is not an array; type: %@", [array class]], @"description",
+ array, @"result",
+ nil];
+
+ *error =
+ [NSError errorWithDomain:FSNConnectionErrorDomain code:FSNConnectionErrorCodeJSONResultType userInfo:userInfo];
+
+ return nil;
+ }
+
+ *error = nil;
+ return array;
+}
+
+
- (NSString *)stringFromUTF8 {
return [NSString withUTF8Data:self];
}
@@ -170,6 +193,20 @@ - (NSData *)UTF8Data {
@end
+
+
+@implementation NSNumber (FSN)
+
+
+- (NSString *)urlEncodedString {
+ return self.stringValue;
+}
+
+
+@end
+
+
+
@implementation NSURLResponse (FSN)
Please sign in to comment.
Something went wrong with that request. Please try again.