Nick Harris

Archive for March 2010

UIAlertView with an NSObject

with 3 comments

Here’s my situation… I have an operation that gets performed in the background. If that operation fails I need to alert the user and see what they would like to do about it. If they want to retry it, I just add the operation back onto the queue.

To do this, I’m sending a notification that the operation failed and am including the operation as the notifications object. I then set up a responder on my view controller for that notification. It creates a UIAlertView to ask the user what to do.

If the user selects “Retry”, it would be nice to have the operation right there on the alert view in alertView:clickedButtonAtIndex: so that I can just add it back to the operation queue. But there doesn’t seem to be any properties on UIAlertView for an arbitrary object. Instead I’ve subclassed UIAlertView and simply added a NSObject property.

Pretty easy code wise, just wondering if I’m missing something on UIAlertView that would handle the same thing.

Written by Nick Harris

March 26, 2010 at 5:00 pm

Posted in Code

Tagged with

Finding a FavIcon URL

with one comment

Being relatively new to objective-c, I was wondering what people thought of this code. The idea was to find the favIcon URL from a string of HTML. Is this the fastest/most efficient way without using RegEx?



NSScanner *htmlScanner = [NSScanner scannerWithString:htmlString];

while ([htmlScanner isAtEnd] == NO)


[htmlScanner scanUpToString:@"<link" intoString:NULL];

if(![htmlScanner isAtEnd])


NSString *linkString;

[htmlScanner scanUpToString:@"/>" intoString:&linkString];

// we have a link element.  does it have rel set to anything we want?

if(([linkString rangeOfString:@"rel=\"shortcut icon\""].location != NSNotFound)||

  ([linkString rangeOfString:@"rel='shortcut icon'"].location != NSNotFound)||

  ([linkString rangeOfString:@"rel=\"icon\""].location != NSNotFound)||

  ([linkString rangeOfString:@"rel='icon'"].location != NSNotFound)||

  ([linkString rangeOfString:@"rel=icon "].location != NSNotFound))


// yep, grab the href

NSScanner *hrefScanner = [NSScanner scannerWithString:linkString];

[hrefScanner scanUpToString:@"href=" intoString:NULL];

if(![hrefScanner isAtEnd])


[hrefScanner scanString:@"href=" intoString:NULL];

NSString *hrefString;

// scan up to a space. 

// if we don't hit one cause the href was the last thing in the element, we don't care

[hrefScanner scanUpToString:@" " intoString:&hrefString];

// clean up any quotes

hrefString = [hrefString stringByReplacingOccurrencesOfString:@"\"" withString:@""];

hrefString = [hrefString stringByReplacingOccurrencesOfString:@"'" withString:@""];

// we're done, return

return hrefString;





return nil;


Written by Nick Harris

March 24, 2010 at 10:11 pm

Posted in Uncategorized


with one comment

Hi. I’m Nick. I write software.

I’ve written Windows apps, Windows services and Outlook plugins in Delphi and C#, Firefox plugins in Xul and javascript, RIA applications in Silverlight, Windows Mobile apps in C#, and most recently iPhone apps in Objective-C.

I work for NewsGator Technologies and am also the founder of Sirrahsoft LLC.

I use to have a blog called NewsGator Inbox but since Inbox is no longer a product I’ve pretty much stopped writing there.

The plan for this blog? Share things that I’ve learned over the last 8 years of writing software and hopefully give back a little to the community that has taught me so much.

Hopefully it will be interesting too!

Written by Nick Harris

March 24, 2010 at 9:29 pm

Posted in Uncategorized