Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Cleaned up NSJSONSerialization code

  • Loading branch information...
commit 54ed98aa94925cc4079cae6df35a4e22ed684592 1 parent 55d0d7c
@MugunthKumar authored
View
2  MKNetworkKit-iOS/MKNetworkKit-iOS.xcodeproj/project.pbxproj
@@ -203,7 +203,7 @@
ABB5C253148B3AE00056D3E9 /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 0430;
+ LastUpgradeCheck = 0450;
ORGANIZATIONNAME = Steinlogic;
};
buildConfigurationList = ABB5C256148B3AE00056D3E9 /* Build configuration list for PBXProject "MKNetworkKit-iOS" */;
View
75 MKNetworkKit/Categories/NSDictionary+RequestEncoding.m
@@ -28,57 +28,52 @@
@implementation NSDictionary (RequestEncoding)
-(NSString*) urlEncodedKeyValueString {
+
+ NSMutableString *string = [NSMutableString string];
+ for (NSString *key in self) {
- NSMutableString *string = [NSMutableString string];
- for (NSString *key in self) {
-
- NSObject *value = [self valueForKey:key];
- if([value isKindOfClass:[NSString class]])
- [string appendFormat:@"%@=%@&", [key urlEncodedString], [((NSString*)value) urlEncodedString]];
- else
- [string appendFormat:@"%@=%@&", [key urlEncodedString], value];
- }
-
- if([string length] > 0)
- [string deleteCharactersInRange:NSMakeRange([string length] - 1, 1)];
-
- return string;
+ NSObject *value = [self valueForKey:key];
+ if([value isKindOfClass:[NSString class]])
+ [string appendFormat:@"%@=%@&", [key urlEncodedString], [((NSString*)value) urlEncodedString]];
+ else
+ [string appendFormat:@"%@=%@&", [key urlEncodedString], value];
+ }
+
+ if([string length] > 0)
+ [string deleteCharactersInRange:NSMakeRange([string length] - 1, 1)];
+
+ return string;
}
-(NSString*) jsonEncodedKeyValueString {
-
-#if __IPHONE_OS_VERSION_MAX_ALLOWED < 50000
- if(NSClassFromString(@"NSJSONSerialization")) {
- NSError *error = nil;
- NSData *data = [NSJSONSerialization dataWithJSONObject:self
- options:0 // non-pretty printing
- error:&error];
- if(error)
- DLog(@"JSON Parsing Error: %@", error);
-
- return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- } else {
- DLog(@"JSON encoder missing, falling back to URL encoding");
- return [self urlEncodedKeyValueString];
- }
-#else
+
+ if(NSClassFromString(@"NSJSONSerialization")) {
+ NSError *error = nil;
+ NSData *data = [NSClassFromString(@"NSJSONSerialization") dataWithJSONObject:self
+ options:0 // non-pretty printing
+ error:&error];
+ if(error)
+ DLog(@"JSON Parsing Error: %@", error);
+
+ return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
+ } else {
DLog(@"JSON encoder missing, falling back to URL encoding");
return [self urlEncodedKeyValueString];
-#endif
+ }
}
-(NSString*) plistEncodedKeyValueString {
-
- NSError *error = nil;
- NSData *data = [NSPropertyListSerialization dataWithPropertyList:self
- format:NSPropertyListXMLFormat_v1_0
- options:0 error:&error];
- if(error)
- DLog(@"JSON Parsing Error: %@", error);
-
- return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
+
+ NSError *error = nil;
+ NSData *data = [NSPropertyListSerialization dataWithPropertyList:self
+ format:NSPropertyListXMLFormat_v1_0
+ options:0 error:&error];
+ if(error)
+ DLog(@"JSON Parsing Error: %@", error);
+
+ return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
}
@end
View
7 MKNetworkKit/MKNetworkOperation.m
@@ -1240,11 +1240,10 @@ -(NSXMLDocument*) responseXML {
-(id) responseJSON {
-#if __IPHONE_OS_VERSION_MAX_ALLOWED < 50000
if(NSClassFromString(@"NSJSONSerialization")) {
if([self responseData] == nil) return nil;
NSError *error = nil;
- id returnValue = [NSJSONSerialization JSONObjectWithData:[self responseData] options:0 error:&error];
+ id returnValue = [NSClassFromString(@"NSJSONSerialization") JSONObjectWithData:[self responseData] options:0 error:&error];
if(error) DLog(@"JSON Parsing Error: %@", error);
return returnValue;
}
@@ -1252,10 +1251,6 @@ -(id) responseJSON {
DLog("You are running on iOS 4. Subclass MKNO and override responseJSON to support custom JSON parsing");
return [self responseString];
}
-#else
- DLog("You are running on iOS 4. Subclass MKNO and override responseJSON to support custom JSON parsing");
- return [self responseString];
-#endif
}
#pragma mark -
View
2  iOS-Demo/MKNetworkKit-iOS-Demo.xcodeproj/project.pbxproj
@@ -323,6 +323,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "MKNetworkKitDemo/MKNetworkKit-iOS-Demo-Prefix.pch";
INFOPLIST_FILE = "MKNetworkKitDemo/MKNetworkKit-iOS-Demo-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 5.0;
OTHER_LDFLAGS = (
"-ObjC",
"-all_load",
@@ -340,6 +341,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "MKNetworkKitDemo/MKNetworkKit-iOS-Demo-Prefix.pch";
INFOPLIST_FILE = "MKNetworkKitDemo/MKNetworkKit-iOS-Demo-Info.plist";
+ IPHONEOS_DEPLOYMENT_TARGET = 5.0;
OTHER_LDFLAGS = (
"-ObjC",
"-all_load",
View
56 iOS-Demo/MKNetworkKitDemo/en.lproj/MainStoryboard.storyboard
@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="1.0" toolsVersion="1938" systemVersion="11C74" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="9VJ-YU-mm5">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="2809" systemVersion="11E53" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" initialViewController="9VJ-YU-mm5">
<dependencies>
- <development defaultVersion="4200" identifier="xcode"/>
- <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="933"/>
+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="1884"/>
</dependencies>
<scenes>
+ <!--View Controller - MKNetworkKit Demo-->
<scene sceneID="5">
<objects>
- <placeholder placeholderIdentifier="IBFirstResponder" id="4" sceneMemberID="firstResponder"/>
<viewController title="MKNetworkKit Demo" id="2" customClass="ViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="3">
<rect key="frame" x="0.0" y="64" width="320" height="416"/>
@@ -66,19 +65,19 @@
<rect key="frame" x="20" y="281" width="280" height="9"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</progressView>
- <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="MKNetworkKit Demo" textAlignment="center" lineBreakMode="tailTruncation" minimumFontSize="10" id="Cq6-9L-04t">
+ <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" lineBreakMode="tailTruncation" minimumFontSize="10" text="MKNetworkKit Demo" textAlignment="center" autoshrinkMode="minimumFontSize" id="Cq6-9L-04t">
<rect key="frame" x="20" y="9" width="280" height="34"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
- <fontDescription key="fontDescription" type="system" pointSize="20"/>
- <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
+ <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+ <fontDescription key="fontDescription" type="system" pointSize="20"/>
</label>
- <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Copyright (C) Mugunth Kumar" textAlignment="center" lineBreakMode="tailTruncation" minimumFontSize="10" id="Tom-SW-ODV">
+ <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" lineBreakMode="tailTruncation" minimumFontSize="10" text="Copyright (C) Mugunth Kumar" textAlignment="center" autoshrinkMode="minimumFontSize" id="Tom-SW-ODV">
<rect key="frame" x="20" y="388" width="280" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
- <fontDescription key="fontDescription" type="system" pointSize="10"/>
- <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
+ <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+ <fontDescription key="fontDescription" type="system" pointSize="10"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="Axl-TC-OtQ">
<rect key="frame" x="13" y="108" width="136" height="37"/>
@@ -113,14 +112,14 @@
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="username" minimumFontSize="17" id="RTo-3I-DXZ">
<rect key="frame" x="157" y="51" width="151" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
- <fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
+ <fontDescription key="fontDescription" type="system" pointSize="14"/>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="password" minimumFontSize="17" id="yEM-GJ-ODv">
<rect key="frame" x="157" y="90" width="151" height="31"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
- <fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
+ <fontDescription key="fontDescription" type="system" pointSize="14"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="DEJ-bd-I5d">
<rect key="frame" x="85" y="305" width="151" height="37"/>
@@ -164,26 +163,13 @@
<outlet property="userTextField" destination="RTo-3I-DXZ" id="ODo-N6-qAE"/>
</connections>
</viewController>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="4" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="429" y="-206"/>
</scene>
- <scene sceneID="nVy-01-meB">
- <objects>
- <placeholder placeholderIdentifier="IBFirstResponder" id="Xpb-E9-mb6" userLabel="First Responder" sceneMemberID="firstResponder"/>
- <viewController id="dxL-P4-nyu" sceneMemberID="viewController">
- <view key="view" contentMode="scaleToFill" id="OvZ-nW-3xH">
- <rect key="frame" x="0.0" y="20" width="320" height="460"/>
- <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
- <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
- </view>
- <navigationItem key="navigationItem" title="Root View Controller" id="iFd-Vj-NuA"/>
- </viewController>
- </objects>
- <point key="canvasLocation" x="1063" y="-451"/>
- </scene>
+ <!--Navigation Controller-->
<scene sceneID="2tA-nM-urH">
<objects>
- <placeholder placeholderIdentifier="IBFirstResponder" id="iBU-EW-OUe" userLabel="First Responder" sceneMemberID="firstResponder"/>
<navigationController definesPresentationContext="YES" id="9VJ-YU-mm5" sceneMemberID="viewController">
<navigationBar key="navigationBar" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" id="7ld-28-gUM">
<autoresizingMask key="autoresizingMask"/>
@@ -192,12 +178,13 @@
<segue destination="2" kind="relationship" relationship="rootViewController" id="cln-Oo-nMu"/>
</connections>
</navigationController>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="iBU-EW-OUe" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-197" y="-206"/>
</scene>
+ <!--Flickr Table View Controller-->
<scene sceneID="haG-Xr-eAE">
<objects>
- <placeholder placeholderIdentifier="IBFirstResponder" id="ja6-fg-gTq" userLabel="First Responder" sceneMemberID="firstResponder"/>
<tableViewController id="hO6-6F-jyb" customClass="FlickrTableViewController" sceneMemberID="viewController">
<tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" rowHeight="72" sectionHeaderHeight="22" sectionFooterHeight="22" id="oxp-VI-LZp">
<rect key="frame" x="0.0" y="64" width="320" height="416"/>
@@ -215,19 +202,19 @@
<rect key="frame" x="20" y="11" width="50" height="50"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
- <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Nice Sunset" lineBreakMode="tailTruncation" minimumFontSize="10" id="Yx6-1N-NVt">
+ <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" lineBreakMode="tailTruncation" minimumFontSize="10" text="Nice Sunset" autoshrinkMode="minimumFontSize" id="Yx6-1N-NVt">
<rect key="frame" x="78" y="11" width="222" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
- <fontDescription key="fontDescription" type="system" pointSize="17"/>
- <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
+ <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+ <fontDescription key="fontDescription" type="system" pointSize="17"/>
</label>
- <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Mugunth" lineBreakMode="tailTruncation" minimumFontSize="10" id="9be-63-dg7">
+ <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" lineBreakMode="tailTruncation" minimumFontSize="10" text="Mugunth" autoshrinkMode="minimumFontSize" id="9be-63-dg7">
<rect key="frame" x="78" y="40" width="222" height="21"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
- <fontDescription key="fontDescription" type="system" pointSize="15"/>
- <color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
+ <color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
+ <fontDescription key="fontDescription" type="system" pointSize="15"/>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
@@ -248,6 +235,7 @@
</tableView>
<navigationItem key="navigationItem" id="f4v-fy-2qy"/>
</tableViewController>
+ <placeholder placeholderIdentifier="IBFirstResponder" id="ja6-fg-gTq" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="802" y="-164"/>
</scene>

0 comments on commit 54ed98a

Please sign in to comment.
Something went wrong with that request. Please try again.