<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>iPhone Software Development</title>
    <link rel="alternate" type="text/html" href="http://mauvilasoftware.com/iphone_software_development/" />
    <link rel="self" type="application/atom+xml" href="http://mauvilasoftware.com/iphone_software_development/atom.xml" />
    <id>tag:mauvilasoftware.com,2008-01-26:/iphone_software_development//3</id>
    <updated>2008-05-12T09:58:44Z</updated>
    <subtitle>Articles by 3rd party developers on how to create native software for the Apple iPhone.</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Open Source 4.1-en-release-26-r1120-20071224</generator>

<entry>
    <title>A Brief Intro to Objective C Protocols</title>
    <link rel="alternate" type="text/html" href="http://mauvilasoftware.com/iphone_software_development/2008/05/a-brief-intro-to-objective-c-p.html" />
    <id>tag:mauvilasoftware.com,2008:/iphone_software_development//3.31</id>

    <published>2008-05-12T09:36:06Z</published>
    <updated>2008-05-12T09:58:44Z</updated>

    <summary><![CDATA[This is another article aimed at the Java programmer.&nbsp; This will touch very very briefly on protocols.Protocols are Objective C's version of what is known in Java as "interfaces".&nbsp; Defining the protocolTo make one, first create a blank .h header...]]></summary>
    <author>
        <name>JLA</name>
        
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://mauvilasoftware.com/iphone_software_development/">
        <![CDATA[This is another article aimed at the Java programmer.&nbsp; This will touch very very briefly on protocols.<br /><br /><br />Protocols are Objective C's version of what is known in Java as "interfaces".&nbsp; <br /><br /><br /><b><font style="font-size: 1.25em;">Defining the protocol</font></b><br /><br />To make one, first create a blank .h header file.<br />Then type:<br /><br />@protocol MyProtocolName &lt;NSObject&gt;<br />//Method declarations go here<br />@end<br /><br />Replace "MyProtocolName" with the name of your choice.<br /><br />You will notice a couple of things...first, there are no curly brackets.&nbsp; That's because variables go in curly brackets, and protocols have no variables associated with them.<br /><br />Second, notice the "&lt;NSObject&gt;".&nbsp; This actually means that the current protocol is a derivative of the NSObject protocol.&nbsp; (There is both an NSObject class and an NSObject protocol...this is the protocol...)<br /><br />In objective C, you have protocols and categories.&nbsp; Pointed brackets are associated with protocols.&nbsp; Curved brackets (aka parentheses) are associated with categories.&nbsp;&nbsp; So just remember, "pointy protocol, curved category"...<br /><br /><font style="font-size: 1.25em;"><b>Using the protocol</b></font><br /><br />In Java, you specify that a class implements an interface with the "implements" keyword.&nbsp; In Objective C, you use the pointy brackets in the interface declaration (and by "interface" here, I mean the part of the class in the header file, not "interface" in the Java sense), following the class you extend. For example, suppose your class was normally declared like:<br />@interface CustomView : UIView<br /><br />To specify that it implements a protocol, simply change it to this:<br /><br />@interface CustomView : UIView &lt;MyProtocolName&gt;<br /><br /><br /><b><font style="font-size: 1.25em;">Protocols as variables</font></b><br /><br />Here is where it differs from Java the most.&nbsp; In Java, when declaring a variable, you would use an interface name just like you would a class.&nbsp; In Objective C, you declare a variable this way:<br /><br />id&lt;MyProtocolName&gt; myNewVariable;<br /><br />So the new type is "id&lt;MyProtocolName&gt;".&nbsp; "id" is the generic object...even though it is a pointer to an object, it doesn't have an asterisk...that's assumed.<br /><br />You can also use this notation when defining a method...e.g.<br /><br />- (void) doSomethingWithThisObject: (id&lt;MyProtocolName&gt;) aObject<br /><br />There's a lot more to protocols than what I've mentioned, but this should be enough to get you started.<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />]]>
        
    </content>
</entry>

<entry>
    <title>iPhone Low Level Audio Part II : AudioQueue Output</title>
    <link rel="alternate" type="text/html" href="http://mauvilasoftware.com/iphone_software_development/2008/04/iphone-low-level-audio-part-ii.html" />
    <id>tag:mauvilasoftware.com,2008:/iphone_software_development//3.28</id>

    <published>2008-04-12T08:10:59Z</published>
    <updated>2008-05-12T09:35:34Z</updated>

    <summary><![CDATA[Note: This entry (and everything before it) refers to firmware version 1.x...i.e. the original jaibroken/toolchain type.&nbsp; This information will be of limited use for development on firmware version 2.0+.AudioQueue HeaderTo start off, you will need the AudioQueue.h file...this wasn't included...]]></summary>
    <author>
        <name>JLA</name>
        
    </author>
    
    <category term="firmare1x" label="firmare 1.x" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="lowlevelaudio" label="low level audio" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="toolchaindevelopment" label="Toolchain development" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mauvilasoftware.com/iphone_software_development/">
        <![CDATA[<b>Note:</b> This entry (and everything before it) refers to firmware version 1.x...i.e. the original jaibroken/toolchain type.&nbsp; This information will be of limited use for development on firmware version 2.0+.<br /><br /><font style="font-size: 1.25em;"><b>AudioQueue Header</b></font><br /><br />To start off, you will need the AudioQueue.h file...this wasn't included in original toolchain releases, but it should be fairly common now.&nbsp; Check your usr/local/arm-apple-darwin/include/AudioToolbox folder for it.&nbsp; If it's not there, you will need to put it there.&nbsp; <br /><br /><font style="font-size: 1.25em;"><b>The Output Callback<br /></b></font><br />AudioQueue output is pretty straightforward.&nbsp; I strongly recommend you check out the documentation on Apple's website (in the AudioToolbox part for Leopard).&nbsp; As far as explaining goes, It does a better job than I plan on doing.&nbsp; It will also have sample sourcecode ...<b>AudioQueueTest</b>...I recommend you use this as a template...<br /><br />Notice that AudioQueue is a C routine, and not an Objective C one.&nbsp; The main function is a "callback"...if you are strictly a Java person, then you might not be familiar with this concept.&nbsp; Instead of you calling a method everytime you want to play something, you instead designate a callback function, and the system calls YOU whenever it's ready for more audio data.&nbsp; "Don't call us...we'll call you," says the sound system.<br /><br />And because this is C (and not ObjC), this callback method won't be inside of any class...it won't be "object oriented".&nbsp; It's a static function that doesn't have access to member variables of a class it may or may not be affiliated with.&nbsp; (It can still be in the same file, it just won't technically be part of that class).&nbsp; And let's assume you aren't going to use static variables...then how will this static function know what to send?&nbsp; Through a custom struct...you design it yourself, and the system will pass it to the callback whenever it is called.&nbsp; This way, you can make the callback function independent.&nbsp; <br /><br />In Apple's example, the callback is named <b>AQTestBufferCallback</b>, and the custom data struct is called <b>AQTestInfo</b>.&nbsp; Don't reuse "AQTestInfo" in the Apple example...start from scratch and make the custom struct contain whatever you think it should.<br /><br />I would get rid of all the XThrowIfError stuff...it's good to check for errors, but you can do it other ways later.&nbsp; DON'T get rid of the stuff inside of the XThrowIfError part...it cocoons the important function calls.<br /><br />The two main things you need to have in the callback are:<br />1)inCompleteAQBuffer-&gt;mAudioDataByteSize = (# of bytes you plan on putting in the queue)<br />2)AudioQueueEnqueueBuffer command...this is what actually sends the audio data off to the system.<br /><br /><br /><b><font style="font-size: 1.25em;">The Rest</font></b><br /><br />AudioQueue works by recycling a certain number of buffers.&nbsp; While it's playing the data in one, it's letting you fill a different one.&nbsp; It's sort of like the security checkpoint in an airport...those trays that you stick the carry-on bags into so they can run through the x-ray machine.&nbsp; While one is being scanned, a few others are being filled by passengers.&nbsp; After the one being scanned has made it out the other end, it is returned to be filled again.&nbsp; And so on.&nbsp; You get to choose how many buffers you want in circulation.&nbsp; I recommend 3.<br /><br />Before the callback gets called, you obviously need to inform the audio system that you will be supplying audio data.<br />This is done by these essential calls:<br /><ul><li>AudioQueueNewOutput - creates the new output system...you specify your callback function here.</li><li>AudioQueueAllocateBuffer - this is called each time you want to create a buffer.&nbsp; So you would probably want to call this three times.</li><li>AudioQueueStart - this starts the AudioQueue...surprise.</li></ul>The example has a while-loop following the AudioQueueStart.&nbsp; This is needed if you are running the AudioQueue in its own thread.&nbsp; You don't need this if either 1) you are running the AudioQueue in the main thread, or 2) you let the AudioQueue choose its own thread to run it in,&nbsp; (The latter is accomplished by passing a NULL in the AudioQueueNewOutput function instead of CFRunLoopGetCurrent).<br /><br /><ul><li>AudioQueueDispose - This isn't part of the init, but rather part of the destruction of the AudioQueue.&nbsp; This is VERY important...you need to free up the audio hardware...don't assume this will be done automatically when the program ends.</li></ul><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />.<br /><br />&nbsp; <br /><br /><br /><br /><br /><br /> ]]>
        
    </content>
</entry>

<entry>
    <title>Low level audio on the iPhone : a brief introduction</title>
    <link rel="alternate" type="text/html" href="http://mauvilasoftware.com/iphone_software_development/2008/03/low-level-audio-on-the-iphone.html" />
    <id>tag:mauvilasoftware.com,2008:/iphone_software_development//3.25</id>

    <published>2008-03-03T04:23:12Z</published>
    <updated>2008-03-03T05:31:17Z</updated>

    <summary><![CDATA[Sound on the iPhoneIf you want to do high level (i.e. "easy") audio on the iPhone, I suggest looking at the Celestial framework.&nbsp; It has what you need to load and play media files.&nbsp; You can also check out GraphicsServices...it...]]></summary>
    <author>
        <name>JLA</name>
        
    </author>
    
    <category term="audio" label="audio" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="audioqueue" label="AudioQueue" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mauvilasoftware.com/iphone_software_development/">
        <![CDATA[<font style="font-size: 1.25em;"><b>Sound on the iPhone</b></font><br /><br />If you want to do high level (i.e. "easy") audio on the iPhone, I suggest looking at the Celestial framework.&nbsp; It has what you need to load and play media files.&nbsp; You can also check out GraphicsServices...it has a method that will allow you to play a sound simply by specifying the path.<br /><br />But if you want to do low-level stuff, i.e. get down to the individual samples, then you're probably going to need AudioQueue.&nbsp; What is AudioQueue?&nbsp; It's like a brief vacation in hell...well, at least the way it's implemented on the iPhone.&nbsp; An official SDK is supposedly going to be released next week--perhaps it will shed light on this...but then again, documentation for AudioQueue is already up on Apple's website (for OS X 10.5), and it's still a bitter journey.&nbsp; Not that it's bad inherently...if you are merely looking at the API, it doesn't seem so tough.&nbsp; But the way it's implemented on the iPhone, it's hardly ideal for 3rd party developers, especially those trying to do input and output at the same time.&nbsp; Do this wrong or in the wrong thread, then the AudioQueue will stop...do this, and it will lose routing, or something will go haywire.&nbsp; Again, this may be due to my ignorance...I'm figuring it out as I go.&nbsp; [A more technical definition: AudioQueue is a group of C routines used for output and input of low-level audio.]<br /><br />Who needs AudioQueue?&nbsp; If you want to simply play wav files, then you probably don't need to use low-level stuff...stick with Celestial.&nbsp; If you want to synthesize sounds, or analyze sounds via a Fast Fourier Transform, then you probably will have to use AudioQueue.&nbsp; <br /><br />To use AudioQueue, you will need the AudioQueue.h header...if you are using the toolchain, then you will probably need to find the header yourself.&nbsp; Search for it on the Internet.&nbsp; It may be available in the XCode 3.0 download from Apple.<br /><br /><font style="font-size: 1.25em;"><b>Low-level sound in a nutshell</b></font><br />Here is a very quick intro to low level audio that isn't iPhone specific.&nbsp; If you are new to all of this, it's probably best to do a search of the Internet to learn more about audio formats, samples, etc.&nbsp; Moreover, I recommend downloading audio programs like Audacity (freeware/open source) or Goldwave (shareware) to see what all this stuff means...use these programs to experiment.<br /><br />Sound is all in your mind...what is actually out there in the real world is varying waves of pressure.&nbsp; As the air pressure rises and falls (perhaps 1000 times/sec), your eardrums move back and forth, and this is translated into sound by your brain.&nbsp; Imagine your eardrum as being horizontal...when the air pressure changes, it moves up and down.&nbsp; If you were to graph the location of the ear drum as time went by, you would end up with one of those waves you see in Audacity:<br /><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="Audio01.jpg" src="http://mauvilasoftware.com/iphone_software_development/Audio01.jpg" class="mt-image-none" style="" height="373" width="783" /></span><br /><br />(You should open up a sound in Audacity, and zoom in until the line looks curvy and smooth.)<br /><br />This is an "analog" wave.&nbsp; However, on a computer, you are going to have to be able to express this wave in terms of 0s and 1s...i.e. discrete measurements.&nbsp;&nbsp; So typically, an analog-to-digital converter measure the y-value (i.e. the height) of the wave.&nbsp; This will be repeated at a certain time interval.&nbsp; This is called "sampling", and each measurement is called a "<b>sample</b>".&nbsp; So instead of a smooth wave, you now end up with a digitized wave.<br /><br /><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="Audio02.jpg" src="http://mauvilasoftware.com/iphone_software_development/Audio02.jpg" class="mt-image-none" style="" height="192" width="504" /></span><br /><br />This is an image from Goldwave, which shows what a digitized sound wave actually looks like.&nbsp; It's not as smooth as a real one.<br /><br />The rate at which the wave is measured is called the "<b>sample rate</b>", and is expressed in units of Hertz.&nbsp; (1 Hertz means once per second.)&nbsp; A sample rate of 8000 Hz means the wave is being measured 8000 times every second, with each measurement being 0.125 milliseconds after the previous one.&nbsp; This sounds like a lot, but really, 8000 Hz isn't great in terms of quality.&nbsp; The higher the sample rate is, the "less choppy" the wave. (See image above).<br /><br />Also affecting quality is the number of bytes used to specify the y-value.&nbsp; For example, a byte (aka 8 bits) represents a value from -128 to 127.&nbsp; (This is called a "<b>signed byte</b>" because a negative sign is allowed...an "<b>unsigned byte</b>" would have values from 0 to 255).&nbsp; If we increase the sample size from 8 bits to 16 bits (i.e. 2 bytes), we'll be able to express the y-value more precisely.<br /><br />The term "<b>channel</b>" is how many simultaneous sound waves you have..."mono" means 1 channel, while "stereo" usually means 2 channels.&nbsp; Surround sound uses multiple channels.&nbsp; <br />The term "sample frame", often just "<b>frame</b>", represents a set of samples (across all the channels) that were recorded at the same time.&nbsp; Mono audio only has one channel, so a frame will only contain a single sample.&nbsp; With two channels, a frame will contain two samples.&nbsp; (Those samples will have occurred simultaneously).&nbsp;&nbsp; If you record two channels (stereo) at a sample rate of 8000 Hz for exactly 1 second...you will end up with a total of 8000 frames, but actually 16000 samples.&nbsp; (Note that sample rate usually refers to the number of samples per channel...in other words, the number of frames.)<br /><br /><br /><font style="font-size: 1.25em;"><b>What AudioQueue does</b></font><br />AudioQueue will allow you to take an array, with each member of the array representing a sample, and feed that array into it to produce sound.&nbsp;&nbsp; It also allows the reverse to occur.&nbsp; You can save the samples you get from the iPhone's microphone.&nbsp; Funiculus Musical Instrument Tuner does exactly this...it reads in samples, and continually analyzes them for pitch.<br /><b><br /><font style="font-size: 1.25em;">What AudioQueue doesn't do</font></b><br />Work.&nbsp; At least not all the time unless certain arbitrary conditions are perfect...again, this could be due to my own ignorance.<br /><br /><br />To be continued...]]>
        
    </content>
</entry>

<entry>
    <title>Snooping around the frameworks</title>
    <link rel="alternate" type="text/html" href="http://mauvilasoftware.com/iphone_software_development/2008/02/snooping-around-the-frameworks.html" />
    <id>tag:mauvilasoftware.com,2008:/iphone_software_development//3.18</id>

    <published>2008-02-08T01:19:54Z</published>
    <updated>2008-02-08T01:36:29Z</updated>

    <summary><![CDATA[Uncharted FrameworksIf you go to your iPhone file system, and look in the directory /System/Library/Frameworks, you'll see a&nbsp; list of the different frameworks available for iPhone programming.&nbsp; For ones that are mainly in ObjC (e.g. UIKit, etc), you can find...]]></summary>
    <author>
        <name>JLA</name>
        
    </author>
    
    
    <content type="html" xml:lang="en-us" xml:base="http://mauvilasoftware.com/iphone_software_development/">
        <![CDATA[<font style="font-size: 1.25em;"><b>Uncharted Frameworks</b></font><br />If you go to your iPhone file system, and look in the directory /System/Library/Frameworks, you'll see a&nbsp; list of the different frameworks available for iPhone programming.&nbsp; For ones that are mainly in ObjC (e.g. UIKit, etc), you can find a listing of all the methods on sites like Erica Sadun's.&nbsp; <br /><br />For Frameworks that are mainly in C (or C++), assuming there is no available listing somewhere on the Internet, you will have to snoop to discover the method names.&nbsp; <br /><br />Here are a few tools that you can use on the binaries within these folders to see what they contain.&nbsp; These are run from your personal computer, and should be available after you install the toolchain.&nbsp; <br /><ul><li><b>arm-apple-darwin-nm</b> : this will print out a list of symbols</li><li><b>arm-apple-darwin-otool</b> : this will (among other things) print out a disassembly</li><li><b>strings</b> : this will print out the strings in the binary</li></ul>Example of use:<br />(I'm on Windows, so I use cygwin for the prompt.)<br />$ cd /usr/local/share/iphone-filesystem/System/Library/Frameworks/AudioToolbox.framework<br />$ arm-apple-darwin-nm AudioToolbox &gt; AudioToolboxSymbols.txt<br />This will put the symbols of the AudioToolbox framework into a new file called AudioToolboxSymbols.txt.<br /><br /><font style="font-size: 1.25em;"><b>Mangled names</b></font><br />When you look at the raw list of symbols, some of the method names may look garbled.&nbsp; That's because they are "mangled"...this ensures that every method has a unique name.<br />Mangled C names will often be preceeded with an underscore.&nbsp; <br />Mangled C++ names will look something like this:<br />__ZN24MeCCA_AudioRoutingPolicy16setRoutingPolicyEPKc<br /><br />The unmangled version would be:<br />MeCCA_AudioRoutingPolicy::setRoutingPolicy(char const*)<br /><br />If you want to unmangle the names in the symbols text file you just created, you can use a command called <b>c++filt</b>.&nbsp; <br />Example of usage:<br />$ c++filt &lt; MySymbolsFile.txt &gt; MyUnmangledSymbolsFile.txt<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />]]>
        
    </content>
</entry>

<entry>
    <title>Audio dependencies</title>
    <link rel="alternate" type="text/html" href="http://mauvilasoftware.com/iphone_software_development/2008/02/audio-dependencies.html" />
    <id>tag:mauvilasoftware.com,2008:/iphone_software_development//3.15</id>

    <published>2008-02-05T03:33:18Z</published>
    <updated>2008-02-05T05:02:26Z</updated>

    <summary><![CDATA[Here is a graph of the relationship between audio frameworks on the iPhone.&nbsp; (Courtesy of Samuel Vinson)...]]></summary>
    <author>
        <name>JLA</name>
        
    </author>
    
    <category term="audioqueue" label="AudioQueue" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mauvilasoftware.com/iphone_software_development/">
        <![CDATA[Here is a graph of the relationship between audio frameworks on the iPhone.&nbsp; (Courtesy of Samuel Vinson) <br /><br /><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><a href="http://mauvilasoftware.com/iphone_software_development/dependencies1.html" onclick="window.open('http://mauvilasoftware.com/iphone_software_development/dependencies1.html','popup','width=1058,height=794,scrollbars=no,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false"><img src="http://mauvilasoftware.com/iphone_software_development/assets_c/2008/02/dependencies-thumb-600x450.png" alt="dependencies.png" class="mt-image-none" style="" height="450" width="600" /></a></span><br /><br /><br /> <div><br /></div><div><br /></div><div><br /></div><div><br /></div>]]>
        
    </content>
</entry>

<entry>
    <title>iPhone memory management - a brief introduction</title>
    <link rel="alternate" type="text/html" href="http://mauvilasoftware.com/iphone_software_development/2008/01/iphone-memory-management-a-bri.html" />
    <id>tag:mauvilasoftware.com,2008:/iphone_software_development//3.12</id>

    <published>2008-01-31T10:55:06Z</published>
    <updated>2008-01-31T12:06:12Z</updated>

    <summary><![CDATA[No Garbage Collection&nbsp;&nbsp;&nbsp; If you are coming from Java, you are probably used to creating variables and having someone else clean up your mess after you are finished with them.&nbsp; Unfortunately, on the iPhone, you have to clean up after...]]></summary>
    <author>
        <name>JLA</name>
        
    </author>
    
    <category term="memorymanagement" label="memory management" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mauvilasoftware.com/iphone_software_development/">
        <![CDATA[<font style="font-size: 1.25em;"><b>No Garbage Collection</b></font><br />&nbsp;&nbsp;&nbsp; If you are coming from Java, you are probably used to creating variables and having someone else clean up your mess after you are finished with them.&nbsp; Unfortunately, on the iPhone, you have to clean up after yourself.&nbsp;&nbsp; If you don't, your program will leak memory.&nbsp; <br />&nbsp;&nbsp;&nbsp; It isn't exactly manual labor, however.&nbsp; The NSObject class has some accounting stuff that keeps track of how many other objects are currently using the object in question ("retain count").&nbsp; But unlike Java, it isn't automatic...you will have to adjust this count yourself.<br /> &nbsp;&nbsp;&nbsp; The analogy that is frequently used is that of a time-share condo...a condominium with multiple owners.&nbsp; And this condo sits on valuable land.&nbsp; As soon as the all the owners are done using the condo, it can be bulldozed to make way for other buildings.&nbsp; The "retain count" of the condo would be the number of owners (i.e. those who are still wanting to use it).&nbsp;  <br /><br /><b><font style="font-size: 1.25em;">Adjusting the Retain Count</font></b> &nbsp;  <br />&nbsp;&nbsp;&nbsp; The rule of managing memory is to make sure that, by the time the program has finished executing, the number of "ownership methods" called on an object will equal the number of "loss-of-ownership" methods.<br /><br /><b>

Ownership methods:</b><br />

Don't release anything you don't own.  You own anything that (any of the following):<br /><ol><li>

you call [myClass alloc] explicitly on</li><li>you explicitly [myObject retain]<br /></li><li>you create an object with a method that has the word "copy" in it.<br /></li></ol>

Note: you do not own objects created by convenience constructors...they are set to autorelease.&nbsp; (An example of calling a convenience constructor: [NSString string];)<br />

<br /><b>

Loss-of-ownership methods:</b><br />

To release something you own, you can either:<br /><ol><li>call [myObject autorelease] - will release later</li><li>call [myObject release]</li></ol><br /><b><font style="font-size: 1.25em;">Dealloc</font></b><br />Never directly call dealloc...you should always use release, and let the system decide when to deallocate. <br />
<br />
You should override dealloc for each of your objects, and inside that
method, release anything you have retained. And the end of the method,
call [super dealloc]; (It's okay to call release on a null object).<br /><br /><font style="font-size: 1.25em;"><b>Bookkeeping</b></font><br />When you implement a "set" method for encapsulation, you should do the following:<br />
<br />
- (void) setSomeObject: (NSObject*) aNewObject<br />
{<br />
[aNewObject retain];  //<b>#1</b><br />
[myObject release];   //<b>#2</b><br />
myObject=aNewObject; //<b>#3</b><br />
}<br />
<br />
#3 obviously sets the new object<br />
#2 is called just in case you have a previous object...you should
release it before you set it free. It is perfectly okay to call release
on a null object.<br />
#1 - always retain the new one first, just in case they are passing the
same object in that is already assigned. Otherwise, you may end up
deallocating the object. <br />
<br />
And if you release a variable somewhere other than dealloc, you might want to set that variable to nil immediately afterwards.<br /><br /><b>Autorelease</b><br />&nbsp;&nbsp;&nbsp; Suppose you add a convenience constructor to your own object.&nbsp; Or you have a method that allocates and returns an object that you don't plan on "owning".&nbsp; If you call "alloc", you will have to balance that out with a release of some sort.&nbsp; But you can't call "release" before you return it--the object will cease to exist.&nbsp; So instead, you call "autorelease".&nbsp; This will cause it to be released at some point in the near future, but not immediately. <br /><br />Example:<br /><br />+ (id) createAnObjectForMe<br />{<br />return [[[MyClass alloc] init] autorelease];<br />}<br />&nbsp;&nbsp; ]]>
        
    </content>
</entry>

<entry>
    <title>Settings/Preferences : a Picture Essay</title>
    <link rel="alternate" type="text/html" href="http://mauvilasoftware.com/iphone_software_development/2008/01/settingspreferences-a-picture.html" />
    <id>tag:mauvilasoftware.com,2008:/iphone_software_development//3.11</id>

    <published>2008-01-27T02:21:31Z</published>
    <updated>2008-01-27T02:32:07Z</updated>

    <summary><![CDATA[Here is the settings menu from Garf.&nbsp; Each row has a height of 48.0.&nbsp; There are 3 groups and a total of 8 rows.&nbsp; Groups 0 and 1 each have two rows, while Group 2 has one row.The arrow head...]]></summary>
    <author>
        <name>JLA</name>
        
    </author>
    
    <category term="garf" label="Garf" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="preferences" label="Preferences" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="settings" label="Settings" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mauvilasoftware.com/iphone_software_development/">
        <![CDATA[Here is the settings menu from <a href="http://mauvilasoftware.com/garf">Garf</a>.&nbsp; Each row has a height of 48.0.&nbsp; There are 3 groups and a total of 8 rows.&nbsp; Groups 0 and 1 each have two rows, while Group 2 has one row.<br /><br /><br /><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="GarfSettingsA.JPG" src="http://mauvilasoftware.com/iphone_software_development/GarfSettingsA.JPG" class="mt-image-left" style="margin: 0pt 20px 20px 0pt; float: left;" height="480" width="320" /></span><br /><br /><br /><br /><br /><br /><br /><br />The arrow head (pointy-bracket) is achieved by calling "<b>setShowDisclosure:YES</b>" on the preference cell.<br /><div><br />Most of the cells are of the type:<br /><b>UIPreferencesTableCell</b><br /><br /><br /><br /><br /><br /><br />The "High scores" cell is of the following type: <b>UIPreferencesControlTableCell</b>.<br /><br />The switch inside of it is of the type: <br /><b>UISwitchControl</b><br /><br /><br /><br /><br /><br /><br /><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="GarfSettingsB.jpg" src="http://mauvilasoftware.com/iphone_software_development/GarfSettingsB.jpg" class="mt-image-left" style="margin: 0pt 20px 20px 0pt; float: left;" height="480" width="520" /></span></div><div><br /></div>]]>
        
    </content>
</entry>

<entry>
    <title>Source Code and Packages</title>
    <link rel="alternate" type="text/html" href="http://mauvilasoftware.com/iphone_software_development/2008/01/source-code-and-packages.html" />
    <id>tag:mauvilasoftware.com,2008:/iphone_software_development//3.10</id>

    <published>2008-01-27T00:17:32Z</published>
    <updated>2008-01-27T00:43:48Z</updated>

    <summary><![CDATA[Source Code &nbsp;&nbsp;&nbsp; When you start programming your first original program, you'll probably want to reuse the "main.m" source file that you find in another program (e.g. HelloWorld).&nbsp;&nbsp; Just edit it and make sure it is importing your program's header.&nbsp;...]]></summary>
    <author>
        <name>JLA</name>
        
    </author>
    
    <category term="infoplist" label="Info.plist" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="makefile" label="Makefile" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="package" label="package" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mauvilasoftware.com/iphone_software_development/">
        <![CDATA[<font style="font-size: 1.25em;"><b>Source Code</b></font><br />
&nbsp;&nbsp;&nbsp; When you start programming your first original program, you'll
probably want to reuse the "main.m" source file that you find in another program (e.g. HelloWorld).&nbsp;&nbsp; Just edit it and
make sure it is importing your program's header.&nbsp; And of course make
sure it is specifying your program's name in the call to
UIApplicationMain.&nbsp; This should be self explanatory when you actually
see it.<br />
&nbsp;&nbsp;&nbsp; So let's say you are creating a program called "Big Gulp".&nbsp; Here is the layout of files I recommend:<br />
<ul><li>main.m (a very small file...)</li><li>BigGulp.m (your primary application class...of type UIApplication)</li><li>BigGulp.h (the header file for your application class)</li><li>Makefile (the make file...recycle this from another program...be sure to edit it to make sure the filenames match your program)</li></ul><font style="font-size: 1.25em;"><b>Building Your Program</b></font><br />&nbsp;&nbsp;&nbsp; When you want to compile and link your program, you will want to use a Makefile.&nbsp; I'm no expert on this subject, and how they work is still somewhat of a mystery to me, but I do know that you it's best to copy the Makefile from another iPhone program you find and edit it to make sure it fits your program.&nbsp; Be very careful...the file is very picky about white space (tabs, etc).&nbsp; The Makefile easily deserves its own article, and so I won't go into too much detail here, but for now, you should be able to look at one and see what needs replacing.<br />&nbsp;&nbsp;&nbsp; To compile, go to the prompt in your program's directory (e.g. Cygwin for Windows users).&nbsp; If the Makefile is set up properly, the command "make clean" should delete any previously compiled binaries and give you a fresh plate...so go ahead and type that.&nbsp; Then follow that by typing "make".&nbsp; If it builds correctly, it should produce an executable file (whose name you specified in the Makefile).&nbsp; Unlike Windows executables, this file will not have a special extension (.exe).&nbsp; Or any extension, for that matter.&nbsp; It will simply be plain extensionless file.<br /><br /><b><font style="font-size: 1.25em;">Package structure</font></b><br />&nbsp;&nbsp;&nbsp; When you want get your program ready for installing on the iPhone springboard, you should create a directory on your computer called BigGulp.app (replacing "BigGulp" with the name of your app).&nbsp; <br />&nbsp;&nbsp;&nbsp; This folder should eventually contain the following files:<br /><ul><li>biggulp (or whatever your executable is called)</li><li>icon.png (the icon for your program)</li><li>Default.png (the splash screen for your program...should be 320 x 460)</li><li>PkgInfo (get this from another program and don't change it)</li><li>Info.plist (get this from another program but DO change it...)</li><li>(any other graphics file, etc. that your app needs)</li></ul><font style="font-size: 1.25em;"><b>Info.plist</b></font><br />&nbsp;&nbsp;&nbsp; This is another file that you should borrow from some other iPhone program.&nbsp; You will need to edit however.<br />&nbsp;&nbsp;&nbsp; Specifically, you should edit the strings that come after the following labels (keys):<br /><ul><li>CFBundleExecutable - this should specify your app's executable file (e.g. biggulp)</li><li>CFBundleIdentifier - this should be some unique string...one that no other app in the world will have.&nbsp; You may notice that it frequently looks like a web address in reverse.&nbsp; This is merely a convention of coming up a unique identifier...since only one entity (company) will "own" a website name, two different companies won't accidentally use the same identifier.&nbsp; Note that there is no requirement that this name have anything to do with a website, or that a website exists.&nbsp; One place this identifier will be used is when you save user defaults, the iPhone will create a file by that name in the Preferences directory.<br /></li><li>CFBundleVersion - this is whatever arbitrary version you have assigned to your app.</li></ul>You should leave the other stuff alone, including the CFBundleInfoDictionaryVersion.&nbsp; <br /><br /><br /><font style="font-size: 1.25em;"><b>Installing the app</b></font><br />&nbsp;&nbsp;&nbsp; To install the app on your iPhone, you will simply need to copy the .app directory you just made into the /Applications directory on your phone (via SSH).&nbsp; Make sure that both your app's directory (e.g. BigGulp.app) and the executable file inside it have full Execution permissions.&nbsp; This is done by either your SSH program or by using an app like MobileFinder. <br />&nbsp;&nbsp;&nbsp; After doing this, you will need to "respring" the phone...that is, restart SpringBoard.&nbsp; There are a couple of apps that can do this for you, including SysInfo (from Robota Software - available on Installer).&nbsp; Or you can simply reboot your phone (so it starts up again, showing the silver apple).&nbsp; Your app should show up on the springboard.<br /><br /><br /><br />
 ]]>
        
    </content>
</entry>

<entry>
    <title>Getting started (on Windows)</title>
    <link rel="alternate" type="text/html" href="http://mauvilasoftware.com/iphone_software_development/2008/01/getting-started-on-windows.html" />
    <id>tag:mauvilasoftware.com,2008:/iphone_software_development//3.9</id>

    <published>2008-01-26T23:54:41Z</published>
    <updated>2008-01-27T00:44:21Z</updated>

    <summary><![CDATA[Windows user?&nbsp;&nbsp;&nbsp; If you use Windows, you are at a slight disadvantage when it comes to developing for the iPhone.&nbsp; Mac users have the (alleged) benefit of XCode.&nbsp; Windows users, however, must make it on their own.&nbsp; Toolchain&nbsp;&nbsp;&nbsp; Obviously, the...]]></summary>
    <author>
        <name>JLA</name>
        
    </author>
    
    <category term="cygwin" label="Cygwin" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="toolchain" label="toolchain" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="windows" label="Windows" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mauvilasoftware.com/iphone_software_development/">
        <![CDATA[<font style="font-size: 1.25em;"><b>Windows user?</b></font><br />&nbsp;&nbsp;&nbsp; If you use Windows, you are at a slight disadvantage when it comes to developing for the iPhone.&nbsp; Mac users have the (alleged) benefit of XCode.&nbsp; Windows users, however, must make it on their own.&nbsp; <br /><br /><b><font style="font-size: 1.25em;">Toolchain</font></b><br />&nbsp;&nbsp;&nbsp; Obviously, the first step is to get the toolchain up and running with Cygwin.&nbsp; Cygwin is a Linux shell (i.e. command prompt) emulator for Windows.&nbsp; It is distributed with a setup file that makes it very easy to download most of the components you'll need (sort of like Installer on the iPhone).&nbsp;&nbsp; To get everything setup, see the first entry of this blog.<br /><br /><b><font style="font-size: 1.25em;">Text editor</font></b><br />&nbsp;&nbsp;&nbsp; You'll need a good text editor that is Unix friendly.&nbsp; Windows (DOS) uses a different combination of invisible keys to mark the end of each line than Unix.&nbsp; For this reason, I wouldn't recommend any Microsoft products.&nbsp; <br />&nbsp;&nbsp;&nbsp; The text editor I use is jEdit.&nbsp; It's a free download and has a good number of easy-to-install plugins.&nbsp; Fairly programmer friendly.<br /><br /><font style="font-size: 1.25em;"><b>HelloWorld</b></font><br />&nbsp;&nbsp;&nbsp; Once you have the toolchain up, you'll need to find a copy of the UIKit version of HelloWorld.&nbsp; HelloWorld, in case you are new to programming, is the traditional name for the first program&nbsp; you compile.&nbsp; It's a fairly worthless program, but it serves to a) test the toolchain and b) provide a template for your future programs.]]>
        
    </content>
</entry>

<entry>
    <title>A quick intro to iPhone development for Javans</title>
    <link rel="alternate" type="text/html" href="http://mauvilasoftware.com/iphone_software_development/2008/01/a-quick-intro-to-iphone-develo.html" />
    <id>tag:mauvilasoftware.com,2008:/iphone_software_development//3.8</id>

    <published>2008-01-26T08:55:17Z</published>
    <updated>2008-01-26T09:38:49Z</updated>

    <summary><![CDATA[A brief Java-oriented glossaryIf you are coming from Java (the language, not the place), then here's a very brief Java-to-UIKit guide.&nbsp; (Note: some of these are only approximately equal)interface (Java) = protocol (ObjC)static method = class methodjava.lang.Object = NSObjectjavax.swing.JOptionsPane =...]]></summary>
    <author>
        <name>JLA</name>
        
    </author>
    
    <category term="java" label="Java" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="methods" label="methods" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="objc" label="ObjC" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mauvilasoftware.com/iphone_software_development/">
        <![CDATA[<b><font style="font-size: 1.25em;">A brief Java-oriented glossary</font></b><br />If you are coming from Java (the language, not the place), then here's a very brief Java-to-UIKit guide.&nbsp; (Note: some of these are only approximately equal)<br /><ul><li>interface (Java) = protocol (ObjC)</li><li>static method = class method</li><li>java.lang.Object = NSObject<br /></li><li>javax.swing.JOptionsPane = UIAlertSheet</li><li>null = nil</li><li>System.out.println("my object=" + myObject); = NSLog(@"my object=%@", myObject);</li><li>"a literal string" = @"a literal string"</li><li>java.lang.String = NSString</li><li>boolean = BOOL</li><li>java.util.ArrayList = NSMutableArray</li><li>map = dictionary</li><li>this = self<br /></li></ul><br /><b><font style="font-size: 1.25em;">For loop</font></b><br />One thing that sort of bugs me is that you aren't allowed to do this: "<i>for (int i=0; i&lt;10; i++)</i>"...you can't declare the variable 'i' there.&nbsp; You have to do this instead: <br /><i>int i;<br />for (i=0; i&lt;10; i++)</i><br /><br /><b><font style="font-size: 1.25em;">Methods in ObjC</font></b><br />(Note: the word "method" will be used interchangeably with the words "function" and "procedure".)<br /><br />The most obvious difference between Java and Objective C is probably the ways methods are declared.&nbsp; <br /><br />A regular ole method declaration looks like this:<br /><i>- (int) getSomeNumber: (int) aParameter withAnotherParameter: (NSString*) aStringParameter</i><br />This would be equivalent to:<br />private int getSomeNumber(int aParameter, String aStringParameter)<br /><br /><ul><li>First, notice that it starts with a hypen (a minus sign).&nbsp; If this were a plus sign (+), it would mean the function is a "class method" (known in Java as a static method).</li><li>Next, notice that Objective C puts the variable type in parentheses, sort of like you do when you cast from one type to another.&nbsp; The parentheses do not enclose the entire parameter list.<br /></li><li>Notice there are no commas...also note that ObjC uses labels for parameters (starting with the second one).&nbsp; In the previous example, it is "withAnotherParameter".&nbsp; This is just something that helps describe what the next variable is, and I could have just as easily used "fooMcLovin" or some other nonsense instead.</li><li>The asterisk means that ObjC uses the same pointer notation as C/C++.</li></ul><br />When you call the function, it will look something like this:<br /><i>int x = [myObject getSomeNumber: 32 withAnotherParameter: @"some string I made up"];</i><br />(Technically, in ObjC, you aren't calling methods...you are sending
messages, but we'll ignore this distinction for the time being.)<br /><br /><br /><b><font style="font-size: 1.25em;">Other differences</font></b><br />There are many more differences that I'm not going to cover in this article...e.g. header files, pointers, memory management (no more garbage collection).&nbsp; These will hopefully be addressed in some form or another in later articles. ]]>
        
    </content>
</entry>

<entry>
    <title>Programming software for the iPhone</title>
    <link rel="alternate" type="text/html" href="http://mauvilasoftware.com/iphone_software_development/2008/01/programming-software-for-the-i.html" />
    <id>tag:mauvilasoftware.com,2008:/iphone_software_development//3.7</id>

    <published>2008-01-26T08:05:41Z</published>
    <updated>2008-01-26T09:39:30Z</updated>

    <summary><![CDATA[Purpose of this blog&nbsp;&nbsp;&nbsp; As of the time of composition of this initial entry, the iPhone Software Development Kit (SDK) is set to be released in a little over a month.&nbsp; This will allegedly allow 3rd parties to develop native...]]></summary>
    <author>
        <name>JLA</name>
        
    </author>
    
    <category term="java" label="Java" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="toolchain" label="toolchain" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en-us" xml:base="http://mauvilasoftware.com/iphone_software_development/">
        <![CDATA[<b><font style="font-size: 1.25em;">Purpose of this blog</font></b><br />&nbsp;&nbsp;&nbsp; As of the time of composition of this initial entry, the iPhone Software Development Kit (SDK) is set to be released in a little over a month.&nbsp; This will allegedly allow 3rd parties to develop native software for the iPhone.&nbsp; I say allegedly because Apple is releasing this with some reluctance...I'm not sure exactly who this SDK will target, but my guess is that it will be aimed at professional developers who work for "significant" software companies.<br />&nbsp;&nbsp;&nbsp; This blog isn't intended for professional programmers, but rather the amateur...the hobbyist developer who wants to write something for the iPhone.&nbsp; I feel I am especially qualified for this because I am only one step up from the "noob"...my profession has very little to do with computers, and I can certainly relate to how confusing this all can be.&nbsp; <br />&nbsp;&nbsp;&nbsp; If you fit into this hobbyist demographic, you will want to have a jailbroken iphone.&nbsp; To "jailbreak" an iPhone is to uncripple it so that it will allow 3rd party native applications...(don't confuse "jailbreak" with "unlock" the the media often does).&nbsp; If you haven't reached this step, I recommend visiting a site like <a href="http://modmyifone.com/">ModMyIfone.com</a>, which will have plenty of information on how to do this.<br />&nbsp;&nbsp;&nbsp; It should go without saying that this blog has absolutely no affiliation with Apple.&nbsp; <br />&nbsp;&nbsp;&nbsp; <br /><b><font style="font-size: 1.25em;">Native Apps versus "Web Apps"</font></b><br />&nbsp;&nbsp;&nbsp; A native application is one that runs...well...like a real application.&nbsp; It resides on the iPhone storage drive, and it runs without requiring a web browser.&nbsp;&nbsp; A "web app" (notice how I belittle it with quotation marks) is (in my opinion) a fancy web page.&nbsp; This blog will deal with native apps.<br /><br /><b><font style="font-size: 1.25em;">What is required?</font></b><br />So you want to develop software for the iPhone...what will be required?<br />Here are the requirements that involve spending money:<br /><ul><li>An iPhone or an iPod Touch</li><li>A home computer (Windows, Mac, whatever)</li><li>An Internet connection</li><li>A wireless router (for transferring your app to your iPhone to test it)</li></ul>The rest of the stuff needed can be downloaded for free.<br /><br /><b><font style="font-size: 1.25em;">Programming experience</font></b><br />While programming experience for non-iPhone stuff isn't absolutely required, you probably want some under your belt before attempting to program for the iPhone.&nbsp; If you have programmed for the Mac before, this will be a breeze for you to learn.&nbsp; If you are a C++ person, this will also be fairly easy.&nbsp; I am personally coming from the land of Java.&nbsp; If you have never programmed before, I definitely recommend you spend a few months (at least) toying with Java.&nbsp; Why?<br /><ul><li>Java is very friendly for those who are new to programming</li><li>Java is popular on a variety of computer operating systems, including yours</li><li>There is a whole lot of help available on the Internet for Java programmers.</li><li>There are tons of "Beginner's Guide to Java" type books in bookstores<br /></li><li>Java has really great (and free) IDEs like Netbeans and Eclipse.</li></ul>Note that none of the above really apply to iPhone development.&nbsp; And also note that the stuff above and below represents my personal opinion.<br /><br /><b><font style="font-size: 1.25em;">Programming languages in iPhone development</font></b><br />&nbsp;&nbsp;&nbsp; So what programming language is used to make iPhone apps?&nbsp; The simple answer: Objective C (ObjC).&nbsp; Outside of the land of Apple, ObjC is fairly obscure.&nbsp; So what is Objective C?&nbsp; Let's go back to C.&nbsp; <br />&nbsp;&nbsp;&nbsp; C is the foundation for a number of languages.&nbsp; It isn't as often used by itself anymore because it isn't <i>object oriented</i>...it doesn't use classes/objects.&nbsp; So a number of languages added object-oriented capabilities onto C.&nbsp; One of these was C++.&nbsp; Another of these was ObjC.&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp; So because ObjC was built on top of C, C can be freely used throughout an Objective C program.&nbsp; So you could program an iPhone app in C, with only a dab of ObjC in the whole thing.&nbsp; But you'll find that ObjC isn't difficult to learn.<br /><br /><b><font style="font-size: 1.25em;">UIKit?</font></b><br />&nbsp;&nbsp;&nbsp; So you may have heard about UIKit...what is that?&nbsp; Specifically, it's a single framework (i.e. set of classes) that contains classes needed for iPhone user-interface (UI).&nbsp; (Sort-of like what Swing is for Java.)&nbsp; <br />&nbsp;&nbsp;&nbsp; UIKit is often used, however, in a more general sense to mean not only the UIKit framework, but all of the frameworks present on the iPhone.&nbsp; And it's sometimes used to refer to the entire iPhone programming experience.<br /><br /><b><font style="font-size: 1.25em;">So what's the next step?</font></b><br />So before you get going, you'll need what is called the <a href="http://code.google.com/p/iphone-dev/">toolchain</a>.&nbsp; This is a 3rd party bundle of software that is used to build programs for the jailbroken iPhone.&nbsp; You can either find a precompiled binary for your computer system, or you can build it yourself.&nbsp; If you do choose the old-fashioned build-it-yourself technique, check out the toolchain site for instructions.&nbsp; If you use Windows, however, I recommend you using a separate set of instructions that are tailored to Windows.&nbsp; There may be a copy of these on the wiki portion of the ModMyIfone site, but you may have to look around to find them.<br />&nbsp;&nbsp; ]]>
        
    </content>
</entry>

</feed>
