<?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>musicalgeometry &#187; XCode</title>
	<atom:link href="http://www.musicalgeometry.com/archives/category/xcode/feed" rel="self" type="application/rss+xml" />
	<link>http://www.musicalgeometry.com</link>
	<description>sound, code, &#38; DIY tech</description>
	<lastBuildDate>Sat, 24 Jul 2010 16:32:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Xcode Script For Creating Properties From Instance Variables For UIViewController</title>
		<link>http://www.musicalgeometry.com/archives/904</link>
		<comments>http://www.musicalgeometry.com/archives/904#comments</comments>
		<pubDate>Wed, 24 Feb 2010 07:26:29 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[OSX]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[XCode]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=904</guid>
		<description><![CDATA[One of my favourite blogs on the net is Matt Gallagher&#8217;s Cocoa with Love. Today I was investigating ways to speed up my workflow in Xcode and I found a great mixed Perl and AppleScript script already written by Matt a &#8230; <a href="http://www.musicalgeometry.com/archives/904">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of my favourite blogs on the net is Matt Gallagher&#8217;s <a href="http://cocoawithlove.com/">Cocoa with Love</a>. Today I was investigating ways to speed up my workflow in Xcode and I found a great mixed Perl and AppleScript script already written by Matt a couple of years ago.</p>
<div id="attachment_905" class="wp-caption alignnone" style="width: 637px"><a href="http://cocoawithlove.com/"><img class="size-full wp-image-905 " style="border: 1px solid black;" title="cocoawithlove" src="http://www.musicalgeometry.com/wp-content/uploads/2010/02/cocoawithlove.png" alt="" width="627" height="139" /></a><p class="wp-caption-text">A fantastic resource for Cocoa, Objective-C and programming in general</p></div>
<p>The script called <a href="http://projectswithlove.com/projects/PropertyFromInstanceVariable.zip">PropertyFromInstanceVariable</a> had already been added to by a couple of other people, Yung-Luen Lan &amp; <a href="http://github.com/mschrag/xcode_property_from_ivar">Mike Schrag</a> and <a href="http://www.bernard-web.com/pierre/blog/">Pierre Bernard</a> and I have now shaped it for my own specific needs, and possibly yours too.</p>
<p>The tedium I was trying to eliminate was the process of creating Objective-C properties from instance variables and doing basic memory management on them. This is a repetitive process that seems more appropriate to hand off to the machine.</p>
<p>Matt&#8217;s script allows you to take an instance variable defined in your interface file and automatically create a property for it, synthesize the property in the implementation, add a release statement and set the property to NULL in the dealloc method.</p>
<p>For example, running the script on this:</p>
<pre><code>NSString *myString;</code></pre>
<p>would automatically create this in the interface:</p>
<pre><code>@property (nonatomic, retain) NSString *myString;</code></pre>
<p>this at the top of the implementation:</p>
<pre><code>@synthesize myString;</code></pre>
<p>and adds these two lines to the dealloc method:</p>
<pre><code>[myString release];
myString = NULL;</code></pre>
<p>Because this script was written before the viewDidUnload method had been added to the UIViewController class it didn&#8217;t make use of the viewDidUnload method. I wanted to update it to set the retaining references to subviews in the view hierarchy to nil. These reference properties may have been set through IBOutlets when loading a nib or programmatically in the loadView method.</p>
<p>I have now modified the script to reflect my own coding habits. It still creates the property, synthesizes it and adds a release to the dealloc method, but if the class is a subclass of UIViewController then this is placed in viewDidUnload like so:</p>
<pre><code>self.myString = nil;</code></pre>
<p>This script can be run on multiple instance variables at once and greatly cuts down on the time it takes to set up a new class. Instructions on installing the script can be found <a href="http://cocoawithlove.com/2008/12/instance-variable-to-synthesized.html">here</a>.</p>
<p>You can get my fork of the script on <a href="http://github.com/jj0b/xcode_property_from_ivar">github</a>.</p>
<p>NOTE: I have updated to script and edited this post to reflect those changes. All links are to the most recent version.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/904/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>iPhone Camera Overlay App With Custom Button Example</title>
		<link>http://www.musicalgeometry.com/archives/821</link>
		<comments>http://www.musicalgeometry.com/archives/821#comments</comments>
		<pubDate>Fri, 11 Dec 2009 05:26:37 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[AR]]></category>
		<category><![CDATA[XCode]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=821</guid>
		<description><![CDATA[There seems to be a lot of interest recently in making apps that use a camera view with an overlay for augmented reality or what some might call pseudo-augmented reality applications (because often these apps just layer an image or &#8230; <a href="http://www.musicalgeometry.com/archives/821">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There seems to be a lot of interest recently in making apps that use a camera view with an overlay for augmented reality or what some might call pseudo-augmented reality applications (because often these apps just layer an image or data on a camera view). I wasn&#8217;t satisfied with the few examples I found on the topic so I decided to try one myself. I will endeavour to make it as clear as I can and show you how to make a custom button while I am at it, but I do assume a basic knowledge of Objective-C and iPhone app development in Xcode.</p>
<div id="attachment_823" class="wp-caption alignnone" style="width: 210px"><a href="http://www.musicalgeometry.com/wp-content/uploads/2009/12/Screenshot-2009.12.10-18.46.38.png"><img class="size-medium wp-image-823 " style="border: 1px solid black;" title="Screenshot 2009.12.10 18.46.38" src="http://www.musicalgeometry.com/wp-content/uploads/2009/12/Screenshot-2009.12.10-18.46.38-200x300.png" alt="OverlayViewTester screenshot" width="200" height="300" /></a><p class="wp-caption-text">OverlayViewTester screenshot</p></div>
<p>So first I will describe the OverlayViewTester app. Basically it just overlays some cool looking red selection braces on a camera view and has a button that when pressed performs a &#8216;scan&#8217; for two seconds and lets you know by adding a &#8220;Scanning&#8230;&#8221; label at the top of the screen during that time. So really it does nothing, but it looks good and is a good first step to making a more fun and interesting interactive camera overlay app.</p>
<p>To get started download the source code from <a href="http://github.com/jj0b/OverlayViewTester">GitHub</a>. Next I will go through the files in the project and present the juicy bits. Consult the source code you downloaded for the full meal deal.</p>
<p><strong>OverlayViewTesterApDelegate</strong></p>
<p>Taking a look at the project we start with a typical app delegate, OverlayViewTesterAppDelegate which loads the OverlayViewController. Nothing monumental there so I won&#8217;t bother reproducing it here.</p>
<p><strong>OverlayViewController</strong></p>
<p>Now on to the OverlayViewController where we create the camera view.</p>
<p>In the interface, <em>OverlayViewController.h</em>: we define some constants:</p>
<pre><code>// Transform values for full screen support:
#define CAMERA_TRANSFORM_X 1
#define CAMERA_TRANSFORM_Y 1.12412

// iPhone screen dimensions:
#define SCREEN_WIDTH  320
#define SCREEN_HEIGTH 480</code></pre>
<p>In the implementation, <em>OverlayViewController.m</em> there is a bit of a GOTCHA. The line</p>
<pre><code>[self presentModalViewController:picker animated:YES];</code></pre>
<p>must be called in  <em>viewDidAppear:</em> not in a <em>viewDidLoad:</em> method. Here it is:</p>
<pre><code>- (void) viewDidAppear:(BOOL)animated {
    OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];

    // Create a new image picker instance:
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];

    // Set the image picker source:
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    // Hide the controls:
    picker.showsCameraControls = NO;
    picker.navigationBarHidden = YES;

    // Make camera view full screen:
    picker.wantsFullScreenLayout = YES;
    picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);

    // Insert the overlay:
    picker.cameraOverlayView = overlay;

    // Show the picker:
    [self presentModalViewController:picker animated:YES];
    [picker release];

    [super viewDidAppear:YES];
}</code></pre>
<p>I think the comments make it clear what is going on there.</p>
<p><strong>OverlayView</strong></p>
<p>Next lets look at the custom subclass of UIView called OverlayView. This is where we actually create our overlay.</p>
<p>In the interface, <em>OverlayView.h</em> we declare two new methods:</p>
<pre><code>- (void)scanButtonTouchUpInside;
- (void)clearLabel:(UILabel *)label;</code></pre>
<p>Here are the important parts of the implementation, <em>OverlayView.m</em>:</p>
<pre><code>- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Clear the background of the overlay:
	self.opaque = NO;
	self.backgroundColor = [UIColor clearColor];

	// Load the image to show in the overlay:
	UIImage *overlayGraphic = [UIImage imageNamed:@"overlaygraphic.png"];
	UIImageView *overlayGraphicView = [[UIImageView alloc] initWithImage:overlayGraphic];
	overlayGraphicView.frame = CGRectMake(30, 100, 260, 200);
	[self addSubview:overlayGraphicView];
	[overlayGraphicView release];

	ScanButton *scanButton = [[ScanButton alloc] initWithFrame:CGRectMake(130, 320, 60, 30)];

	// Add a target action for the button:
	[scanButton addTarget:self action:@selector(scanButtonTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
	[self addSubview:scanButton];
    }
    return self;
}

- (void) scanButtonTouchUpInside {
    UILabel *scanningLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 50, 120, 30)];
    scanningLabel.backgroundColor = [UIColor clearColor];
    scanningLabel.font = [UIFont fontWithName:@"Courier" size: 18.0];
    scanningLabel.textColor = [UIColor redColor];
    scanningLabel.text = @"Scanning...";

    [self addSubview:scanningLabel];

    [self performSelector:@selector(clearLabel:) withObject:scanningLabel afterDelay:2];

    [scanningLabel release];
}

