<?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>Matt Galloway&#039;s iPhone Apps &#187; iPhone SDK</title>
	<atom:link href="http://iphone.galloway.me.uk/category/iphone-sdk/feed/" rel="self" type="application/rss+xml" />
	<link>http://iphone.galloway.me.uk</link>
	<description>iPhone Applications</description>
	<lastBuildDate>Thu, 02 Feb 2012 09:22:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>A look under ARC&#8217;s hood &#8211; Episode 2</title>
		<link>http://iphone.galloway.me.uk/2012/01/a-look-under-arcs-hood-episode-2/</link>
		<comments>http://iphone.galloway.me.uk/2012/01/a-look-under-arcs-hood-episode-2/#comments</comments>
		<pubDate>Sat, 07 Jan 2012 15:30:31 +0000</pubDate>
		<dc:creator>Matt Galloway</dc:creator>
				<category><![CDATA[iPhone SDK]]></category>

		<guid isPermaLink="false">http://iphone.galloway.me.uk/?p=456</guid>
		<description><![CDATA[Following on from my first post about looking at how ARC works under the hood I thought I would share another little snippet that I found interesting. This time I was wondering what happened when you pulled an object out of an array and returned it from a method. Pre-ARC, you would retain the object [...]]]></description>
			<content:encoded><![CDATA[<p>Following on from my first post about looking at <a href="http://iphone.galloway.me.uk/2012/01/a-look-under-arcs-hood-episode-1/">how ARC works under the hood</a> I thought I would share another little snippet that I found interesting. This time I was wondering what happened when you pulled an object out of an array and returned it from a method. Pre-ARC, you would retain the object then return it autoreleased. With ARC we can get rid of those memory management calls but it just feels wrong. So I decided to check ARC was doing the right thing.</p>
<p><span id="more-456"></span></p>
<p>Consider this class:</p>
<pre class="brush: objc; title: ; notranslate">
#import &lt;Foundation/Foundation.h&gt;

@interface ClassA : NSObject

@property (nonatomic, strong) NSMutableArray *array;

@end

@implementation ClassA

@synthesize array;

- (id)popObject {
    id lastObject = [array lastObject];
    if (lastObject) {
        [array removeLastObject];
    }
    return lastObject;
}

@end
</pre>
<p>In non-ARC land, the call to <code>removeLastObject</code> would release the object that was in the array and then if that was the last reference to it, it would <code>dealloc</code> the object meaning that we return a dead object. So we would retain <code>lastObject</code> and then return it with an autorelease.</p>
<p>But this scared me not doing this, even though I knew full well that ARC should be doing its job. I think I thought this because naively I thought that ARC would parse the method line by line. If it did then I thought it might not necessarily add in a retain because when we get a reference to the last object, ARC doesn&#8217;t know it needs to add a retain because well, why would it necessarily have to?</p>
<p>That&#8217;s where I was wrong. Obviously what ARC does is it will add in a retain once we get a reference to that object and then when that variable goes out of scope it adds a release or in our case, because we are returning it and the method name does not start with <code>new</code> or <code>copy</code>, it autoreleases it.</p>
<p>Let&#8217;s see what that code compiled to:</p>
<pre class="brush: cpp; highlight: [21,34]; title: ; notranslate">
        .thumb_func     &quot;-[ClassA popObject]&quot;
&quot;-[ClassA popObject]&quot;:
        push    {r4, r5, r6, r7, lr}
        movw    r6, :lower16:(_OBJC_IVAR_$_ClassA.array-(LPC0_0+4))
        mov     r4, r0
        movt    r6, :upper16:(_OBJC_IVAR_$_ClassA.array-(LPC0_0+4))
        movw    r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_-(LPC0_1+4))
LPC0_0:
        add     r6, pc
        movt    r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_-(LPC0_1+4))
LPC0_1:
        add     r1, pc
        add     r7, sp, #12
        ldr     r0, [r6]
        ldr     r1, [r1]
        ldr     r0, [r4, r0]
        blx     _objc_msgSend
        @ InlineAsm Start
        mov     r7, r7          @ marker for objc_retainAutoreleaseReturnValue
        @ InlineAsm End
        blx     _objc_retainAutoreleasedReturnValue
        mov     r5, r0
        cbz     r5, LBB0_2
        movw    r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_2-(LPC0_2+4))
        movt    r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_2-(LPC0_2+4))
        ldr     r0, [r6]
LPC0_2:
        add     r1, pc
        ldr     r1, [r1]
        ldr     r0, [r4, r0]
        blx     _objc_msgSend
LBB0_2:
        mov     r0, r5
        blx     _objc_autoreleaseReturnValue
        pop     {r4, r5, r6, r7, pc}
