Thursday, January 29, 2009
at
3:37 PM
|
I started reading the development guide available on Apple's development center website. It outlines some of the basics that you should know about developing an application. This post will serve as basically a bookmark for pages I think are important.
- Page 11, lists the "Essential Development Tasks"
- Page 15, "Accessing Documentation"
- Page 18,49, "Measuring Performance"
- Page 19, "Hello World"
- Page 26, "Building Your Application"
- Page 31, "Using the Simulator"
- Page 35, "Preparing Devices for Development"
- Page 45, "Debugging"
- Page 51, "Testing"
- Page 55, "Conditional Compiling"
That's all for now.
Wednesday, January 28, 2009
at
11:18 AM
|
I made a small program the other day to convert Fahrenheit to Celsius and back. It's a simple program not requiring many lines of code at all but it took me awhile to write for some reason. I'm still getting used to the Objective-C syntax and all of the different connections that need to be made in order to get things to work. Eventually it will all sort itself out I suppose. Also, I'm back working on the virtual machine and it's really slow so I can't work as fast as I'd like to. Here are some pictures of what I was working on.
Sunday, January 25, 2009
at
5:41 PM
|
Now I'd like to explore a little bit more of the basics and create another simple application. This application is from a tutorial I just read with a few modifications for things that I thought were a little bit confusing. This application involves the simple use of a Model-View-Controller methodology. The model is mostly taken care of by the framework itself, so this focuses on the controller and the view. Let's create the view first.
First open up XCode and create a new Window-Based project. Call it whatever you like, I called mine HelloUniverse2. The first thing we are going to create is a view. An IPhone application has only one window (MainWindow.xib) and to see additional views you must add them as subviews to the main window. Double click on MainWindow.xib to open the Interface Builder.
Depending on how things are set up you might see a few different things. What you should definitely see is a window that says MainWindow.xib. There are four objects in that window, File's Owner, First Responder, something that involves the name of your project, and Window. File's Owner and First Responder we will probably learn more about later, but from what I understand, they are "proxy objects" which apparently means they are a bridge between the nib file (the user interface we create) and the application (the code we write).
For now, let's make a new view. To do that go to File --> New and choose View. A new window similar to the previous one will pop-up but instead of four items it will have three and one of them is View. You can save this view. I saved it as HelloView like in the tutorial I followed. You should probably save the file somewhere in your project folder. You'll be given the choice to add it to your project which you obviously want to do. Then you'll be brought back to XCode where you should drag the file into your resources folder.
Go back to the Interface Builder so that we can decorate our view. Go to Tools --> Library so we can see all of the available goodies. Let's get a label, two text fields, and a button and drag them onto the View. Now we can change some of the properties of our items using the Inspector window. If the Inspector window isn't already showing up go to Tools-->Inspector. The tools menu lists four inspector types underneath Inspector. These correspond to the four tabbed buttons in the main Inspector window. They are attributes, connections, size, and identity.
Let's mess around with the first text field first. Click the text field on the View and go to the Attribute Inspector (Tools --> Attribute Inspector or click the first tab button in the Inspector window). For Placeholder, type First Name. Make sure Clear When Editing Begins is checked. Under Text Input Traits, select Words for Capitalize and Name Phone Pad for Type. Repeat the same thing for the second text field except call the Placeholder, Last Name. Then double click on the button and type something clever. Save the view (File-->Save) and we're done here for now.
We've made the view, now we have to make the controller. Luckily most of the work is done behind the scenes so we are going to just make a subclass of an existing controller. To do this go to File --> New File and in Cocoa Touch Classes we are going to select UIViewController subclass. This is an example of inheritance. UIViewController is a method provided by the Cocoa framework to handle most of the things we need to do. We are going to build upon the functionality of the UIViewController without reinventing the wheel so to speak.
Go to the header file (.h) for the file that you just created. Mine is HelloViewController.h. In here we are going to create variables to link the view to the controller. Make your header file look like the one in the image. The line beginning with @interface specifies the name of our class as a subclass of UIViewController. is a protocol which we will need later to make the textfield behave properly. The lines starting with IBOutlet declare variables for the items that we set up in the Interface Builder. IBOutlet means that it is accessible in the Interface Builder. NSString creates string objects for the text that we will pull from the text fields. We also set some properties for the variables that we created. Nonatomic seems to be what we'll use most and should be like that for most applications. Retain means that the object will retain its value on assignment. I believe copy means that it will create a copy of this object on assignment but I'm not sure. The final declaration is a method for handling the button press. IBAction lets us see this method in the Interface Builder. The name of the function is displayMessage and it takes an id object as a parameter.
Now that we've created the header file we get to provide implementation for it just as we would in C++. So open up the .m file and look at this source code (too much code for an image). To initialize our variables we use the @synthesize keyword. Now we are going to provide the implementation for the displayMessage method. The idea is that when the user clicks the button we want the label to show whatever it was that was in the textfields. The code itself is pretty self-explanatory give or take some syntax. Remember, there is no garbage collection so we have to manage our own memory to avoid leaks. We also create a textFieldShouldReturn method. This is why we used to allow us to write this method. This method says that if the textfield is one of ours that we created, when we press return, we should give up control of it. Without this, the typing pad will stay open.
 We're not done yet. We still have to add the view we just made to the main view. To do that go to the AppDelegate.h file and add a variable declaration for HelloViewController. Then in the .m file we need to actually provide the implementation to link the view with the main window. Once again, the code is pretty self-explanatory except for the syntax. We're using a bundle. I'm not too sure what it means but perhaps I'll figure it out later.
