— Shang Liang

Archive
iphone

In Xcode 3, this is an option to select whether the project uses core data features. If it’s checked, Xcode automatically generates the code to set up the environment. Most of the examples about core data is based on the codes generated by Xcode. However, this feature is taken out in Xcode 4.This post is a guide of how to add the code manually in Xcode 4. Based on that, here’s my version of a simplified routine (it’s only 7 lines without the comments) .

>>Enjoy<<

Read More

I had a weird error when working with Core Data. The App crashes without giving anything information. After adding break points here and there for  a few hours, I narrowed that the problem is caused by failure to retrieve the NSManagedObjectModel file. I re-created another project and re-created the xcdatamodeld file from scratch and everything works fine. I suddenly remember I edited the xcdatamodeld file with vim when entering the attributes. That must be the reason.

I’m not 100% sure what happened but here’s my guess. The data model file is versioned automatically in Xcode 4. If I edit the “content” file directly, the versioning is disturbed and the IOS won’t be able to locate the “mom” file properly inside the “momd” folder.

Read More

The library is great and it’s very simple to implement. You can follow the instructions on Google to get things ready.

When calling the function, assuming trackPageview, it will be like this

NSError* error;
[[GANTracker sharedTracker] trackPageview:@"/page name" withError:&error]

Just two things to note:

  1. the page name must start with forward slash “/”
  2. withError cannot be nil. If you set the “error” as nil, the system will give you a runtime error.

Read More

I’m spoilt by other IDEs and used to see all my files in my project folder are sorted alphabetically. Xcode does not do that automatically. The newer files are located at the bottom of the folders by default. However, you can drag and drop to arrange them.

I accidentally found out that there is a “Sort” function in the “Edit” menu. Select the folder you want to sort and apply. It will list the files by name or by type based on your choice.

I guess the reason for Xcode not to sort files automatically is due to usability issue. As I am working on my project, some files are seldom opened and some files are edited constantly. It’s quite convenient to drag the more frequently used files onto the top.

Read More

I was following the instructions on this website but I didn’t manage to get the custom fonts working. After trying for a while I found out the problem.

Here’s the updated details of how to use custom fonts in iPhone. This is only available for SDK 4.0 and above.

  1. Add your custom font files into your project using XCode as resources.
  2. Add a key to your info.plist file called “Fonts provided by application” ( Used to be called UIAppFonts).
  3. It’s an array key.
  4. For each font you have, enter the full name of your font file (including the extension).
  5. Save info.plist.
  6. Now in your application you can simply call [UIFont fontWithName:@"CustomFontName" size:12] to get the custom font to use with your UILabels and UITextView.
  7. “CustomFontName” is not the font’s file name. It is the font name registered in the operating system. For example, if you try to use “Bauhaus Medium BT.ttf”, the “CustomFontName” should be “Bauhaus Md BT”, no extension “.ttf” is needed. You need to install the font in your system to find out what name it is. Some fonts have 2 names, you may need FontForge to find out and try which one works.
  8. So far I found out that both ttf and otf format work out of the box. I haven’t tested other font formats yet.

*Points 1-6 credit to http://blog.beefyapps.com/

Read More

Looks really fun!

This one is definitely done in Objective-C.

Read More

Developing iPhone stuff with Cocoa, Objective-C and xCode? Take a look at www.vikingsmackdown.com. If you don’t have an iPhone, you can view the video in this article from TechChurch.

I thought it was built with the accelerometer and stuff but it was just JavaScript! It listens to a Safari browser event, “onorientationchange”. So technically, it’s not motion sensing. It’s a very old JavaScript event “onresize”. All other phones with a rotatable browser can also implement this diea.

More information of developing JavaScript based applications or games can be found at Apple Web Apps DevCenter.

Read More