January 11, 2012, 4:14 pm
I’m storing birthdays in Core Data, and now I want to get a list of entities sorted by the day of their birth. However, I just cannot sort by the date, since the year of their birth would take precedence, I just need to sort by the month and day of the NSDate stored as the birth date.
The big problem that I faced was trying to find out how to get the Julian date from an NSDate. Well as it turns out, Julian date does not correctly describe what I was looking for, I needed to look for ordinal date.
After a bit of investigation, I was able to put together this category that I have hung off of NSDate in my app:
- (int)ordinalDate
{
return [[NSCalendar currentCalendar] ordinalityOfUnit:NSDayCalendarUnit
inUnit:NSYearCalendarUnit forDate:self];
}
This, along with a sortUsingComparator of my NSMutableArray of contacts, is exactly what the doctor ordered.
BTW, Happy Birthday to the Grand Canyon National Monument, created this day in 1908, which eventually became the Grand Canyon National Park. (Yet another must see place.)
January 4, 2012, 1:52 pm
I found this one out the hard way.
If you are doing simple attribute additions when you transition from one Core Data model version to another, you can just create a new model version, set your overall data model’s default to the new version, and add the needed attributes to the entities as you need. When you fire up the app, the new fields are magically added to the table without any additional work.
However, when you want to rename an attribute, if you follow the above series of steps, the data that exists in the fields corresponding to the old attribute name is now replaced with a shiny new nil. Outstanding!
I guess I didn’t read the Apple Core Data docs well enough. Make sure that, when you add your model version and rename the attribute, make sure that you can see the Utilities view on the right side of the Xcode 4 window, click on the attribute you are renaming, click on the Data Model inspector (the third icon in the Utilities view, looks like a little database cylinder with an eye patch on it), and for the Renaming ID entry, type in the old name of the attribute. Once you do this, the data in the field should migrate forward.
Luckily, I didn’t blow away too many beta user’s data discovering this one.
BTW, a posthumous Happy Birthday to James Bond, the ornithologist whose book Ian Fleming had on his bookshelf and reportedly named his super spy character after.
December 31, 2011, 11:25 pm
Yup, yet another “year in review”.
There was the good. I finally got my Batter vs. Pitcher app into the App Store, and found my way to a new job that was way better than the one I had previously.
There was the bad. The passing of Steve Jobs, Dennis Ritchie, and unfortunately my beloved male schipperke Kirk hit home for me, and the Pirates turned a June first place NL Central tie into yet another sub-.500 season.
There was the ugly. My November presentation to the Columbus iPhone Developer User Group comes right to mind, and then of course there was that whole thing with being able to play MP3 files on my brand new Samsung Charge Android phone.
Here’s hoping that all of you out there have a safe and happy new year, and that 2012 is better than your 2011.
December 9, 2011, 10:08 am
Samidip Basu gave a very informative presentation on OData as it applied to the Columbus M3 Conference that took place in November of 2011, and how he put together a Windows Phone app that consumed the Azure hosted data.
As it was at the December CONDG meeting two years ago, I won a totally crappy T-shirt, and gave it to a former co-worker. Which made the evening that much more successful.
BTW, Happy Birthday to the Petrified Forest National Park, established this day in 1962. The petrified logs and the Painted Desert are fantastic, I highly recommend a trip there.
November 28, 2011, 10:31 am
Just in case you were wondering how to use a UIButtonTypeInfoLight (or UIButtonTypeInfoDark) as a UINavigationItem (a la UIBarButtonItem), here is what I threw together. Put this code in your view controller’s viewDidLoad method:
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeInfoLight];
button1.frame = CGRectMake(0.0f, 0.0f, 40.0f, 32.0f);
[button1 addTarget:self action:@selector(aboutButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *aboutButton = [[UIBarButtonItem alloc] initWithCustomView:button1];
self.navigationItem.leftBarButtonItem = aboutButton;
[aboutButton release];
Adjust the frame to your taste, and supply the aboutButtonPressed method with an (id)sender parameter, and you are good to go.
November 23, 2011, 11:42 am
Thanks to everyone who turned out on Tuesday night for my CIDUG presentation on utilizing open source iOS projects. The presentation went a bit longer than I was hoping, largely due to the volume of demos that I had.
If you would like to download a PDF of the presentation, here is a link:
Open Source iOS Projects presentation
Also, if you would like to download a ZIP file of all of the demos that I did, here is a link for that:
Open Source iOS Projects demos
I realized this morning that what I should have done was to create a workspace, and then drag all of the individual projects into that one workspace for the demo. I have done this in the code that I uploaded, so when you unzip the demos file, just open the Demo projects.workspace file and then just use the Scheme selector at the top of the Xcode window to select which demo you want to look at or try out.
Please let me know if you have any questions or suggestions on the presentation or the demo code. I hope everyone out there has a safe and happy holiday season.
November 11, 2011, 4:01 pm
It has been a while since I have made a post, so I figured I would take this opportunity to point out that, if you are ever putting together a UITableViewCell (such as in the cellForRowAtIndexPath delegate method), there is a big difference between this:
cell.backgroundColor = [UIColor redColor];
And this:
cell.contentView.backgroundColor = [UIColor redColor];
Or, if you are creating an NSSortDescriptor, there is a big difference between this:
sortDesc = [[NSSortDescriptor alloc] initWithKey:@"sortOrder" ascending:YES];
And this:
sortDesc = [[NSSortDescriptor alloc] initWithKey:@"sortOrder" ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)];
Happy Nigel Tufnel day and Last Binary Day Of This Century (11/11/11) to everyone!
October 25, 2011, 9:30 pm
Ran Flasterstein gave a presentation tonight about his experiences in communicating with users of his apps. He mainly spoke about the ways that he encourages conversation with his users through feedback and e-mail.
Next month at the CIDUG meeting, I will be giving my presentation, Open Source iOS Projects. Hopefully, since the meeting date is only a couple of days before Thanksgiving, there will be fewer folks there for me to inflict my wit and wisdom on.
BTW, happy birthday to the pride of Kelvington, Wendel Clark. In my humble opinion, they should not even bother giving any other Leaf the C.
October 14, 2011, 9:16 am
A couple of years ago, I wrote a blog post about displaying and dismissing a view controller in an iPhone application. To get rid of your view controller from within that view controller, you would simply run this line of code:
[[self parentViewController] dismissModalViewControllerAnimated:YES];
Alas, with the update to iOS SDK version 5, this no longer works. And in fact, if you spelunk through the UIViewController.h file, it does say that as of 5.0, it will no longer return the presenting view controller.
Luckily, you can just do this instead:
[self dismissModalViewControllerAnimated:YES];
BTW, happy birthday to Roger Moore, star of the excellent films “The Cannonball Run” and “ffolkes”.
October 5, 2011, 7:40 pm
Love him or hate him, our industry lost a real visionary today.
Over the next days and weeks, depending on who you listen to, there will be many words used to describe Steve Jobs. Which words are true? The simple answer is that all of them will be true, and none of them will be true.
The reason for this apparent contradiction is because that he was an individual that defied convention. Sure, not all of his ideas and products were slam dunks, but who among is so perfect as to measure up to our own ideals?
Simply put, a lot of Apple’s products are flat out awesome. Oh, and by the way, did I forget to mention that Steve ideas and products brought about massive changes in the computer industry, the consumer electronics industry, the motion picture industry, and the music industry?
Yes, kind words even though Steve killed the Newton platform and caused my software development company in Florida all sorts of problems back in 1998. I just wish I had bought the stock back then when it was right around the $20 level.
Steve, you will be missed.