</pre>
<p>Well, there we go. ARC has done a fine job for us. What it&#8217;s actually done is added a call to <code>objc_retainAutoreleaseReturnValue</code> which means it has noticed it needs to retain a value that was returned autoreleased which must be an ARC optimisation that will just pull the object once from the autorelease pool rather than actually performing a retain. Then at the end of the method it calls <code>objc_autoreleaseReturnValue</code> which must do the work of autoreleasing the value we&#8217;re returning.</p>
<p>This is just another example of how to look at what ARC is doing under the hood. The more I use ARC, the more I realise how useful it is. It makes code less prone to memory management errors and allows for optimisations such as the one shown here of retaining an autoreleased return value.</p>
]]></content:encoded>
			<wfw:commentRss>http://iphone.galloway.me.uk/2012/01/a-look-under-arcs-hood-episode-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A look under ARC&#8217;s hood &#8211; Episode 1</title>
		<link>http://iphone.galloway.me.uk/2012/01/a-look-under-arcs-hood-episode-1/</link>
		<comments>http://iphone.galloway.me.uk/2012/01/a-look-under-arcs-hood-episode-1/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 11:12:58 +0000</pubDate>
		<dc:creator>Matt Galloway</dc:creator>
				<category><![CDATA[iPhone SDK]]></category>

		<guid isPermaLink="false">http://iphone.galloway.me.uk/?p=443</guid>
		<description><![CDATA[After a conversation on Twitter with @jacobrelkin I decided to write a little post about how ARC works under the hood and how you can go about seeing what it&#8217;s doing. In this post I&#8217;ll explain about how ARC adds in retain, release and autorelease calls accordingly. We shall start by defining a class like [...]]]></description>
			<content:encoded><![CDATA[<p>After a <a href="http://twitter.com/#!/mattjgalloway/status/154478264537194496">conversation on Twitter</a> with <a href="http://twitter.com/jacobrelkin">@jacobrelkin</a> I decided to write a little post about how ARC works under the hood and how you can go about seeing what it&#8217;s doing. In this post I&#8217;ll explain about how ARC adds in <code>retain</code>, <code>release</code> and <code>autorelease</code> calls accordingly. </p>
<p><span id="more-443"></span></p>
<p>We shall start by defining a class like so:</p>
<pre class="brush: objc; title: ; notranslate">
#import &lt;Foundation/Foundation.h&gt;

@interface ClassA : NSObject 

@property (nonatomic, retain) NSNumber *foo;

@end

@implementation ClassA

@synthesize foo;

- (void)changeFooDirect:(NSNumber*)inFoo {
    foo = inFoo;
}

- (void)changeFooSetter:(NSNumber*)inFoo {
    self.foo = inFoo;
}

- (NSNumber*)newNumber {
    return [[NSNumber alloc] initWithInt:10];
}

- (NSNumber*)getNumber {
    return [[NSNumber alloc] initWithInt:10];
}

@end
</pre>
<p>This outlines a few important aspects of ARC including direct access to ivars versus using a setter and how ARC will add autorelease calls when returning an object from a method based on the name of the method.</p>
<p>Let&#8217;s first look at the direct access to ivars versus using a setter. If we compile that code and look at the assembly then we&#8217;ll get an insight into what&#8217;s going on. I decided to use ARMv7 because it&#8217;s easier to understand what&#8217;s going on than x86 (in my opinion anyway!). We can turn ARC on and off with the <code>-fobjc-arc</code> and <code>-fno-objc-arc</code> compiler options. In these examples I&#8217;ve used optimisation level 3 which will mean the compiler will also remove redundant code which we&#8217;re not really interested in and would clog up the understanding (an exercise for the reader is to try without any optimisations and see what it looks like).</p>
<p>So to compile without ARC I used the following command:</p>
<pre class="brush: bash; title: ; notranslate">$ /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -arch armv7 -fno-objc-arc -O3 -S -o - test-arc.m</pre>
<p>So, let&#8217;s look at <code>changeFooDirect:</code> and <code>changeFooSetter:</code>:</p>
<pre class="brush: cpp; title: ; notranslate">
        .align  2
        .code   16
        .thumb_func     &quot;-[ClassA changeFooDirect:]&quot;
&quot;-[ClassA changeFooDirect:]&quot;:
        movw    r1, :lower16:(_OBJC_IVAR_$_ClassA.foo-(LPC0_0+4))
        movt    r1, :upper16:(_OBJC_IVAR_$_ClassA.foo-(LPC0_0+4))
LPC0_0:
        add     r1, pc
        ldr     r1, [r1]
        str     r2, [r0, r1]
        bx      lr

        .align  2
        .code   16
        .thumb_func     &quot;-[ClassA changeFooSetter:]&quot;
&quot;-[ClassA changeFooSetter:]&quot;:
        push    {r7, lr}
        movw    r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_-(LPC1_0+4))
        mov     r7, sp
        movt    r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_-(LPC1_0+4))
LPC1_0:
        add     r1, pc
        ldr     r1, [r1]
        blx     _objc_msgSend
        pop     {r7, pc}
</pre>
<p>And following straight on, let&#8217;s look at what it looks like with ARC enabled. To do this I used the following command:</p>
<pre class="brush: bash; title: ; notranslate">$ /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/clang -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -arch armv7 -fobjc-arc -O3 -S -o - test-arc.m</pre>
<p>Again, we&#8217;re interested at the moment in <code>changeFooDirect:</code> and <code>changeFooSetter:</code>:</p>
<pre class="brush: cpp; highlight: [14]; title: ; notranslate">
        .align  2
        .code   16
        .thumb_func     &quot;-[ClassA changeFooDirect:]&quot;
&quot;-[ClassA changeFooDirect:]&quot;:
        push    {r7, lr}
        movw    r1, :lower16:(_OBJC_IVAR_$_ClassA.foo-(LPC0_0+4))
        mov     r7, sp
        movt    r1, :upper16:(_OBJC_IVAR_$_ClassA.foo-(LPC0_0+4))
LPC0_0:
        add     r1, pc
        ldr     r1, [r1]
        add     r0, r1
        mov     r1, r2
        blx     _objc_storeStrong
        pop     {r7, pc}

        .align  2
        .code   16
        .thumb_func     &quot;-[ClassA changeFooSetter:]&quot;
&quot;-[ClassA changeFooSetter:]&quot;:
        push    {r7, lr}
        movw    r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_-(LPC1_0+4))
        mov     r7, sp
        movt    r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_-(LPC1_0+4))
LPC1_0:
        add     r1, pc
        ldr     r1, [r1]
        blx     _objc_msgSend
        pop     {r7, pc}
</pre>
<p>We can instantly see the difference here. The <code>changeFooSetter:</code> is exactly the same whereas <code>changeFooDirect:</code> has changed with a single call to <code>objc_storeStrong</code>. That&#8217;s the interesting bit. If we looks at the <a href="http://clang.llvm.org/docs/AutomaticReferenceCounting.html#runtime.objc_storeStrong">LLVM documentation for this</a> then we see that it&#8217;s doing a standard swap of the variable by releasing the old value and retain the new value. Whereas in the non-ARC version the ivar is just swapped without any retain or release. That&#8217;s just what we&#8217;d expect! Thanks ARC!</p>
<p>Now for the more interesting bit, the <code>newNumber</code> versus <code>getNumber</code>. Those methods in non-ARC land are both returning <code>NSNumber</code> objects which have a retain count of 1, i.e. the caller owns them. That sounds right for <code>newNumber</code> but not for <code>getNumber</code> according to Cocoa&#8217;s naming conventions. We&#8217;d expect to see an <code>autorelease</code> call when returning from <code>getNumber</code>. So let&#8217;s see what the code looks like without ARC:</p>
<pre class="brush: cpp; title: ; notranslate">
        .align  2
        .code   16
        .thumb_func     &quot;-[ClassA newNumber]&quot;
&quot;-[ClassA newNumber]&quot;:
        push    {r7, lr}
        movw    r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_2-(LPC2_0+4))
        mov     r7, sp
        movt    r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_2-(LPC2_0+4))
        movw    r0, :lower16:(L_OBJC_CLASSLIST_REFERENCES_$_-(LPC2_1+4))
        movt    r0, :upper16:(L_OBJC_CLASSLIST_REFERENCES_$_-(LPC2_1+4))
LPC2_0:
        add     r1, pc
LPC2_1:
        add     r0, pc
        ldr     r1, [r1]
        ldr     r0, [r0]
        blx     _objc_msgSend
        movw    r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_4-(LPC2_2+4))
        movs    r2, #10
        movt    r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_4-(LPC2_2+4))
LPC2_2:
        add     r1, pc
        ldr     r1, [r1]
        blx     _objc_msgSend
        pop     {r7, pc}

        .align  2
        .code   16
        .thumb_func     &quot;-[ClassA getNumber]&quot;
