21 May 2010

Objective-C Article

There is an interesting article at
http://www.psynixis.com/blog/2008/04/25/did-apple-make-a-mistake-choosing-objective-c-for-iphone-sdk/ about Objective-C and iPhone application development. The best part of the article is the list of responses that follow. The author is not a fan of Objective-C, but the follow-up posts make some very good points about why Objective-C was chosen and give some interesting glimpses into the history of the platform and development environment.

JK

19 May 2010

While cleaning up my code, I realized that I had gone hog-wild with @properties and @synthesize, so I was attempting to clean up un-necessary instances of them. What I found was that I could remove them all and my code would compile and run just fine. What are the circumstances when @property and @synthesize are mandatory?

1. Never

2. Whenever the property will be set in the format of “var = [[varitype alloc] init];”

3. Whenever the property will be read in the format of “anothervar = var;”

4. Whenever the properties attributes will be directly accessed as in “var.property = 2;”

Thanks.

JK

18 May 2010

Storing Data

Chapter 8 (Handling Data) ends with a discussion of how you can store and retrieve data in your iPhone apps, including a nice modification to the CityGuide app on pages 219-224, using SQLite. I almost got the modification working, but had problems when I made an error in my citites.sqlite file. I deleted the previous cities.sqlite from my Resources, added the new file, and still got the old data. It turns out that to really "clean" your app data, you need to remove the old version of cities.sqlite (or whatever data file you're using) from /Users/yourname/Library/Application Support/iPhone Simulator/3.1.3/Applications/bigrandomkey/Documents/. (The bigrandomkey is just an arbitrary code that the simulator uses to generate temporary directories in which to store your data.)

13 May 2010

Typo and an Omission

A typo on page 180 (middle of the page) reads "Then make the change shown in bold to the top of MainViewController.h:" It should be MainViewController.m:

Also, on page 183-4 he has us make new helper methods for the WeatherForecast object, but they were undeclared in the WeatherForecast.h file. We added these lines in WeatherForecast.h before the @end:
-(NSString *)fetchContent:(NSArray *)nodes;
-(void)populateArray:(NSMutableArray *)array fromNodes:(NSArray *)nodes;

Email App on pages 161-165

Josiah and I ran this app on the simulator, and got no email output at all. We decided to try it on the iPhone itself, and I got a pretty little email from him that ended with "Sent from my iPhone." I think it only works from the iPhone itself because the simulator has no email address attached to it.

The Story of Mel: A Real Programmer

"When the light went on, it nearly blinded me."

12 May 2010

(Asynchronous) Reachability

Okay, here's the full(er) story on Apple's Reachability class, which we use in the NetworkMonitor app that starts off this week's assignment (Chapter 7).

For some reason (probably a typo by a programmer at Apple), the actual name of the method that starts notification is not startNotifier, but rather startNotifer. Allan, the textbook author, uses the actual method name ( startNotifer), but in copying his code into XCode I automatically changed it to what I thought he meant (or what I thought the name should be). If you do exactly what he says, it works fine.

So, how exactly does Reachability work? It seems to work similarly to the Unix ping command: anything that can be resolved by ping comes back as reachable, and anything that cannot comes back as unreachable. So a URL like foo is unreachable: consisting of letters, it is sent by ping to the Domain Name Server (DNS), which cannot resolve it. On the other hand, a bogus numerical address like 123 appears to dodge the DNS, so ping (and the Reachability) class don't reject it, even though ping fails to retrieve any packets (test messages) back from such addresses:
~: ping www.apple.com
PING e3191.c.akamaiedge.net (96.16.93.15): 56 data bytes
64 bytes from 96.16.93.15: icmp_seq=0 ttl=53 time=8.789 ms
64 bytes from 96.16.93.15: icmp_seq=1 ttl=53 time=8.535 ms
64 bytes from 96.16.93.15: icmp_seq=2 ttl=53 time=8.526 ms
^C
--- e3191.c.akamaiedge.net ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 8.526/8.617/8.789/0.122 ms

~: ping foo
ping: cannot resolve foo: Unknown host

~: ping 123
PING 123 (0.0.0.123): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
^C
--- 123 ping statistics ---
3 packets transmitted, 0 packets received, 100.0% packet loss
Now, it's a bad idea to fiddle with DNS (and it requires root privilege on the server anyway), so how would one simulate a server becoming (un)reachable? That is, how can we test our asynchronous NetworkMonitor app? I'll leave this as an extra-credit riddle for you to solve.

11 May 2010

Cocos2d

Hi, just want to show you guys a new project framework to work with if you are thinking about designing games(especially 2d ones) . This framework is a lot easier to use than the openGL templates in that it provides you with a library of methods more specifically geared towards game development.

Typo in Book: Bottom of p. 148

"The final step is to add the stringWithStatus: stringFromStatus: method..."

Typo in book, bottom of p. 151

Final paragraph: Next, click on File's Owner in the WebView.xib PrototypeViewController.xib window.

07 May 2010

#import vs. @class

I had a question today at the end of the lecture, about the distinction between #import and @class ("forward" class declaration) Here's a brief recipe, based on the textbook (top of p. 69):
  • In implementation (.m) files, use #import to access declarations for classes you create; e.g.,
    #import "CityDelegate.h"
  • In header (.h / interface) files, use #import to access declarations for Cocoa classes: e.g.,
    #import 〈UIKit/UIKit.h〉
  • In header (.h / interface) files, use @class to access declarations for other classes you create; e.g.,
    @class RootController
In principle, you should be able use #import to include any code anywhere you want. As the author says, however, @class is recommended by Apple for including your own class declarations in your own interface files, because "it avoids potential problems that may come with importing files that import still other files."

06 May 2010

Why assign a pointer to nil, then to something else?

I'm wondering if there is a typo on page 141 of the text where these two lines of code appear:

newCity.cityPicture = nil;
newCity.cityPicture = cityPicture;

Isn't the first assignment statement irrelevant since it is overwritten anyway on the next line? Or does assigning a pointer to nil have a side affect? (I say a pointer because each City object has a pointer of type UIImage named "cityPicture". ) I think Chen may have spotted this first, but I wanted to put it on the blog.

05 May 2010

Bug in Task 2

Hello everyone,

Si-Young and I were working on Task 2. On page 141 the author mentions something about a bug in the program. The bug is that if we load an image after putting text in the City field, the City field will be empty once we return from adding an image. That doesn't happen in our program even before we added the code to fix the bug. We think that the error may be caused by the fact that the author is using an older version of iTouch. I'm not sure if we should bother adding the code to fix the bug on page 142. What do you guys think?

Thanks,
Paul Nguyen

Battery app on the iPad....

One difference between the iPad and the iTouch/iPhone app became apparent when I loaded the BatteryMonitor app on both devices.

The code runs on the iPad, but it is unable to determine the percentage charge on the battery. It does determine the battery state correctly. I will try to figure out:

1. How to determine what device you are using....
2. How to read the battery level on the iPad...

One difference between the simulator and the iTouch//iPad...

I was a little sloppy in naming my photos for the CityGuide app.....the case of the file names for the photos did not match exactly. On the simulator, this did not matter.

However, on the actual device (both Touch and iPad), it could not find the image if the case of the name does not match exactly.....

Thanks to Jeff for noticing this right away.

30 April 2010

Steve Jobs and Flash

http://news.cnet.com/8301-30685_3-20003742-264.html?tag=mncol;txt

This is an open letter from Steve Jobs about why the iPhone and iPad don't support Flash.

Empty Implementation of viewDidUnload?

I'm wondering about something from page 97 of the text--the method "viewDidUnload" contains no statements. I noticed that in the stub code generated by XCode for this method, a call to [super viewDidUnload]; was included. Don't we want that, or is it just not needed here? The IPhone Simulator will run CityGuide (seemingly just fine) either way, but it seemed odd to me that the textbook would call for an empty method body.

27 April 2010

iPhone Sky-Cam app for Spring Term Fair

I'm hoping that someone with an iPhone (vs. iPod, which currently has no camera) will choose to do some version of an app that Steve Goryl and have been discussing. Our original idea was to use a Parrot AR.Drone, or a blimp, but as these are currently either unavailable or two expensive, we came up with the idea of using a kite instead. The kite we ordered will easily hoist the 130-gram iPhone, allowing us (we hope) to transmit real-time video to a large-screen Mac or other computer on the ground. It could also transmit GPS info, orientation (from the accelerometer), etc. Please let me know if you're up for this project!

If you plan to develop on your own Mac....

...the IDE download is quite large (2.3GB). Steve Goryl has it available on a thumb drive; it may save you some time to grab it from him.