Elegant JSON Pretty Print for BBEdit

Working with JSON in BBEdit is great, but reading JSON is greatly enhanced by having it formatted nicely, and BBEdit doesn’t have anything (that I’ve found) which supports pretty printing JSON by default. A while ago I found this post http://crisp.tumblr.com/post/2574967567/json-pretty-print-formatting-in-bbedit which worked great, but I ran into this elegant little snippet. Inspired, I created a much simpler Text Filter for BBEdit:

(drop this file in your ~/Library/Application Support/BBEdit/Text Filters directory and then you can select it from BBEdit’s Text->Apply Text Filter menu.
0 notes

Give me back my ~/Library (!)

As a developer I need access to my Library directory, but Apple keeps hiding it from me with every OS update. Finally tired of manually typing chflags nohidden ~/Library/ every time it disappeared, I created a simple LaunchAgent to do this for me every time I log into my machine. Check it out:

As an aside, I’ll take this space to plug Lingon, which is a nice GUI tool for managing LaunchAgents and saves you from editing XML and dropping to the command line to talk to launchd.
0 notes

Override Deprecated API Warning

Sometimes I need to make a call to a deprecated API (for DEBUG builds only, of course) and don’t want to see the warning. This little preprocessor tip will hide that warning:

0 notes

CoreData Browsing

Found a handy tool for browsing core data on the simulator. It’s not very polished, but it allows you to perform fetch requests with predicates and get back results, which helps immensely when trying to understand what’s happening inside your app’s data at runtime.

Check it out:

http://atastypixel.com/blog/browsing-core-data-databases-using-f-script/

I also found this answer on SO which helped me get bootstrapped by giving the location of the two needed files in the simulator:

http://stackoverflow.com/a/5998072/397210

Happy CoreData spelunking!

P.S. @tomhoag suggested this https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/ as well… looks handy!

0 notes

Using NSURLProtocol for Injecting Test Data

I found this extremely useful for mocking up calls to network services.

0 notes

Asynchronous GHUnit Tests & Objective C Foo!

GHUnit is quite useful for running and reporting tests (unit or otherwise) for iOS projects, and I’ve been using it for a while with good results. Recently, however, I found as I wrote more and more integration-style tests with a remote HTTP service I found the code getting to be a pain to write and maintain. There were two reasons for this:

GHAssert variants fail with an Exception, and therefore other tests do not continue to execute.

This was a real drag, since the assert macros are pretty handy, but I want all my tests to run, even if some fail (<gasp> I know!).

So, I ended up replacing the GHAsserts with a simple conditional, which doesn’t feel as clean, but navigates around the issue.

Selector names became copy and paste heavy.

Since I’m making notification calls like [self notify:kGHUnitWaitStatusSuccess forSelector:@selector(testAsynchronousOperation)]; from within the same method it was additional grunt work to copy the selector name to all the places I needed a reference to the selector.

I thought of adding a SEL mySelector = @selector(foo); to each method, which would cut down on the copy & pasting, but that just didn’t seem clean to me.

I discovered there is an Objective C variable like self called _cmd which is a reference to the current selector(!). That’s cool, and simplifies code like my testing code a lot.

Sample

For the specific kinds of test cases I was writing, here’s an example which shows both of these issues resolved:
0 notes

Ongoing Resources for iOS Knowledge

Since my last post on learning iOS I’ve been asked about the Continuous section and what resources/people/blogs etc. I recommend following. To be clear, there’s no way to even scratch the surface for all the really great people in this community who should be paid attention to (I continuously find new great people and welcome introductions too!), so please don’t take this as a comprehensive list, but just a place to start… Also, it’s a good idea to keep up on Apple related news, but that’s a different beastie altogether.

Blogs

(in no particular order)

Tweeters

(in no particular order)
0 notes

opponeredraconem:

looking Rugged at the Rugged Maniac in Denver

opponeredraconem:

looking Rugged at the Rugged Maniac in Denver

(via opponeredraconem-deactivated201)

1 note

Ranged Random Numbers in Objective C

Sounds pretty basic, and it is, but like many things there are lots of ways to do it. This is my new favorite:

u_int32_t arc4random_uniform(u_int32_t /*upper_bound*/) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);

Based on discussions on StackOverflow and my own testing.

This assumes you’re on iOS 4.3 or later, however.

0 notes

Learning iOS

I’ve recently been asked a couple times about resources for developers who want to get into iOS development. I don’t pretend to be an expert, and am constantly learning myself, but these resources are ones I find useful, believe would be good for people just starting, and should certainly get you started. There’s lots of information out there, so don’t get too overwhelmed.

The First Place

I’d start is with a good book. Aaron Hillegass is the goto guy for learning Cocoa and Objective C.

Second, Apple’s documentation is quite good and will be your constant companion. Use the Documentation tab of the Xcode Organizer to search and browse the docs. There are many many sample code projects on various topics.

The docs are also online… some good starting places are:

View Controllers are the “main entry point” when using UIKit. It is important to understand them… many iOS devs do not (I was making fatal mistakes for my first year!). Read Apple’s View Controller Programming Guide until it makes sense.

Attend a Conference/Course

If you’re at all like me, you’ll most likely come away inspired and energized to build cool stuff. I’ve been to two 360iDev's now and loved them both. Highly recommend.

The Pragmatic Studio just announced a session which looks promising.

Continuous

Follow people on Twitter who talk about iOS and Cocoa. There’s a lot of people out there with a lot of experience.

This should lead you to some great blog posts and open source projects which will help you learn and grow, as they continue to do for me.

A great place to go for answers is StackOverflow. Search before you post… it’s probably been asked (and answered) already.

Lot’s to know

There is a difference between intelligence and knowledge. Do not sell yourself short.

Give Back

Probably about the most astounding thing I encountered when I first joined this community, for that is what it is, was the unselfish and unpretentious giving of knowledge and experience. There is an amazing amount of source code out there, for free. People are writing blogs and answering questions all the time. When you have the experience, pay it forward and help the community by sharing.

0 notes