<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Codethink &#187; ios</title>
	<atom:link href="https://codethink.no-ip.org/tags/ios/feed" rel="self" type="application/rss+xml" />
	<link>https://codethink.no-ip.org</link>
	<description>A blog about coding, life, and other arbitrary topics</description>
	<lastBuildDate>Sun, 15 Mar 2026 21:30:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.29</generator>
	<item>
		<title>NSObject+SimpleJson</title>
		<link>https://codethink.no-ip.org/archives/924</link>
		<comments>https://codethink.no-ip.org/archives/924#comments</comments>
		<pubDate>Wed, 08 Jan 2014 07:37:39 +0000</pubDate>
		<dc:creator><![CDATA[aroth]]></dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[objc]]></category>

		<guid isPermaLink="false">http://codethink.no-ip.org/wordpress/?p=924</guid>
		<description><![CDATA[Certainly the subject of JSON processing on iOS is fairly old-hat at this point. After all, Apple has provided native support for JSON serialization and parsing since the release of iOS 5. So why bring it up now? Personally I&#8217;ve &#8230; <a href="https://codethink.no-ip.org/archives/924">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Certainly the subject of JSON processing on iOS is fairly old-hat at this point.  After all, Apple has provided native support for JSON serialization and parsing since the release of iOS 5.  So why bring it up now?  </p>
<p>Personally I&#8217;ve never been entirely happy with the implementation provided by Apple, and in particular their decision to build their API around <i>NSData</i> instead of <i>NSString</i>.  Granted there&#8217;s probably a reason why Apple chose to go that route, and also a reason why they didn&#8217;t bother to provide convenience methods that allow people to work with whichever type they prefer.  But as far as I&#8217;m concerned, JSON is a textual/non-binary data format, so therefore the natural iOS data structure to use for outputting and inputting JSON data is an <i>NSString</i>.  Using <i>NSData</i> instead is counter-intuitive, and clunky as a result.</p>
<p>So because of that clunkiness, I&#8217;ve stuck with the tried and true <a href="http://superloopy.io/json-framework/?utm_source=ipadsummary&#038;utm_medium=twitter">SBJson</a> library, even though the author of that library himself recommends just using Apple&#8217;s implementation.  This preference is largely based around the very helpful (and also very deprecated) &#8216;<i>NSObject+SBJson</i>&#8216; category that is included in the library.  This category imbues objects with a couple of very convenient methods:</p>
<pre class="brush: cpp; title: ; notranslate">- (NSString*)JSONRepresentation;
- (id)JSONValue;</pre>
<p>These methods can be used to turn an appropriate object (i.e. an <i>NSArray</i> or an <i>NSDictionary</i>) into a JSON string, and to turn a JSON string back into a proper object, respectively.  No parameters, no options, no boxing to or unboxing from <i>NSData</i>; just a simple API that is basically just &#8216;<i>[thing turnIntoJson];</i>&#8216; and &#8216;<i>[json turnBackIntoThing];</i>&#8216;.  It doesn&#8217;t get much more convenient than that.  </p>
<p>And that was all well and good, until I wanted to build a <a href="https://github.com/kstenerud/iOS-Universal-Framework">framework</a> which internally used SBJson, and then use that framework within a project that also needs to make its own use of SBJson.  Linker hell was the result.  And long story short, I decided that it would be faster to build a shim around Apple&#8217;s JSON API to preserve the convenience I&#8217;m after than it would be to appease the linker gods.  </p>
<p>So in case anyone else has been avoiding Apple&#8217;s JSON implementation because it&#8217;s too clunky to work with (or too painful to migrate away from SBJson), here&#8217;s my 5-minute shim:</p>
<p><b>NSObject+SimpleJson.h</b></p>
<pre class="brush: cpp; title: ; notranslate">#import &lt;Foundation/Foundation.h&gt;

@interface NSObject (SimpleJson)

- (NSString *)JSONRepresentation;  //turns an object into a JSON string
- (id)JSONValue;                           //turns a JSON string back into an object

@end</pre>
<p><b>NSObject+SimpleJson.m</b></p>
<pre class="brush: cpp; title: ; notranslate">#import &quot;NSObject+SimpleJson.h&quot;

@implementation NSObject (SimpleJson)

- (NSString*)JSONRepresentation {
    //write ourself to a JSON string; only works if we're a type that 'NSJSONSerialization' supports
    NSError* error = nil;
    NSData* tempData = [NSJSONSerialization dataWithJSONObject:self options:kNilOptions error:&amp;error];
    if (error) {
        return nil;
    }
    
    return [[NSString alloc] initWithData:tempData encoding:NSUTF8StringEncoding];
}


- (id) JSONValue {
    //converts from a string back into a proper object; only works if we're an NSString or NSData instance
    if (! [self isKindOfClass:[NSString class]] &amp;&amp; ! [self isKindOfClass:[NSData class]]) {
        return nil;
    }
    
    NSData* jsonData = nil;
    if ([self isKindOfClass:[NSData class]]) {
        jsonData = (NSData*)self;
    }
    else {
        //we must be an NSString
        jsonData = [((NSString*)self) dataUsingEncoding:NSUTF8StringEncoding];
    }
    
    return [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:nil];
}

@end</pre>
<p>If you have code that uses SBJson&#8217;s &#8216;<i>NSObject+SBJson</i>&#8216; category, the above category should be drop-in compatible.  And just as importantly (in my case) does not invoke linker hell when used as part of an iOS framework.</p>
<p>Note that the above code assumes you are using ARC.  If not, you&#8217;ll want to add an &#8216;<i>autorelease</i>&#8216; call in there.</p>
]]></content:encoded>
			<wfw:commentRss>https://codethink.no-ip.org/archives/924/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[XCode] Building Universal iOS Frameworks</title>
		<link>https://codethink.no-ip.org/archives/688</link>
		<comments>https://codethink.no-ip.org/archives/688#comments</comments>
		<pubDate>Sun, 26 Jun 2011 11:56:12 +0000</pubDate>
		<dc:creator><![CDATA[aroth]]></dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[xcode]]></category>

		<guid isPermaLink="false">http://codethink.no-ip.org/wordpress/?p=688</guid>
		<description><![CDATA[Here&#8217;s an excellent little project that I stumbled across not too long ago: https://github.com/kstenerud/iOS-Universal-Framework This project provides a single installation shell script that will add a new Project Template to XCode, one that can be used to build universal iOS &#8230; <a href="https://codethink.no-ip.org/archives/688">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Here&#8217;s an excellent little project that I stumbled across not too long ago:</p>
<p><a href="https://github.com/kstenerud/iOS-Universal-Framework" target="_blank">https://github.com/kstenerud/iOS-Universal-Framework</a></p>
<p>This project provides a single installation shell script that will add a new Project Template to XCode, one that can be used to build universal iOS frameworks.  Now this wouldn&#8217;t be a big deal (and in all rights, <em>shouldn&#8217;t</em> be a big deal), if not for the fact that for some unspecified and frustrating reason, XCode has no built-in ability to create such frameworks.  This means that up until recently if you had an iOS library that you wanted to use across many projects, or that you wanted to distribute for other developers to use in their projects, you had only a few not-very-good options:</p>
<ul>
<li>Include your source code in every project that uses your library (increased compilation time, hooray!).</li>
<li>Build two library versions, one for armv6/armv7 and one for x86.</li>
<li>Screw with the linker to <a href="http://mark.aufflick.com/blog/2010/11/19/making-a-fat-static-library-for-ios-device-and-simulator" target="_blank">manually create a &#8220;fat&#8221; library</a>.</li>
<li>Use the <a href="http://db-in.com/blog/2011/05/creating-universal-framework-to-iphone-ios/" target="_blank">Bundle Hack</a> and hope that it works.</li>
</ul>
<p>It&#8217;s worth noting here that the first three options listed above do nothing to help with the management of any shared header files needed to actually make use of the library code.  The fourth option does allow you to include public headers in your build artifact, but the setup to do so is tedious, and the entire thing is basically a giant hack besides.  None of these options are really very convenient or useful from the developer&#8217;s point of view.</p>
<p>What developers really need, what they should have access to, and what XCode should have supported at least since the release of iOS 4.0, is the ability to build true universal iOS frameworks that are &#8220;real&#8221; frameworks in the same sense that UIKit and CoreGraphics are real frameworks.  And that&#8217;s exactly what the <a href="https://github.com/kstenerud/iOS-Universal-Framework" target="_blank">iOS-Universal-Framework</a> project gives you.  Just install it and you get a handy XCode Project Template that can be used to build a universal iOS framework.  This lets you build real iOS frameworks that include libraries for both x86 and armv6/armv7 in a single package, automatically bundled with your public header files.  You (or anyone else) can then use the generated framework inside of other projects in the same way as any other iOS framework; just add it to your &#8220;Link With Binary Libraries&#8221; build phase, and away you go.</p>
<p>All told, the  <a href="https://github.com/kstenerud/iOS-Universal-Framework" target="_blank">iOS-Universal-Framework</a> Project Template is great and works exactly as advertised.  Just install it and you&#8217;re good to go.  I&#8217;ve only come across one minor caveat worth mentioning, which is that although the template does correctly produce a universal iOS framework, the build product shown in XCode will actually point to an architecture-specific version of the framework.  In order to find the correct, universal framework it is necessary to do a &#8220;Show in Finder&#8221; on the build product shown in XCode (or otherwise navigate to your project output directory), and then go up a level (or two) in the filesystem to find the folder that contains the universal version of the framework (<em>edit:  as per Karl&#8217;s comment below, this has now been fixed.  Hooray!</em>).  </p>
<p>Apart from that minor annoyance this little XCode extension is really quite excellent, and I encourage you to give it a try.  My personal thanks to Karl Stenerud for putting this together.</p>
]]></content:encoded>
			<wfw:commentRss>https://codethink.no-ip.org/archives/688/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
