"Lets elevate the tone shall we" Steve Jobs quote.

Posts Tagged: xcode

Finger Lag

This helped me think differently about some multitouch finger based meat lag problems I’m having, and hopefully solve them.

http://blog.parse.com/2012/07/12/loading-remote-images-in-a-table-view/

Looks good, I’ll have to try it out. Might simplify one of my projects. 

Text

I wish Xcode had the ability to Scaffold up iOS View Controllers like Ruby on Rails does. 

I’m repeating myself in code all the time at the moment. 

Text

For what ever reason (bug?)  you can’t delete local calendars you have created via the iPhone’s Calendar app. 

A few lines of code can however. Which of course you need to super careful when running because you can easily erase Calendars you actually want and then have that propagated over iCloud before you can say “Oh fuck…”

EKEventStore *eventStore = [EKEventStore new];

    for (EKCalendar *thisCalendar in eventStore.calendars){

        NSLog(@”Calendar: %@”, thisCalendar.title);

        if ([thisCalendar.title isEqualToString:@”My Calendar”]) {

            NSError *err;

            [eventStore removeCalendar:thisCalendar commit:YES error:&err];

            if (!err) {

                NSLog(@”deleted %@”, thisCalendar.title);

            } else {

                NSLog(@”%@”, err.localizedDescription);

            }

        }

    }

Text

If you’ve got iCloud for Calendars turned on then any EKSourceTypeLocal calendars you create won’t show up. 

I just turned off iCloud Calendar synching and a bazillion calendars I’d created programmatically just showed up. 

Cant seem to delete them though with the Calendar app… 

Hmm…

Scrolling with UIScrollView

A useful straight forward pattern for putting UIView content in a UIScrollView on iOS using a XIB.

In my last project I’d just StoryBoards in iOS5 with a TableView and a Static cell, which is easily stretchable to house the content and can be designed visually in IB. But that wasn’t what I wanted for my current project and the linked technique works a treat.

Text

Glad to see Xcode 4.3.2 is as crash happy as ever. Thank goodness some things never change. 

Things you can rely on in life:

  1. Death
  2. Taxes
  3. Xcode crashing

Text

Whilst Current Geek Me enjoyed writing this SELECT statement for mySQL

SELECT id, price, lesson AS l, CONCAT((DATE_FORMAT(start_date, ‘%a %D %b %Y : ‘)), IF(DATE_FORMAT(start_date, ‘%i’) = ‘00’, LOWER(DATE_FORMAT(start_date, ‘%l%p’)), LOWER(DATE_FORMAT(start_date, ‘%l:%i%p’))), ’ - ‘, IF(DATE_FORMAT(end_date, ‘%i’) = ‘00’, LOWER(DATE_FORMAT(end_date, ‘%l%p’)), LOWER(DATE_FORMAT(end_date, ‘%l:%i%p’))), ’ : $’, price) AS d, start_date AS sd, end_date AS ed, longdesc AS f FROM `cookingSchool` WHERE (start_date >= ‘2012-01-01 03:33:28’) ORDER BY start_date ASC

I’m sure Future Me is going to hate me when I have to change it.

Lazy coding: I know SQL better than I know how to chop up strings in Obj-C. 

My current approach with iOS coding is to just return some JSON with the strings just how I like so I have to do as little in Obj-C as possible. My justification is that the iOS device has limited processing power and my big chunky server has CPU cycles and disk to spare. I’ll just keep saying that until it isn’t true any longer. Probably around the time the iPhone 5 arrives.

Text

So you add a button to Cell on a TableView on your Storyboard. Then you want to get the Cell index of the cell when you click the button. Probably because you then want to to fetch the correct data from an array or whatever. 

Here’s the code you need. 

Assuming you have an action on a button, like this:

- (IBAction)buttonClick:(id)sender

UIView *senderButton = (UIView*) sender;

NSIndexPath *indexPath = [self.tableView indexPathForCell: (UITableViewCell*)[[senderButton superview]superview]];

NSLog(@”%i”, [indexPath row]);

Xcode 4 Code Snippets

Also: http://www.icodeblog.com/2011/12/06/using-xcode-4-snippets