&quot;-[ClassA getNumber]&quot;:
        push    {r7, lr}
        movw    r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_2-(LPC3_0+4))
        mov     r7, sp
        movt    r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_2-(LPC3_0+4))
        movw    r0, :lower16:(L_OBJC_CLASSLIST_REFERENCES_$_-(LPC3_1+4))
        movt    r0, :upper16:(L_OBJC_CLASSLIST_REFERENCES_$_-(LPC3_1+4))
LPC3_0:
        add     r1, pc
LPC3_1:
        add     r0, pc
        ldr     r1, [r1]
        ldr     r0, [r0]
        blx     _objc_msgSend
        movw    r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_4-(LPC3_2+4))
        movs    r2, #10
        movt    r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_4-(LPC3_2+4))
LPC3_2:
        add     r1, pc
        ldr     r1, [r1]
        blx     _objc_msgSend
        pop     {r7, pc}
</pre>
<p>And now with ARC:</p>
<pre class="brush: cpp; highlight: [51]; title: ; notranslate">
        .align  2
        .code   16
        .thumb_func     &quot;-[ClassA newNumber]&quot;
&quot;-[ClassA newNumber]&quot;:
        push    {r7, lr}
        movw    r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_2-(LPC2_0+4))
        mov     r7, sp
        movt    r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_2-(LPC2_0+4))
        movw    r0, :lower16:(L_OBJC_CLASSLIST_REFERENCES_$_-(LPC2_1+4))
        movt    r0, :upper16:(L_OBJC_CLASSLIST_REFERENCES_$_-(LPC2_1+4))
LPC2_0:
        add     r1, pc
LPC2_1:
        add     r0, pc
        ldr     r1, [r1]
        ldr     r0, [r0]
        blx     _objc_msgSend
        movw    r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_4-(LPC2_2+4))
        movs    r2, #10
        movt    r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_4-(LPC2_2+4))
LPC2_2:
        add     r1, pc
        ldr     r1, [r1]
        blx     _objc_msgSend
        pop     {r7, pc}

        .align  2
        .code   16
        .thumb_func     &quot;-[ClassA getNumber]&quot;
&quot;-[ClassA getNumber]&quot;:
        push    {r7, lr}
        movw    r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_2-(LPC3_0+4))
        mov     r7, sp
        movt    r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_2-(LPC3_0+4))
        movw    r0, :lower16:(L_OBJC_CLASSLIST_REFERENCES_$_-(LPC3_1+4))
        movt    r0, :upper16:(L_OBJC_CLASSLIST_REFERENCES_$_-(LPC3_1+4))
LPC3_0:
        add     r1, pc
LPC3_1:
        add     r0, pc
        ldr     r1, [r1]
        ldr     r0, [r0]
        blx     _objc_msgSend
        movw    r1, :lower16:(L_OBJC_SELECTOR_REFERENCES_4-(LPC3_2+4))
        movs    r2, #10
        movt    r1, :upper16:(L_OBJC_SELECTOR_REFERENCES_4-(LPC3_2+4))
LPC3_2:
        add     r1, pc
        ldr     r1, [r1]
        blx     _objc_msgSend
        blx     _objc_autorelease
        pop     {r7, pc}
