iPhone Address Book API

Was looking through the dev docs and trying to learn more about it.  Guess what?

The Address Book classes doc are not updated.  Have to search for the Address Book Programming Guide for iPhone OS in the net.  This is much better doc as compared to the online xcode dev doc.

Now to work on that address book.

p.s

There are two Address Book API.  One for MacOS X and the other for iPhone OS.  The API for iPhone does provide the basic functionality that I need.  However, I really want some functionality catered for MacOS X.

gdata objective client 1.10.0

Downloaded the API about 2 weeks ago.  Now’s the time to replace the existing  1.9.

Should be same for me as still using only the Spreadsheet API.  Later, will need to find a way to store last modified file so as not to download if requested.

Maybe that’s for version 1+.

Import vcard using GData

Looking into importing vcard using GData.

Likely to be using some sort of contacts and address for a project.  What’s a better way than using an open standard such as vCard as payload.

Have done some code for GData for spreadsheet import and export.  Need to find some examples for this.  Could be a really useful code to have for managing contacts.  Also, will be using ABAddressBook API which is handy with vCard.

vCard is text based.  Simply put the contents of the vcard into one of the spreadsheet cell.  Then import as string and then convert to NSData for use when needed for address.

controllerDidChangeContent is your best friend when using CoreData

If you are using CoreData, most likely you need to be informed of changes to your table when you have either uploaded or deleted data.

The best way is to use this callback to update the table.  Sample code below:

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
// The fetch controller has sent all current change notifications, so tell the table view to process all updates.

//    reload the list of region
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:0];
[array addObject:@"All"];
NSEnumerator *region = [[fetchedResultsController sections] objectEnumerator];
id <NSFetchedResultsSectionInfo> sectionInfo;
while (sectionInfo = [region nextObject]) {
[array addObject:[sectionInfo name]];
}
wineRegionList = array;
wineRegionIndex = 0;

//    reset region to default value
regionVC.wineRegionList = wineRegionList;
regionVC.wineRegionIndex = wineRegionIndex;
[regionVC.tableView reloadData];
[array release];
}

The GodFather of Energy Efficiency

A group of prominent scientists has proposed that “the Rosenfeld,” a unit for electricity savings, be named after Bay Area physicist Arthur Rosenfeld.

The 83-year-old Berkeley resident is known as the “godfather” of energy efficiency and served on the California Energy Commission from 2000 to January this year.

“The Rosenfeld” would be defined as electricity savings of 3 billion kilowatt-hours per year, the amount needed to replace the annual generation of a 500-megawatt coal-fired power plant. Rosenfeld often uses the example of power plants when explaining the benefits of energy efficiency to students.

A lazy man’s guide to cutting energy costs

Not sure why people here in Singapore aren’t that crazy about measuring energy usage.  People here prefer to spend more on air-conditioner than considering other factors.

Singaporeans also like to complain about the tariffs hike, but do near to nothing when trying to conserve energy use.

Not like in places where they place sensors and controllers within the house to measure peak, off peak and usage patterns to reduce energy cost.

Best way is to follow A lazy’s man guide to cutting energy costs.

UISearchBar together with TableView working with Core Data

This is interesting.  Got some examples of UISearchBar and the like of capturing the text input and resignFirstResponder when finished with search.

Core Data has good examples of tableView and how to retrieve and display data.

However, not much info is available, even from books, blogs and others on how to use UISearch with an existing TableView with data from Core Data.

Seems like you are on your own when using these 3 related APIs. Together, these 3 APIs can give you the best way to view and search data fetched  using Core Data.

Core Data gives you good memory management when using a large database.  Data is faulted, read from the database for viewable cells.  No need to create a huge array to hold the data.

One way to differentiate which table to display; i.e. normal or searched can be dependent on

// when we start/end showing the search UI
- (void) searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
useSearch = YES;
}

- (void) searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller
{
useSearch = NO;
}

You can use this flag to determine which table to view for your UITableViewDelegate methods.

// called when cancel button pressed
- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar {
searchBar.text = nil;
[searchBar resignFirstResponder];
[searchBar setShowsCancelButton:YES animated:YES];

//    reset the fetch search controller
fetchedSearchResultsController = nil;
}

You also need to reset the fetchedSearchResultsController at the end of search.  Have to make sure that search results are refreshed upon new search.

Category: Core Data  One Comment

Also reading other iPhone books from library

Besides the Core Data book, I have also borrowed two other iPhone books for my bedtime reading.

Programming the iPhone User Experience expands on the required Apple HIG.  Good read, especially on parts of iPhone UI that you seldom use.

The iPhone Developer’s Cookbook has lots of sample code that I may use later.  Wish I had this book earlier.  Although a bit outdated, but still great as a reference.

OK and no point buying these books as you can get them from the library when you need them.

TableView and TableViewCell again

Although the tableview and tableViewCell are probably one of the first you will learn when starting the iPhone SDK.  Most of the time, you will just mangle it using some of the more popular and easy way to populate the cell.

For me, I found using this way works out best for me.

Create all the necessary labels in init. For each labels, create a function to return CGRect that describe the actual position and layout.

CGSize ratingSize = [rating.text sizeWithFont:[UIFont boldSystemFontOfSize:24.0]];

self.contentView.bounds.size.width

Use the bounds sizes and get the label  CGSize to determine  required space for the label.

In your layoutSubViews, [sizeLabel setFrame:[self sizeLabelFrame]];

Now, you can put labels exactly where you want it in your TableCell.  This should work for other views too.

PS.  This will be important when you port your iPhone app to iPad should you need  shouldAutoRotate.

Category: iPhone  Leave a Comment

Borrowed the Core Data book from library

Guess what?  The author Marcus is actually the famous blogger at Cocoa is My Girlfriend.  Got lots of good tips from him, especially the iPhone chapter.  Give me better insight to the Core Data API.

Highly recommended reading