Archive for November, 2009

Snippet: Core Data JSON

Oooh, this is extra-nifty: If you’re using Core Data for your app’s data model, as if you’re requiring 3.0+ for your apps you probably should be, and if you’re using JSON for your data interchange as you almost certainly are, here is an awesome snippet that — with the support of blakeseely’s bsjonadditions project — makes dumping your NSManagedModels into JSON as simple as

[coreDataModel jsonStringValue]

Can’t beat that, can you?

h/t: iPhoneFlow!

Continue Reading →
2

Snippet: Array shuffling

Need to quickly shuffle an array, for a deck of cards or whatever? Here’s categories for NSArray and NSMutableArray to do that simply:

- (NSMutableArray*) shuffle {
   NSUInteger n = [self count];
   while (n > 1) {
      NSUInteger k = rand() % n;
      n--;
      [self exchangeObjectAtIndex: n withObjectAtIndex: k];
   }
   return self;
}

The algorithm used here is the Fisher–Yates shuffle which we’ve forgotten far more numerical analysis than we’d need to have an actual opinion about, but hey if it’s popular it must be good, right?

Continue Reading →
0

UIAlertView tables

Ever want to pop up a custom UIAlertView with a list of options in a table? That looks like this, for instance?

locationresults.png

Well, here are part 1 and part 2 with sample project of how to do exactly that!

Continue Reading →
0

Shiny buttons

What’s better than an iPhone app? Why, a shiny iPhone app, of course! At least, an iPhone app with shiny buttons, which we’ll discuss today. You may recall a previous post on faking it with single segmented UISegmentedControls, but well, those just don’t work exactly the way buttons should.

The easy way to do a real button that’s shiny is to Photoshop a stretchable background image and extend UIButton slightly to use it, and here are instructions and code on how to do that; but rather than loading up our app with bitmaps, wouldn’t it be great to create arbitrary colored glossily gradiented buttons in code? Why yes, yes indeed it would. And here’s how.

Shiny Red Buttons!

Essentially, it’s wrapping Matt Gallagher’s gloss gradient code

gradientSample.png
Ooooh! Shiny!

into UIButton extensions, with some other goodies like round rect clipping and SMS.app-style bubbles. Enjoy!

h/t: The Flying Jalapeno Lives via iPhoneFlow!

Continue Reading →
0
Page 2 of 2 12