Friday, June 18, 2010

A Intro to Timers

One of the easiest things to set up in a iPad/iPhone app is a timer, and I'll show an example in this post.

The timer exists in every app, so rather than alloc and init, we schedule an event on the system timer:

[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(timerDone:) userInfo:nil repeats:NO];


Most of this is simple. The Interval is in seconds. The target is where the selector is located, and the selector is the method that is called when time is up. userInfo can be used to pass things to the timer, which are then passed through to the selector in case it will need something to correctly handle the event. Repeats is set to NO because I don't want to repeat this event.


The handler is below:

/**

Called by the timer when it exits.

*/

-(void) timerDone:(NSTimer *) timer{

[self.view removeFromSuperview];

}


This is a simple method that doesn't require the userInfo field, but if it did, I would have added it to the parameter list and used it in this method.


--- RTG

Thursday, June 10, 2010

Sorting an array

I just had to sort an array of mutable objects (entities in Core Data), and I've never done it before, so here's a quick example.

I used the function

- (NSArray *)sortedArrayUsingFunction:

(NSInteger (*)(id, id, void*))comparator

context:(void *)context


and defined a comparator:


NSInteger buttonSort(id one ,id two , void *context){

Button *b1 = (Button *) one;

Button *b2 = (Button *) two;

if([b1.id intValue] > [b2.id intValue]){

return NSOrderedDescending;

}else if([b1.id intValue] < [b2.id intValue]){

return NSOrderedAscending;

}

return NSOrderedSame;

}


Note the style on that function - think macro rather than obj-c class function. Since the id is an NSNumber, I had to use intValue to get the int values that I meant to store (don't forget that!)


Then I simply built the array then sorted it:

NSArray *buttonsUnSort = [appDel getChildrenOfLeaf:parent];

NSArray *buttons = [buttonsUnSort sortedArrayUsingFunction:buttonSort context:NULL];


An important note: *buttons contains references to all the objects, not copies.


-- RTG

Wednesday, June 9, 2010

Back in Winston

After a two week break in the NC mountains and a 3 day move into my new home, I am finally back and able to work on this project. During the iPhone course that I took in the spring, my team developed an application that allowed people to take a tour of Wake Forest using their iPhone and read up on each landmark as they went. While the application was fun, I am ready for a new project and am also excited to be working with an iPad. Hopefully my next update will have some more substantial information on how I am going to be contributing to the group. For now I am building a website for our applications and will begin doing extensive testing of the app before we submit it to the Apple store.

Monday, June 7, 2010

Changes! Oh no!

One of the key reasons that mobile development is fun (no, Jobs, it isn't Obj-C) is that developers get to deal with a fast moving field that present special challenges. A few hours ago, Steve Jobs announced the new iPhone that everyone already knew about because some guy left it in a bar. It includes a higher resolution screen, a new camera, and a higher resolution version of the old camera.

How does this affect us? Well, we aren't sure yet, but we'll post about it. Certain to change are the positioning of custom elements on the screen, because those measurements are in pixels. We might also need to use higher resolution images. As we move through those kinds of issues, including how to tell which version is running, ect., we'll be sure to write about it.

-- RTG

Tuesday, June 1, 2010

First post! Who are we and what do we do?

Over the last few months, a class at Wake Forest University has been working on programming the iPhone as part of a course on Software Engineering with Dr. Paul Pauca. One group, Tommy Guy (that's me!), Edison Munoz, and Harry Pham created an app called VerbalVictor to enable speech impaired children to communicate. There will be a lot more about that in the posts to come. Another student, Brad McDanel, worked on an app for campus tours at Wake Forest. Over the summer, Dr. Pauca, Tommy, Edison, and Brad will be publishing VerbalVictor and creating a second app in the same vein for the iPad.

We plan to use this blog to talk about the process of developing and deploying an application. Why another blog on the iPhone and deployment? Two reasons. First, we want to have another source of helpful hints on getting into iPhone programming, especially for students. Second, we will be working on paid apps within a setting where we don't own our intellectual property. Like most schools, we will have to work with Wake Forest to protect, publish, and monetize our work. We plan to document that process.

--- RTG