Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Friday, May 15, 2009

Creating a NIB-free Cocoa Touch application in XCode

Do you program Cocoa Touch apps? Do you hate that all of the project templates expect you to be using interface builder? Me too! Here's how to get rid off all IB dependencies in your app!


Why would you want to do this?
Because programatically creating interfaces is considerably easier to deal with. (In my opinion anyway.)

How do you do it?
I'm glad you asked. It's a little bit of a hassle, BUT it's worth it.

So here we go.

1) Create a new project in XCode using the "Window Based Application" template (Title it whatever the heck you want. For the sake of this tutorial I'm calling it "NoNib")

2) Looking at all the contents of your new app you should see:
CoreGraphics.framework
Foundation.framework
Info.plist
main.m
MainWindow.xib
NoNib.app
NoNib_Prefix.pch
NoNibAppDelegate.h
NoNibAppDelegate.m
UIKit.framework

Go ahead and delete MainWindow.xib (the NIB) and send it to the trash. You don't need it.

3) Open Info.plist
Select the line with key "Main nib file base name" and delete it

4) Open main.m
Find the line "int retVal = UIApplicationMain(argc, argv, nil, nil);" and replace the second line with the name of your AppDelegate as a string (example "int retVal = UIApplicationMain(argc, argv, nil, @"NoNibAppDelegate");")

5) Open your AppDelegate.h file and remove the line "@property (nonatomic, retain) IBOutlet UIWindow *window;"

6) Open your AppDelegate.m file
Remove the line "@synthesize window;"
Then, within - (void)applicationDidFinishLaunching:(UIApplication *)application before the line that says "[window makeKeyAndVisible];" add this line "window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];"

7) Build and Go
If it doesn't build without error, you most likely missed something in the above steps. Otherwise it should launch in the simulator as a completely empty app with a black background. CONGRATULATIONS! You can now start building Views and View Controllers without any of those icky interface builder remnants dragging you down.

Friday, December 5, 2008

My first contribution to the Arduino Playground

The Arduino: Playground has given me so much that I felt it was time to contribute back.

So I wrote this article: Arduino + PERL

Thursday, December 4, 2008

Semaphore-bot v3.0.alpha


Untitled from Andrew Parnell on Vimeo.


Semaphore-bot 3.0 is on its way!

I went through and rewrote the control code from the ground up in PERL, letting me eliminate processing from the equation all together and making everything run more efficiently.

I also built some gear boxes so that I no longer need to stack servos.

All in all, major improvements all around.

Tomorrow I rebuild the casing and get it ready for show.

Interested in the script? Click here!

...actually... [PERL here] [Arduino here]

Saturday, November 8, 2008

Practicing What I Preach

working title

Considering how much I've been talking / thinking / ranting about flash websites lately, I figured I really should do what I talk about. That is, if I'm going to champion standards based sites, I should learn to do the shiny effects using standards based tech.

So that's what I'm doing, currently making a css, xhtml, javascript (prototype & scriptaculous at the moment) clone of the flash site that Nina has been working on.

...thus far I've got the little bar of posts. But hey, I literally just picked up scriptaculous and prototype last night.

Wednesday, October 22, 2008

PHP Blog Aggregator

So here's a bit of what I'm working on for the backend of this year's Digital Arts BFA website.

It takes this xml (provided by my feed burner NewsLife) and dumps all the feeds into one very large xml file.

<blogs>

<outline text="Nina Pavlich" title="Nina Pavlich" description="" type="RSS" version="RSS" htmlUrl="http://www.ninalp.com/bfarts" xmlUrl="http://www.ninalp.com/bfarts/rss/"/>

<outline text="Zach Rose" title="Zach Rose" description="" type="RSS" version="RSS" htmlUrl="http://zachrose.tumblr.com/" xmlUrl="http://zachrose.tumblr.com/rss"/>

<outline text="Dominic C" title="Dominic C" description="" type="Atom" version="Atom" htmlUrl="http://dom4art225.blogspot.com/" xmlUrl="http://dom4art225.blogspot.com/feeds/posts/default?alt=rss"/>

<outline text="Joe" title="Joe" description="" type="Atom" version="Atom" htmlUrl="http://contempjoe.blogspot.com/" xmlUrl="http://contempjoe.blogspot.com/feeds/posts/default?alt=rss"/>

<outline text="Nathan Emerson-Verhoeven" title="Nathan Emerson-Verhoeven" description="" type="Atom" version="Atom" htmlUrl="http://nevpdx.blogspot.com/" xmlUrl="http://nevpdx.blogspot.com/feeds/posts/default?alt=rss"/>

<outline text="Sarah Moore" title="Sarah Moore" description="" type="Atom" version="Atom" htmlUrl="http://smoore5.blogspot.com/" xmlUrl="http://smoore5.blogspot.com/feeds/posts/default?alt=rss"/>