That's all of the code that we have to write. We still have to link up all of the visual items with their variable names that we've given them. To do this, we go back into the Interface Builder. Click on the File's Owner so the Hello View Inspector appears and click on the Identity tab (the i button on the top right of the Inspector window) and select HelloViewController for the class. We've now connected the view controller to the proxy object. Now we must connect the view to the view controller. While still having File's Owner selected, click on the Connection Inspector (the arrow button) and drag the circle next to the view variable to the actual view. Also drag the circles for our textfields and label and buttons to the ones on screen. And that's it, we should be done. Save your work and go back to XCode, compile and run, and you should have a working app!
I finally was able to create my first working application! Whenever anyone starts a new programming language the first program they inevitably create is Hello World. So that's what we're going to do.
To start off, first open up XCode and close the welcome screen that pops up. Then select File-->New Project and select Window-Based Application. You will be greeted with the XCode IDE. There are some files in there that contain some code and stuff. I'm not quite sure what a lot of that means yet but I'm sure I'll figure it out as I go along. The file of interest is MainWindow.xib. This seems to be the main window of the application. Double clicking this file opens the Interface Builder where we can design a user interface.
What we want to do is go to the Tools menu and select Library. There are a lot of user interface objects that are here. For this simple program all we need is a label. Go the library and find Label and drag one out to the window. Then double click on the label and type "Hello World." Save your work at this point. Now go back into XCode and hit Build and Go at the top of the screen. The IPhone simulator should pop up and you should see "Hello World" pop up in the window. Congratulations! We just made our first application! Now it's time to find something more fun to do.
After several hiccups with my VMWare setup, I was finally able to get up and running. Ideally I'd be working on an actual Mac but for now this will have to do.
The first thing I did was head over to the IPhone Development Center and watch some of the Getting Started videos. These first several videos that I watched give a basic overview of all of the features contained in the IPhone SDK as well as the IPhone. The IPhone SDK contains a number of useful tools like XCode, Dashcode, and Instruments. These tools are what you will be using when developing your own applications. The IPhone itself is comprised of four parts divided into layers. There's the Core OS which handles all of the chores an operating system would be expected to do. On top of that, is the Core Services layer which comprises all of the services that all applications must interact with. On top of that is the Media layer which is where your application can interfacec with the audio and graphical capabilities of the IPhone. Finally on top of that is the Cocoa Touch framework where all our development gets done. The Cocoa Touch framework has a ton of function available for us to use.
The API is written in Objective-C which is a superset of ANSI C with some additional syntax to make it object oriented. Another cool thing that I discovered was that you could mix C++ code with your Objective-C. When developing applications it seems very important to be consistent and stick to appropriate conventions. The Model View Controller model is an essential part of the development.
This was meant to be a brief overview of some of the things I learned today from watching these introduction videos. I recommend watching them yourself as well. Hopefully now I can start making some applications!
Saturday, January 24, 2009
at
4:06 PM
|
After getting my hard drive and installing OS X to it I realized that you can only then boot to that hard drive from a Mac machine. So at this point my only option was to use a virtual machine again. Curiously, this time around, the virtual machine was much more responsive. Hopefully that means I will be able to develop on it very shortly.
Thursday, January 22, 2009
at
7:16 PM
|
I was able to borrow an iBook running Leopard from the CS department. I downloaded the IPhone SDK and attempted to install it. I noticed then of course that the IPhone SDK will only install on Intel-Macs. Since the iBook is a PowerPC-Mac I could not install the SDK. I guess I'll just have to wait for my hard drive to come.
Saturday, January 17, 2009
at
1:06 PM
|
Using VMWare to run OS X, while incredibly cool, is incredibly slow. Instead I'm going to try and install Leopard on an external hard drive and boot off of it directly. While I'm waiting for my drive to get here, I'll redesign some of the blog and start reading up on my Objective-C.
Friday, January 16, 2009
at
12:19 PM
|
Gotta love virtual machines. Seeing as I don't own a Mac and it's really no fun to try and develop applications on a computer that doesn't belong to you, I did the next best thing, run a virtual machine! VMWare allows one to run "virtual operating systems" so you can still run Windows but in another window have a whole other operating system running. In this case the other OS was Mac OS X 10.5.5 which is required to run the IPhone SDK.
The virtual machine is a bit slow but we'll see how things go. I may just cave and go use a computer in the computer lab.
Thursday, January 15, 2009
at
1:29 PM
|
I've got my blog set up. I aim to document the work I do for my independent study here, on this blog. Let's get to work!
The first thing I did was head on over to the IPhone Dev Center to download the IPhone SDK. The IPhone Dev Center seems to contain everything anyone would ever want to know about developing applications. First things first. I downloaded the Free IPhone SDK and realized that it is for Macs only. The IPhone OS as well as OS X (and thus the sdk and all the iphone apps) are written in objective-C which is why there is no Windows version.
So for now, it's off to find a Mac!
|
|