</pre>
<p>And look at the single difference &#8211; a <code>blx</code> (this is a method call) to <code>objc_autorelease</code> in <code>getNumber:</code>. That&#8217;s just what we&#8217;d expect from ARC because it&#8217;s noticed that the method name doesn&#8217;t start with <code>new</code> or <code>copy</code> and it knows that at the point of return the <code>NSNumber</code> has a retain count of 1 so it adds in an <code>autorelease</code> call. Excellent!</p>
<p>This has just shown a little insight into how ARC works in two circumstances and I hope it inspires the reader to go away and look for themselves into how ARC works rather than just taking it for granted. It&#8217;s important as a programmer to understand how your tools work.</p>
]]></content:encoded>
			<wfw:commentRss>http://iphone.galloway.me.uk/2012/01/a-look-under-arcs-hood-episode-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Review: Sensible TableView</title>
		<link>http://iphone.galloway.me.uk/2011/04/review-sensible-tableview/</link>
		<comments>http://iphone.galloway.me.uk/2011/04/review-sensible-tableview/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 20:30:54 +0000</pubDate>
		<dc:creator>Matt Galloway</dc:creator>
				<category><![CDATA[iPhone SDK]]></category>

		<guid isPermaLink="false">http://iphone.galloway.me.uk/?p=402</guid>
		<description><![CDATA[Every iOS developer should be very familiar with the UITableView. It&#8217;s the main building block of most applications (excluding OpenGL based games, of course). So back when I started developing applications when iOS was on version 2.0, I created a tutorial for creating custom UITableViewCell objects. Since then application developers are finding more and more [...]]]></description>
			<content:encoded><![CDATA[<p>Every iOS developer should be very familiar with the UITableView. It&#8217;s the main building block of most applications (excluding OpenGL based games, of course). So back when I started developing applications when iOS was on version 2.0, I created a <a href="http://iphone.galloway.me.uk/iphone-sdktutorials/custom-uitableviewcell/">tutorial</a> for creating custom UITableViewCell objects. Since then application developers are finding more and more that they need to push the boundaries of what they can do with a simple UITableViewCell. In iOS 3.0 Apple introduced a style attribute for cells, which certainly helped with a lot of situations but there is still the tedious process of creating custom cells with anything more than the standard 1 or 2 text labels.<br />
<span id="more-402"></span></p>
<p>I usually end up hand rolling a UITableViewCell subclass, or if I only ever want 1 of that type of cell in a given view (for instance a single username and single password cell) I might use Interface Builder to create the cell and put it in the XIB for the view controller. But when you end up with 10+ projects each with a handful of custom cells, you soon go quite mad trying to remember each detail about each cell.</p>

<p>So I was pleasantly surprised when I was recently given the opportunity to take a look at <a href="http://sensiblecocoa.com/?amigosid=2">Sensible Cocoa</a>&#8216;s <a href="http://sensiblecocoa.com/features.html?amigosid=2">Sensible TableView (STV)</a> project, which is a collection of Objective-C classes for easily creating custom UITableViewCells.</p>
<h1>The Review</h1>
<p>Having had a play with STV I have managed to get to grips with how it works and why you might want to use it. Hopefully by reading this you can get an insight into why you might want to use STV.</p>
<h2>Features</h2>
<p>STV at it&#8217;s core is a very simple way of creating custom cells (see the code samples below) but also there&#8217;s a lot of very impressive extra features such as binding to a data model so that you can create very complex interfaces to interact with your data. They also appear to be adding features all the time which is a good sign.</p>
<h2>Examples</h2>
<p>The best examples are on <a href="http://sensiblecocoa.com/video-tutorials.html?amigosid=2">Sensible Cocoa&#8217;s website</a> where there are videos showing how to use it.</p>
<h2>Cost</h2>
<p>STV is <a href="http://sensiblecocoa.com/?amigosid=2">currently $99</a> for a license which includes full source code &#038; limited time support. I think this is pretty decent value for money given what you can do with it.</p>
<h2>Summary</h2>
<p>If you&#8217;re someone who uses UITableView everyday, I can see that STV will definitely make your life a lot easier. I&#8217;d suggest that it might be suited more to contractors who are constantly churning out apps rather than developers working on long term projects where rolling your own cells is probably the right way to go still, given that you still get much more control over the cells if you do it yourself. For instance, in my <a href="http://itunes.apple.com/gb/app/subnet-calc/id295652242?mt=8&#038;uo=4">Subnet Calc</a> <a href="http://itunes.apple.com/gb/app/subnet-calc-pro/id303555213?mt=8&#038;uo=4">range</a> of <a href="http://itunes.apple.com/gb/app/subnet-calc-hd/id383209264?mt=8&#038;uo=4">applications</a> I have created a custom cell that is far too custom for STV to ever implement &#8211; it&#8217;s too specific to the application.</p>
<p>Overall, go and give STV a look. Watch the <a href="http://sensiblecocoa.com/video-tutorials.html?amigosid=2">tutorial videos</a> and see if it can do something for you.</p>
<p>In the coming weeks I aim to write a few more posts aimed at showing a few of the features of STV.</p>
]]></content:encoded>
			<wfw:commentRss>http://iphone.galloway.me.uk/2011/04/review-sensible-tableview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone SDK Bug Hunting &#8211; GCC atomic builtins</title>
		<link>http://iphone.galloway.me.uk/2010/05/iphone-sdk-bug-hunting-gcc-atomic-builtins/</link>
		<comments>http://iphone.galloway.me.uk/2010/05/iphone-sdk-bug-hunting-gcc-atomic-builtins/#comments</comments>
		<pubDate>Fri, 14 May 2010 14:46:14 +0000</pubDate>
		<dc:creator>Matt Galloway</dc:creator>
				<category><![CDATA[iPhone SDK]]></category>

		<guid isPermaLink="false">http://iphone.galloway.me.uk/?p=333</guid>
		<description><![CDATA[For a while now I have been reporting bugs that I find in the iPhone SDK / iPhone OS to Apple because I realised that it&#8217;d be nice to help out. Some bugs have been small and some have been large, ranging from minor crashes of MobileSafari up to full blown problems in the iPhone [...]]]></description>
			<content:encoded><![CDATA[<p>For a while now I have been reporting bugs that I find in the iPhone SDK / iPhone OS to Apple because I realised that it&#8217;d be nice to help out. Some bugs have been small and some have been large, ranging from minor crashes of MobileSafari up to full blown problems in the iPhone SDK and associated frameworks.</p>
<p>One that I came across today had stumped me for a long time and it has to do with the <a href="http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html">GCC atomic builtins</a>. If you&#8217;re unfamiliar with them, then a good bit of introductory reading is a <a href="http://blogs.arm.com/software-enablement/locks-swps-and-two-smoking-barriers/">great blog post on the ARM blog</a>. Now, these atomic builtins have not been defined within the iPhone&#8217;s libc implementation, until the 3.2 SDK came along &#8211; it appears that Apple have added them. This is a good thing, because it means that we can start using them in our applications. But, we can only use them for <strong>applications running on iPhone OS >=3.2</strong> of course. That&#8217;s where the fun begins&#8230;</p>
<p>I have an application which I have been developing that needs to run on both the 3G and the 3GS, i.e. both armv6 and armv7. I found that after upgrading to the 3.2 SDK I started running into a rather strange problem when running the application on an iPhone 3G (running iPhone OS 3.1.3). The error I was getting was this:</p>
<pre class="brush: plain; title: ; notranslate">

dyld: lazy symbol binding failed: Symbol not found: ___sync_fetch_and_add_4
  Referenced from: /var/mobile/Applications/xxx/MyApp.app/MyApp
  Expected in: /usr/lib/libSystem.B.dylib

dyld: Symbol not found: ___sync_fetch_and_add_4
  Referenced from: /var/mobile/Applications/xxx/MyApp.app/MyApp
  Expected in: /usr/lib/libSystem.B.dylib
</pre>
<p>Now that&#8217;s really odd because __sync_fetch_and_add_4 is one of those GCC atomics which shouldn&#8217;t be being linked in as I am building for an iPhone OS deployment target of 3.1. It&#8217;s worth at this stage having a quick look at &#8211; <a href="http://developer.apple.com/iphone/library/documentation/Xcode/Conceptual/iphone_development/120-Running_Applications/running_applications.html">http://developer.apple.com/iphone/library/documentation/Xcode/Conceptual/iphone_development/120-Running_Applications/running_applications.html</a> &#8211; which says:</p>
<blockquote><p>You specify the earliest iPhone OS release on which you want your application to run with the iPhone OS Deployment Target build setting. By default, this build setting is set to the iPhone OS release that corresponds to the Base SDK build-setting value. For example, when you set Base SDK to iPhone Device 2.2.1 or iPhone Simulator 2.2.1, the value of the iPhone Deployment Target build setting is iPhone OS 2.2.1, as shown in Figure 3-3.</p></blockquote>
<p>So that means that if I set the base SDK to 3.2 and the iPhone OS deployment target to 3.1, then I should get code that will definitely run on 3.1, right? Running my app on 3.1.3 however causes a crash simply because __sync_fetch_and_add_4 isn&#8217;t available in its libc.</p>
<p>After a bit of inspection I found that even this simple program caused the crash:</p>
<pre class="brush: cpp; title: ; notranslate">#include &lt;string&gt;

int main(int argc, char *argv[]) {
    std::string strA = &quot;yes&quot;;
    return 0;
}
</pre>
<p>That really is a very simple program! Why would that crash! Well, with a bit of inspection using &#8216;<a href="http://linux.die.net/man/1/nm">nm</a>&#8216; we can work out what&#8217;s going on. &#8216;nm&#8217; shows us a list of the symbols that a given object file, or binary references. Below are outputs of &#8216;nm&#8217; on the resulting binary from 2 different combinations of base SDK and iPhone OS deployment target.</p>
<p>Base SDK = 3.1.3, iPhone OS Deployment Target = 3.1:</p>
<pre class="brush: plain; title: ; notranslate">nm build/Debug-iphoneos/AtomicsBug.app/AtomicsBug

build/Debug-iphoneos/AtomicsBug.app/AtomicsBug (for architecture armv6):
00002f64 s  stub helpers
00002fdc s GCC_except_table0
00003048 D _NXArgc
0000304c D _NXArgv
         U __Unwind_SjLj_Register
         U __Unwind_SjLj_Resume
         U __Unwind_SjLj_Unregister
         U __ZN9__gnu_cxx18__exchange_and_addEPVii
         U __ZNSs4_Rep10_M_destroyERKSaIcE
         U __ZNSs4_Rep20_S_empty_rep_storageE
         U __ZNSsC1EPKcRKSaIcE
         U ___gxx_personality_sj0
00003054 D ___progname
00002f58 t ___restore_vfp_d8_d15_regs
00002f50 t ___save_vfp_d8_d15_regs
00001000 A __mh_execute_header
00003050 D _environ
         U _exit
00002e9c t _main
0000301c s _pvars
         U dyld_stub_binder
00002e70 T start

build/Debug-iphoneos/AtomicsBug.app/AtomicsBug (for architecture armv7):
00002f64 s  stub helpers
00002fdc s GCC_except_table0
00003048 D _NXArgc
0000304c D _NXArgv
         U __Unwind_SjLj_Register
         U __Unwind_SjLj_Resume
         U __Unwind_SjLj_Unregister
         U __ZN9__gnu_cxx18__exchange_and_addEPVii
         U __ZNSs4_Rep10_M_destroyERKSaIcE
         U __ZNSs4_Rep20_S_empty_rep_storageE
         U __ZNSsC1EPKcRKSaIcE
         U ___gxx_personality_sj0
00003054 D ___progname
00001000 A __mh_execute_header
00003050 D _environ
         U _exit
00002eb0 t _main
0000301c s _pvars
         U dyld_stub_binder
00002e84 T start</pre>
<p>Base SDK = 3.2, iPhone OS Deployment Target = 3.1:</p>
<pre class="brush: plain; title: ; notranslate">nm build/Debug-iphoneos/AtomicsBug.app/AtomicsBug 

build/Debug-iphoneos/AtomicsBug.app/AtomicsBug (for architecture armv6):
00002f64 s  stub helpers
00002fdc s GCC_except_table0
00003048 D _NXArgc
0000304c D _NXArgv
         U __Unwind_SjLj_Register
         U __Unwind_SjLj_Resume
         U __Unwind_SjLj_Unregister
         U __ZNSs4_Rep10_M_destroyERKSaIcE
         U __ZNSs4_Rep20_S_empty_rep_storageE
         U __ZNSsC1EPKcRKSaIcE
         U ___gxx_personality_sj0
00003054 D ___progname
00002f58 t ___restore_vfp_d8_d15_regs
00002f50 t ___save_vfp_d8_d15_regs
         U ___sync_fetch_and_add_4
00001000 A __mh_execute_header
00003050 D _environ
         U _exit
00002ea4 t _main
0000301c s _pvars
         U dyld_stub_binder
00002e78 T start

build/Debug-iphoneos/AtomicsBug.app/AtomicsBug (for architecture armv7):
00002f74 s  stub helpers
00002fe0 s GCC_except_table0
00003044 D _NXArgc
00003048 D _NXArgv
         U __Unwind_SjLj_Register
         U __Unwind_SjLj_Resume
         U __Unwind_SjLj_Unregister
         U __ZNSs4_Rep10_M_destroyERKSaIcE
         U __ZNSs4_Rep20_S_empty_rep_storageE
         U __ZNSsC1EPKcRKSaIcE
         U ___gxx_personality_sj0
00003050 D ___progname
00001000 A __mh_execute_header
0000304c D _environ
         U _exit
00002ea8 t _main
00003018 s _pvars
         U dyld_stub_binder
00002e7c T start</pre>
<p>Notice how it&#8217;s referencing __sync_fetch_and_add_4 in the armv6 version of the binary created with base SDK 3.2? That&#8217;s <strong>bad</strong>! After a bit of digging into the header files supplied with the SDKs we find where the problem stems from &#8211; <em>it&#8217;s in the c++config.h header file</em>. Here is the difference between the file supplied with 3.1.3 SDK to the file supplied with 3.2 SDK:</p>
<pre class="brush: diff; title: ; notranslate">$ diff -u /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/usr/include/c++/4.2.1/armv6-apple-darwin9/bits/c++config.h /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk/usr/include/c++/4.2.1/armv6-apple-darwin10/bits/c++config.h

--- /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/usr/include/c++/4.2.1/armv6-apple-darwin9/bits/c++config.h  2009-12-18 09:19:17.000000000 +0000
+++ /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.2.sdk/usr/include/c++/4.2.1/armv6-apple-darwin10/bits/c++config.h   2010-03-16 05:39:05.000000000 +0000
@@ -879,7 +879,7 @@
 /* #undef _GLIBCXX_VERSION */

 /* Define if builtin atomic operations are supported on this host. */
-/* #undef _GLIBCXX_ATOMIC_BUILTINS */
+#define _GLIBCXX_ATOMIC_BUILTINS 1

 /* Define to use concept checking code from the boost libraries. */
 /* #undef _GLIBCXX_CONCEPT_CHECKS */</pre>
<p>This means that for <em>any</em> file compiled with the 3.2 SDK, GCC is told that it has the atomic builtins and so it creates code that links against them. So, there&#8217;s the problem!</p>
<p>Apple are trying to get everyone to use base SDK and iPhone OS deployment target settings rather than just building for an old SDK, but they need to make sure 100% that their SDKs are sane enough to cope with the asymmetry.</p>
<p>I have uploaded a sample project that shows the problem: <a href='http://iphone.galloway.me.uk/wp-content/uploads/2010/05/AtomicsBug-3.2.tar.gz'>AtomicsBug Project</a>.</p>
<p><strong>EDIT:</strong> I&#8217;ve found that if you use gcc-4.0 rather than gcc-4.2 then the problem doesn&#8217;t appear. This is because gcc-4.0 doesn&#8217;t use __sync_fetch_and_add for its atomic functions. (Note: this <strong>isn&#8217;t</strong> a fix but is a quick workaround for anyone experiencing the problem).</p>
<p><strong>Update [17/05/2010]:</strong> It appears that Apple are aware of the bug. Fingers crossed that it&#8217;ll be fixed in future SDKs.</p>
]]></content:encoded>
			<wfw:commentRss>http://iphone.galloway.me.uk/2010/05/iphone-sdk-bug-hunting-gcc-atomic-builtins/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>iPhone DNS Servers</title>
		<link>http://iphone.galloway.me.uk/2009/11/iphone-dns-servers/</link>
		<comments>http://iphone.galloway.me.uk/2009/11/iphone-dns-servers/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 17:08:48 +0000</pubDate>
		<dc:creator>Matt Galloway</dc:creator>
				<category><![CDATA[iPhone SDK]]></category>

		<guid isPermaLink="false">http://iphone.galloway.me.uk/?p=247</guid>
		<description><![CDATA[I have been bashing my head against the fact that on the iPhone you seemingly cannot access /etc/resolv.conf, or use functions from the Mac such as SCDynamicStore stuff. I have seen many people asking this question, a few related to the same package I was trying to use &#8211; ares. Eventually I managed to find [...]]]></description>
			<content:encoded><![CDATA[<p>I have been bashing my head against the fact that on the iPhone you seemingly cannot access /etc/resolv.conf, or use functions from the Mac such as SCDynamicStore stuff. I have seen many people asking this question, a few related to the same package I was trying to use &#8211; <a href="http://c-ares.haxx.se/">ares</a>.</p>
<p>Eventually I managed to find a fix which uses the libresolv to find the DNS servers. This seems to work just fine and I have shown the patch to ares_init.c below for reference.</p>
<pre class="brush: cpp; title: ; notranslate">#if TARGET_OS_IPHONE
#include &lt;resolv.h&gt;
#endif

...

#if TARGET_OS_IPHONE
// XXX: On the iPhone we need to get the DNS servers using resolv.h magic
if ((_res.options &amp; RES_INIT) == 0) res_init();
channel-&gt;nservers = _res.nscount;
channel-&gt;servers = malloc(channel-&gt;nservers * sizeof(struct server_state));
memset(channel-&gt;servers, '&#92;&#48;', channel-&gt;nservers * sizeof(struct server_state));

int i;
for (i = 0; i &lt; channel-&gt;nservers; i++)
{
    memcpy(&amp;channel-&gt;servers[i].addr, &amp;_res.nsaddr_list[i].sin_addr, sizeof(struct in_addr));
}
#endif</pre>
<p><em>[As per most of my posts these days, this is just a brain dump. I'll try to pad it out as soon as possible]</em></p>
]]></content:encoded>
			<wfw:commentRss>http://iphone.galloway.me.uk/2009/11/iphone-dns-servers/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Compiling Static Libraries for iPhone / Simulator</title>
		<link>http://iphone.galloway.me.uk/2009/11/compiling-static-libraries-for-iphone-simulator/</link>
		<comments>http://iphone.galloway.me.uk/2009/11/compiling-static-libraries-for-iphone-simulator/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 10:16:29 +0000</pubDate>
		<dc:creator>Matt Galloway</dc:creator>
				<category><![CDATA[iPhone SDK]]></category>

		<guid isPermaLink="false">http://iphone.galloway.me.uk/?p=245</guid>
		<description><![CDATA[3rd party libraries used by iPhone applications are required to be linked statically. In order to build such a library for the device and simulator you need to set up your environment such that it will cross compile for the two different environments. This is as simple as using the following set of &#8216;exports&#8217; as [...]]]></description>
			<content:encoded><![CDATA[<p>3rd party libraries used by iPhone applications are required to be <a href="http://en.wikipedia.org/wiki/Static_library">linked statically</a>. In order to build such a library for the device and simulator you need to set up your environment such that it will <a href="http://en.wikipedia.org/wiki/Cross_compile">cross compile</a> for the two different environments. This is as simple as using the following set of &#8216;exports&#8217; as defined below.</p>
<pre class="brush: bash; title: ; notranslate">
# Defines to set up environment
export DEVROOT=${ROOTDIR}/Platforms/${PLATFORM}.platform/Developer
export SDKROOT=${DEVROOT}/SDKs/${PLATFORM}${MAX_VERSION}.sdk
export CC=$DEVROOT/usr/bin/gcc
export LD=$DEVROOT/usr/bin/ld
export CPP=$DEVROOT/usr/bin/cpp
export CXX=$DEVROOT/usr/bin/g++
export AR=$DEVROOT/usr/bin/ar
export LIBTOOL=$DEVROOT/usr/bin/libtool
export AS=$DEVROOT/usr/bin/as
export NM=$DEVROOT/usr/bin/nm
export CXXCPP=$DEVROOT/usr/bin/cpp
export RANLIB=$DEVROOT/usr/bin/ranlib
export OPTFLAG=&quot;-O${OPT}&quot;
export COMMONFLAGS=&quot;${ARCH} -pipe $OPTFLAG -gdwarf-2 -no-cpp-precomp -mthumb -isysroot ${SDKROOT} -miphoneos-version-min=${MIN_VERSION}&quot;
export LDFLAGS=&quot;${COMMONFLAGS} -L${HOME}${SDKROOT}/usr/lib&quot;
export CFLAGS=&quot;${COMMONFLAGS} -fvisibility=hidden&quot;
export CXXFLAGS=&quot;${COMMONFLAGS} -fvisibility=hidden -fvisibility-inlines-hidden&quot;
</pre>
<p>This uses a few defines which need to be different for the device vs. simulator. Below are what you might want to use for each one. Note that MIN_VERSION, MAX_VERSION and OPT can all be set to control what SDK versions and the level of optimisation is used.</p>
<p>Device:</p>
<pre class="brush: bash; title: ; notranslate">
# Variables
export ROOTDIR=&quot;/Developer&quot;
export PLATFORM=&quot;iPhoneOS&quot;
export ARCH=&quot;-arch armv6 -arch armv7&quot;
export MIN_VERSION=&quot;3.1&quot;
export MAX_VERSION=&quot;4.0&quot;
export OPT=&quot;3&quot;
</pre>
<p>Simulator:</p>
<pre class="brush: bash; title: ; notranslate">
# Variables
export ROOTDIR=&quot;/Developer&quot;
export PLATFORM=&quot;iPhoneSimulator&quot;
export ARCH=&quot;-arch i386&quot;
export MIN_VERSION=&quot;3.1&quot;
export MAX_VERSION=&quot;4.0&quot;
export OPT=&quot;3&quot;
</pre>
<p>Once you have set the environment, you just need to use &#8216;make&#8217; to build the library. If the library is using autoconf, then you will need to use the following &#8216;./configure&#8217; options:</p>
<p>Device:</p>
<pre class="brush: bash; title: ; notranslate">./configure --host=arm-apple-darwin9 --prefix=${HOME}/${SDKROOT} --enable-shared=no --disable-dependency-tracking</pre>
<p>[Note: --disable-dependency-tracking is required because gcc can't use dependency tracking when building for 2 architectures at the same time (i.e. armv6 and armv7).]</p>
<p>Simulator:</p>
<pre class="brush: bash; title: ; notranslate">./configure --host=i386-apple-darwin --prefix=${HOME}/${SDKROOT} --enable-shared=no</pre>
<p>Then just use &#8216;make&#8217; and &#8216;make install&#8217; to build the library! It really is as easy as that <img src='http://iphone.galloway.me.uk/wordpress/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> .</p>
<p><em>[Other libraries may require other configure options, but I can't cover them all here as they are often different]</em></p>
<p><b>EDIT: I&#8217;ve edited the defines above to be a bit clearer and factor out the common bits from the device/simulator.</b></p>
]]></content:encoded>
			<wfw:commentRss>http://iphone.galloway.me.uk/2009/11/compiling-static-libraries-for-iphone-simulator/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Compiling Boost for the iPhone</title>
		<link>http://iphone.galloway.me.uk/2009/11/compiling-boost-for-the-iphone/</link>
		<comments>http://iphone.galloway.me.uk/2009/11/compiling-boost-for-the-iphone/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 10:04:10 +0000</pubDate>
		<dc:creator>Matt Galloway</dc:creator>
				<category><![CDATA[iPhone SDK]]></category>

		<guid isPermaLink="false">http://iphone.galloway.me.uk/?p=243</guid>
		<description><![CDATA[Updates: boost-1.44: For compiling Boost 1.44 please see my new post. For a recent project I&#8217;ve had to compile the Boost C++ library for the iPhone. Much of the Boost library is header files so they are fine as nothing needs to be done, they just get copied into place, but the bits which do [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Updates:</strong><br />
<em>boost-1.44</em>:<br />
<strong>For compiling Boost 1.44 please see my <a href="http://iphone.galloway.me.uk/2010/09/compiling-boost-1-44-for-iphone/">new post</a>.</strong></p>
<p>For a recent project I&#8217;ve had to compile the <a href="http://www.boost.org">Boost C++ library</a> for the iPhone. Much of the Boost library is header files so they are fine as nothing needs to be done, they just get copied into place, but the bits which do need compiling are a bit trickier. So I thought I&#8217;d share my experiences here.</p>
<p>First you need to download Boost (I went for version 1.40) from <a href="http://www.boost.org">http://www.boost.org</a>. Then you need to edit some of the Boost.Jam configuration. This involves creating a user-config.jam file in your home directory like so:</p>
<pre class="brush: bash; title: ; notranslate">~/user-config.jam:
using darwin : 4.2.1~iphone
   : /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv6
   : &lt;striper&gt;
   : &lt;architecture&gt;arm &lt;target-os&gt;iphone &lt;macosx-version&gt;iphone-3.0
   ;

using darwin : 4.2.1~iphonesim
   : /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386
   : &lt;striper&gt;
   : &lt;architecture&gt;x86 &lt;target-os&gt;iphone &lt;macosx-version&gt;iphonesim-3.0
   ;</pre>
<p>Then edit tools/build/v2/tools/darwin.jam and add in the following under the macosx-versions variable:</p>
<pre class="brush: bash; title: ; notranslate">.macosx-versions =
    10.6 10.5 10.4 10.3 10.2 10.1
    iphone-3.1 iphonesim-3.1
    iphone-3.0 iphonesim-3.0
    iphone-2.3 iphonesim-2.3
    iphone-2.2 iphonesim-2.2
    iphone-2.1 iphonesim-2.1
    iphone-2.0 iphonesim-2.0
    iphone-1.x
    ;</pre>
<p>Then, you need to use the following lines to build Boost for iPhoneOS and iPhoneSimulator respectively:</p>
<pre class="brush: bash; title: ; notranslate">./bjam --prefix=~/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/usr toolset=darwin architecture=arm target-os=iphone macosx-version=iphone-3.0 define=_LITTLE_ENDIAN link=static include=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/usr/include/c++/4.2.1/armv6-apple-darwin9 install</pre>
<pre class="brush: bash; title: ; notranslate">./bjam --prefix=~/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr toolset=darwin architecture=x86 target-os=iphone macosx-version=iphonesim-3.0 link=static include=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr/include/c++/4.2.1/i686-apple-darwin9 install</pre>
<p>It&#8217;s worth noting that at this stage everything will compile for the simulator but not for the device. This is because the device is missing two header files &#8211; &#8216;bzlib.h&#8217; and &#8216;crt_externs.h&#8217;. To make it compile for the device simply copy these files from &#8216;/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk/usr/include/&#8217; into your Boost folder and then everything should compile fine. I have no idea why Apple have omitted these header files from the device. The libraries are there, just the header files missing. I&#8217;ve created a bug on Radar for this, so please also do the same if you encounter this problem such that Apple will listen and include them.</p>
<p>That installs the files in &#8216;~/Developer/Platforms/iPhone(OS|Simulator).platform/Developer/SDKs/iPhone(OS|Simulator)3.0.sdk/usr&#8217; which was where I wanted mine to go, but feel free to change that to wherever you want the libraries to end up. I did it this way because I created a custom SDK and then include that from iPhone projects within XCode.</p>
<p><strong>boost-1.42</strong>:<br />
Since Boost has been updated, I thought I&#8217;d extend this article to explain how to compile boost-1.42 for the iPhone. Boost themselves have gone a long way to do everything for you now, so there&#8217;s much less that needs to be done. You now need to do this:</p>
<pre class="brush: bash; title: ; notranslate">~/user-config.jam
using darwin : 4.2.1~iphone
   : /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 -arch armv7 -mthumb -fvisibility=hidden -fvisibility-inlines-hidden
   : &lt;striper&gt;
   : &lt;architecture&gt;arm &lt;target-os&gt;iphone &lt;macosx-version&gt;iphone-3.1.3
   ;

using darwin : 4.2.1~iphonesim
   : /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -fvisibility=hidden -fvisibility-inlines-hidden
   : &lt;striper&gt;
   : &lt;architecture&gt;x86 &lt;target-os&gt;iphone &lt;macosx-version&gt;iphonesim-3.1.3
   ;</pre>
<p>Then edit tools/build/v2/tools/darwin.jam and add in the following under the macosx-versions variable:</p>
<pre class="brush: bash; title: ; notranslate">tools/build/v2/tools/darwin.jam
## The MacOSX versions we can target.
.macosx-versions =
    10.6 10.5 10.4 10.3 10.2 10.1
    iphone-3.2 iphonesim-3.2
    iphone-3.1.3 iphonesim-3.1.3
    iphone-3.1.2 iphonesim-3.1.2
    iphone-3.1 iphonesim-3.1
    iphone-3.0 iphonesim-3.0
    iphone-2.2.1 iphonesim-2.2.1
    iphone-2.2 iphonesim-2.2
    iphone-2.1 iphonesim-2.1
    iphone-2.0 iphonesim-2.0
    iphone-1.x
    ;</pre>
<pre class="brush: bash; title: ; notranslate">
# &lt;grab source from boost.org&gt;
tar xzf boost_1_42_0.tar.gz
cd boost_1_42_0
./bootstrap.sh

# Install for device:
./bjam --prefix=${HOME}/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.3.sdk/usr toolset=darwin architecture=arm target-os=iphone macosx-version=iphone-3.1.3 define=_LITTLE_ENDIAN link=static install

# Install for simulator
./bjam –-prefix=${HOME}/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.3.sdk/usr toolset=darwin architecture=x86 target-os=iphone macosx-version=iphonesim-3.1.3 link=static install
</pre>
]]></content:encoded>
			<wfw:commentRss>http://iphone.galloway.me.uk/2009/11/compiling-boost-for-the-iphone/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Android vs. iPhone (+ other smartphones)</title>
		<link>http://iphone.galloway.me.uk/2009/10/android-vs-iphone-other-smartphones/</link>
		<comments>http://iphone.galloway.me.uk/2009/10/android-vs-iphone-other-smartphones/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 12:42:38 +0000</pubDate>
		<dc:creator>Matt Galloway</dc:creator>
				<category><![CDATA[iPhone SDK]]></category>

		<guid isPermaLink="false">http://iphone.galloway.me.uk/?p=217</guid>
		<description><![CDATA[I found an article by Andrew Nusca on ZDNet which caught my eye. He gives 5 points as to why Android will beat other smartphones. I&#8217;d like to comment on them: * Google backs Android, a major pipeline for its cloud services. Yes, true, but Apple backs the iPhone and clearly has cloudy things in [...]]]></description>
			<content:encoded><![CDATA[<p>I found <a href="http://blogs.zdnet.com/gadgetreviews/?p=8126">an article by Andrew Nusca</a> on ZDNet which caught my eye. He gives 5 points as to why Android will beat other smartphones. I&#8217;d like to comment on them:</p>
<p><em>* Google backs Android, a major pipeline for its cloud services.</em><br />
Yes, true, but Apple backs the iPhone and clearly has cloudy things in the pipeline with it&#8217;s building of a new <a href="http://news.zdnet.co.uk/hardware/0,1000000091,39722453,00.htm">billion dollar data centre</a>.</p>
<p><em>* Android is improving rapidly. The Cupcake 1.5 release was well-received, and Donut 1.6 has already been sent over the air to handset owners.</em><br />
iPhone OS is improving all the time as well. Granted Android is faster, but for developers I think it&#8217;s great how Apple release iPhone OS. It means you have time to get ready for each release to make sure all apps work properly on each version.</p>
<p><em>* Android is open, making it easier to quickly gain developers’ support.</em><br />
The iPhone SDK is free to download and only £59 to become a member of the full developer program. It&#8217;s really not that much of a barrier.</p>
<p><em>* Android will run on phones from several manufacturers, which will help it quickly spread through the marketplace. HTC, Motorola and Samsung are already supporting handsets.</em><br />
This is a bad thing in my opinion. I absolutely love the fact that with the iPhone you know <strong>exactly</strong> what devices the app will run on, and you know every exact specification. Only if the hardware manufacturer is the SDK provider, can this happen 100%.</p>
<p><em>* Android combines the best of what’s out there. It’s open, but it offers iPhone-like menus and apps, with Windows Mobile-esque icons, with Palm Pre-like multitasking. There’s another arms race afoot — the battle among Android handset makers as to which company can squeeze the most out of the OS.</em><br />
Is that a good thing to mix-and-match? I prefer having a rock solid, stable OS, built by one of the best software companies in the world. Furthermore, they build the hardware as well so they know how to eek every last bit of power out of the hardware to provide software developers with one of the best platforms to develop for.</p>
]]></content:encoded>
			<wfw:commentRss>http://iphone.galloway.me.uk/2009/10/android-vs-iphone-other-smartphones/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UITableViewCell Geometry</title>
		<link>http://iphone.galloway.me.uk/2009/08/uitableviewcell-geometry/</link>
		<comments>http://iphone.galloway.me.uk/2009/08/uitableviewcell-geometry/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 18:18:34 +0000</pubDate>
		<dc:creator>Matt Galloway</dc:creator>
				<category><![CDATA[iPhone SDK]]></category>

		<guid isPermaLink="false">http://iphone.galloway.me.uk/?p=210</guid>
		<description><![CDATA[I keep needing to find this out, so I thought I&#8217;d post it here so I can refer to it. This is the geometry of the UILabels for each of the UITableViewCellStyles: UITableViewCellStyleValue2 textLabel: 10.000000 : 14.000000 : 68.000000 : 16.000000 detailTextLabel: 83.000000 : 12.000000 : 207.000000 : 0.000000]]></description>
			<content:encoded><![CDATA[<p>I keep needing to find this out, so I thought I&#8217;d post it here so I can refer to it. This is the geometry of the UILabels for each of the UITableViewCellStyles:</p>
<p><b>UITableViewCellStyleValue2</b><br />
<i>textLabel:</i> 10.000000 : 14.000000 : 68.000000 : 16.000000<br />
<i>detailTextLabel:</i> 83.000000 : 12.000000 : 207.000000 : 0.000000</p>
]]></content:encoded>
			<wfw:commentRss>http://iphone.galloway.me.uk/2009/08/uitableviewcell-geometry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple Developer Certificates</title>
		<link>http://iphone.galloway.me.uk/2009/08/multiple-developer-certificates/</link>
		<comments>http://iphone.galloway.me.uk/2009/08/multiple-developer-certificates/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 22:03:59 +0000</pubDate>
		<dc:creator>Matt Galloway</dc:creator>
				<category><![CDATA[iPhone SDK]]></category>

		<guid isPermaLink="false">http://iphone.galloway.me.uk/?p=201</guid>
		<description><![CDATA[I had the need to code sign using a different developer accounts and my initial thoughts were that it was going to be tricky. But it seems that Apple have actually made it easy now! The problem comes that during code-sign, it searches for certificates by the name, which leads to &#8220;iPhone Developer: Matthew Galloway&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>I had the need to code sign using a different developer accounts and my initial thoughts were that it was going to be tricky. But it seems that Apple have actually made it easy now!</p>
<p>The problem comes that during code-sign, it searches for certificates by the name, which leads to &#8220;iPhone Developer: Matthew Galloway&#8221; matching both certificates you have installed (one for each developer account). But Apple have at some point changed their certificate signing process and they add a number of the end of the common name on the certificate. This means that each certificate is unique even if it&#8217;s for the same physical developer.</p>
<p>One thing to note is that I used the same private key to generate the CSR for both certificates. I&#8217;m not sure what the implications would be for using separate private keys, but I can&#8217;t imagine it would make a difference.</p>
<p>I guess Apple had to do this really because lots of companies would have ended up with problems I&#8217;m sure.</p>
<p>So for anyone wondering if they can use multiple developer certificates, then just go for it, it should work!</p>
]]></content:encoded>
			<wfw:commentRss>http://iphone.galloway.me.uk/2009/08/multiple-developer-certificates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