- (void)clearLabel:(UILabel *)label {
    label.text = @"";
}</code></pre>
<p>Notice that we have used an instance of ScanButton which we will get to next. When the ScanButton detects a UIControlEventTouchUpInside it calls the scanButtonTouchUpInside method which places a label on the screen for 2 seconds.</p>
<p><strong>ScanButton</strong></p>
<p>So finally we are left with our ScanButton. You might think that for a custom button we would subclass UIButton, but unless you really want to use the UIBUtton method setTitle:ForState it is recommended that you subclass UIControl. It will save you a world of hurt.</p>
<p>Here is the interface, <em>ScanButton.h</em>:</p>
<pre><code>#import &lt;Foundation/Foundation.h&gt;

@interface ScanButton : UIControl {
}

- (void)buttonPressed;

@end</code></pre>
<p>I put the buttonPressed method in here for future use. It is meant to be used to change things related to the button itself and not the actions associated with the button in the OverlayViewController. You could for example use it to have the button&#8217;s image or state or both toggle.</p>
<p>Last but not least we have the implementation, <em>ScanButton.m</em>:</p>
<pre><code>#import "ScanButton.h"

@implementation ScanButton

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
	// Set button image:
	UIImageView *buttonImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
	buttonImage.image = [UIImage imageNamed:@"scanbutton.png"];

	[self addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside]; // for future use

        [self addSubview:buttonImage];
    }
    return self;
}