<outline text="Bryson" title="Bryson" description="" type="Atom" version="Atom" htmlUrl="http://gazzookabazookaz.blogspot.com/" xmlUrl="http://gazzookabazookaz.blogspot.com/feeds/posts/default?alt=rss"/>

<outline text="Daniel Strong" title="Daniel Strong" description="" type="Atom" version="Atom" htmlUrl="http://danielstrongdesign.blogspot.com/" xmlUrl="http://danielstrongdesign.blogspot.com/feeds/posts/default?alt=rss"/>

<outline text="Mac" title="Mac" description="" type="Atom" version="Atom" htmlUrl="http://macschubert.blogspot.com/" xmlUrl="http://macschubert.blogspot.com/feeds/posts/default?alt=rss"/>

<outline text="Travis" title="Travis" description="" type="Atom" version="Atom" htmlUrl="http://thelightisfading.blogspot.com/" xmlUrl="http://thelightisfading.blogspot.com/feeds/posts/default?alt=rss"/>

<outline text="Shawna" title="Shawna" description="" type="Atom" version="Atom" htmlUrl="http://shawna-x.blogspot.com/" xmlUrl="http://shawna-x.blogspot.com/feeds/posts/default?alt=rss"/>

<outline text="Lindsay AuCoin" title="Lindsay AuCoin" description="" type="Atom" version="Atom" htmlUrl="http://sheddingthequills.blogspot.com/" xmlUrl="http://sheddingthequills.blogspot.com/feeds/posts/default?alt=rss"/>

<outline text="Peter Baston" title="Peter Baston BFA 08" description="" type="Atom" version="Atom" htmlUrl="http://bastonbfa08.blogspot.com/" xmlUrl="http://bastonbfa08.blogspot.com/feeds/posts/default?alt=rss"/>

<outline text="Dustin Design" title="Dustin Design" description="" type="Atom" version="Atom" htmlUrl="http://dybevikda1.blogspot.com/" xmlUrl="http://dybevikda1.blogspot.com/feeds/posts/default?alt=rss"/>

<outline text="Andrew Parnell" xmlUrl="http://andrewparnell.blogspot.com/feeds/posts/default?alt=rss"/>

</blogs>


the code in question:

<?php

header ("content-type: text/xml");


$blogfeeds = array(array(),array());

$doc = new DOMDocument();

$doc->load( 'blogs.xml' );


$blogs = $doc->getElementsByTagName("outline");

$x=0;

foreach($blogs as $blog) {

$blogfeeds[$x]["path"] = $blog->getAttribute("xmlUrl");

$blogfeeds[$x]["title"] = $blog->getAttribute("text");

//array_push($blogfeeds[0], $blog->getAttribute("xmlUrl"));

//array_push($blogfeeds[1], $blog->getAttribute("text"));

$x++;

}


$out = new DOMDocument();

$out->preserveWhiteSpace = false;

$out->loadXML("<blogs/>");

for($i=0;$i<count($blogfeeds);$i++) {

$docBlog[$i] = new DOMDocument();

$docBlog[$i]->preserveWhiteSpace = false;




if(strpos($blogfeeds[$i]["path"],"blogspot.com")!==false)

{

$tot = new DOMDocument();

$tot->preserveWhiteSpace = false;

$tot->load($blogfeeds[$i]["path"].'&max-results=0');

foreach($tot->getElementsByTagNameNS('http://a9.com/-/spec/opensearch/1.1/', 'totalResults') as $openSeach_totalResults) $total = $openSeach_totalResults->nodeValue;

$blogfeeds[$i]["path"] .= "&max-results=".$total;


}


$docBlog[$i]->load($blogfeeds[$i]["path"]);

$docBlog[$i]->formatOutput = true;



foreach($docBlog[$i]->getElementsByTagName("channel") as $chan) {

//$chan->setAttribute("auth",$blogfeeds[$i]);

$in = $out->importNode($chan, true);

$in->setAttribute("auth",$blogfeeds[$i]["title"]);

$in->setAttribute("path",$blogfeeds[$i]["path"]);

$out->documentElement->appendChild($in);

}



//echo $docBlog[$i]->saveXML();

}


$out->formatOutput = true;

echo $out->saveXML();

?>




Notes:
Nina's feed seems to be home brewed, so everything she has is there. AWESOME!
Blogger feeds are by default limited to only the 25 latest entries. I subvert that by first opening them empty, so as to get the value from the openSearch:totalResults node, and then reopen them with the query string max-results=[that total] appended to them.
Tumbler seems to also truncate its feed...but I can't find any way around that (it also doesn't make any mention of this truncation.)

Still a work in progress.