- (void)buttonPressed {
    // TODO: Could toggle a button state and/or image
}

@end</code></pre>
<p>So there you have it. A custom camera overlay and a custom button. I hope that with this code you will be well on your way to writing much more useful, interesting and creative apps than this example. Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/821/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Change Your Company Name In XCode</title>
		<link>http://www.musicalgeometry.com/archives/766</link>
		<comments>http://www.musicalgeometry.com/archives/766#comments</comments>
		<pubDate>Sun, 25 Oct 2009 06:46:39 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[OSX]]></category>
		<category><![CDATA[XCode]]></category>
		<category><![CDATA[command line]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=766</guid>
		<description><![CDATA[If you want your own company name to be automatically included in your XCode source files instead of this: // // helloworld.m // helloworld // // Created by John Smith on 24/10/09. // Copyright __MyCompanyName__ 2009. All rights reserved. // &#8230; <a href="http://www.musicalgeometry.com/archives/766">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you want your own company name to be automatically included in your XCode source files instead of this:</p>
<pre><code>//
//  helloworld.m
//  helloworld
//
//  Created by John Smith on 24/10/09.
//  Copyright __MyCompanyName__ 2009. All rights reserved.
//</code></pre>
<p>then it is time to open up your Terminal app.</p>
<div id="attachment_778" class="wp-caption alignnone" style="width: 310px"><a href="http://www.musicalgeometry.com/wp-content/uploads/2009/10/Terminal-2.png"><img class="size-medium wp-image-778" style="border: 1px solid black;" title="Terminal 2" src="http://www.musicalgeometry.com/wp-content/uploads/2009/10/Terminal-2-300x212.png" alt="Terminal 2" width="300" height="212" /></a><p class="wp-caption-text">OSX Terminal app</p></div>
<p>You will find it at ~/Applications/Utilities/Terminal.app.</p>
<p>Enter the following in the open terminal (replacing the company name with yours):</p>
<pre><code>defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{"ORGANIZATIONNAME" = "Smith Incorporated";}'</code></pre>
<p>Now when you create new source files in XCode you will see this:</p>
<pre><code>//
//  helloworld.m
//  helloworld
//
//  Created by John Smith on 24/10/09.
//  Copyright Smith Incorporated 2009. All rights reserved.
//</code></pre>
<p>Much better.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/766/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
