Categories
Development

Xcode Error: Could not insert new outlet connection

Stack Overflow: “I got into a similar state just today. It was very odd: I could attach any XIB (new or existing) to any already-existing ViewController class in the project, but I could not create a new ViewController and have it attach properly to any XIB. The “assistant” functionality didn’t work, nor did the IB-to-headerfile-connection functionality.”

This has become an everyday annoyance so I’m documenting the link to the “fix.”

Categories
Business Development

The realities of app development

Shifty Jelly Weblog: “It’s no surprise that most people don’t understand the sheer volume of effort that goes into creating and maintaining an application. Two years ago we didn’t really understand that either, and we launched so many new applications without thinking through the consequences.Who could forget our Pocket Weather AU app on Android, something which we’ll soon fix, but which has to go down as one of our biggest mistakes of all time. It turns out with just 2 developers and 1 designer, we can’t maintain 10 different apps…”

Yes, even mobile apps take time to build.

Categories
Apple Development

WWDC tips from @buzz

Apptentive Weblog: “It’s hard to pick one thing, but when I was working for Square and flying out to SF every 6 weeks or so, I had kind of a tradition of taking the N Judah out to Ocean Beach every Sunday to have a cappuccino at Trouble Coffee, brunch at Outerlands, check out a few shops I like out there (General Store and Mollusk Surf Shop), and then walk along the beach up to the Cliff House. If you’re feeling ambitious, you can even walk back through Golden Gate park and catch the N in the Haight. It’s exactly the kind of uniquely California experience you want out a visit to SF.”

I’m not going to WWDC this year, but I wanted to make sure I had a link back to this for next year. Who knows, maybe someone I know will also find it useful.

Categories
Development

Old Man Coder

Nick Bradbury: “And because of the years we’ve spent creating software, we’ve learned what works and what doesn’t, regardless of the language or the platform. Operating systems rise and fall, development tools come and go, but through it all, old farts know how to write solid code.”

Great piece.

Us old guys gotta stick together.

Categories
Business Development

Responsive Developer

Red Sweater Blog: “In this case, I discovered a bug in MarsEdit 3.5.2 (and 3.5.1, as it happens) that would cause the blog settings editing panel in MarsEdit to fill up all of a blog’s settings with default values when you opened it to tweak a blog. Then, if you innocently click “OK”, wham, all your blog settings are updated with default settings. Not good.”

I use MarsEdit to manage this weblog as well as the Apple Core Labs weblog. It’s a great piece of software and I have a lot of respect for its creator: Daniel Jalkut. Every developer makes mistakes. It comes with the territory. Daniel made a mistake and fixed that mistake as soon as he discovered it. It’s nice to see a developer be so responsive. Hats off.

Thanks for the great software, Daniel.

Categories
Development Indie iOS

Get Shacked

Get Shacked: “If you are a web / mobile designer, and would like to come out for a few months, and work on one of our many app ideas, send us a link to your portfolio. If we like what we see, we will fly you out and put you up in your own grass shack (it will have a roof, don’t worry). What better way to try out living in Hawaii then cruising out here for a 3 month workcation. We work hard and play hard also!”

Who’s with me? Let’s go to Hawaii! I’ll bet it would be easy to convince my wife to spend a bit of time there.

The company is Shacked and I discovered them because of this great little app, TeleTweet. How cool is that?

Categories
Development

Call Stacks

I find it interesting how deep we tend to go as developers when we’re building on top of other code. I’ve been debugging a memory leak in our app and this is part of a call stack for a potential culprit.

	ntdll!RtlLogStackBackTrace+7
	ntdll!RtlpAllocateHeap+C4
	ntdll!RtlAllocateHeap+23A
	msxml6!LEVEL2::operator new+16 (d:\w7rtm\sql\xml\msxml6\core\base\pointer.cxx, 68)
	msxml6!AddPointerToCache+70 (d:\w7rtm\sql\xml\msxml6\core\base\pointer.cxx, 204)
	msxml6!SlotAllocator::NewPage+40 (d:\w7rtm\sql\xml\msxml6\core\base\slot.cxx, 546)
	msxml6!SlotAllocator::Alloc+98 (d:\w7rtm\sql\xml\msxml6\core\base\slot.cxx, 339)
	msxml6!Node::operator new+26 (d:\w7rtm\sql\xml\msxml6\xml\om\node.cxx, 257)
	msxml6!Node::newNode+F (d:\w7rtm\sql\xml\msxml6\xml\om\node.cxx, 295)
	msxml6!Node::_clone+1C (d:\w7rtm\sql\xml\msxml6\xml\om\node.cxx, 2971)
	msxml6!Node::clone+13 (d:\w7rtm\sql\xml\msxml6\xml\om\node.cxx, 3028)
	msxml6!Node::cloneChildren+66 (d:\w7rtm\sql\xml\msxml6\xml\om\node.cxx, 3080)
	msxml6!Node::clone+63 (d:\w7rtm\sql\xml\msxml6\xml\om\node.cxx, 3050)
	msxml6!Node::cloneChildren+66 (d:\w7rtm\sql\xml\msxml6\xml\om\node.cxx, 3080)
	msxml6!Node::clone+63 (d:\w7rtm\sql\xml\msxml6\xml\om\node.cxx, 3050)
	msxml6!Node::cloneChildren+66 (d:\w7rtm\sql\xml\msxml6\xml\om\node.cxx, 3080)
	msxml6!Node::clone+63 (d:\w7rtm\sql\xml\msxml6\xml\om\node.cxx, 3050)
	msxml6!Node::clone+34 (d:\w7rtm\sql\xml\msxml6\xml\om\node.hxx, 486)
	msxml6!DOMNode::cloneNode+9A (d:\w7rtm\sql\xml\msxml6\xml\om\domnode.cxx, 1642)
	msxml6!W3CDOMWrapper::cloneNode+17 (d:\w7rtm\sql\xml\msxml6\xml\om\w3cdom.cxx, 254)

It’s kind of fascinating, isn’t it? Notice all the steps we go through to allocate memory. All the way from Node::operator new up to the actual call into the NT runtime, RtlAllocateHeap.

Categories
Development

Instagram Stack

Instagram LogoInstagram Engineering: “We thought it would be fun to give a sense of all the systems that power Instagram, at a high-level; you can look forward to more in-depth descriptions of some of these systems in the future. This is how our system has evolved in the just-over-1-year that we’ve been live, and while there are parts we’re always re-working, this is a glimpse of how a startup with a small engineering team can scale to our 14 million+ users in a little over a year.”

Go read this post, if you haven’t already. It’s amazing how much the company has changed in just a little over a year.

I wonder how long it’s going to take to transition all this content to Facebook servers? Will they even attempt to do it? The integration of the systems will be fun to watch. From a DevOps perspective it’ll be a great challenge. Hopefully Facebook will leave most of the stack alone and move the parts that can be moved fairly easily. I figure the actual storage of photos is one area that could come over fairly easily. Facebook has some caching mechanisms that could work right away, but all-in-all I think I’d leave most of the Instagram infrastructure in place. Why? Because it’s working.

Their new infrastructure sure beats where they were on October 6, 2010.

“On Wednesday, October 6, 2010, Instagram launched its mobile photo sharing service for iPhone. In six hours, the back-end operation, which was running off a single machine in Los Angeles, was completely overwhelmed.”

That’s right, all of Instagram was hosted on one computer. Amazing.

Categories
Development

Objective-C Objects from JSON

I was asked recently how to create an Objective-C Object from a JSON result returned by a RESTful service. Man, that’s a mouthful.

It’s actually fairly easy, especially if you make use of the excellent JSONKit by John Engelhart. The example below does just that.

For starters I created a simple Cocoa Application and changed main() so it returns 0, because we don’t need to show a window and have an event loop. Here’s a link to the complete main.m.

Next add JSONKit.m and JSONKit.h to your project, and build. That’s it. It should just work.

Here’s what the code does.

For starters we define some sample JSON. This is very rudimentary. The object contains a firstName and lastName field. This is meant to represent the data returned by our pretend REST service.

static NSString* const kSampleJSON = @"{\"firstName\": \"Rob\", \"lastName\": \"Fahrni\"}";

Next up we define a Person interface.

@interface Person : 
    NSObject
{
@private
    NSString* _firstName;
    NSString* _lastName;
}

@property (copy) NSString* firstName;
@property (copy) NSString* lastName;

- (id)initWithDictionary:(NSDictionary*)dict;
- (void)dealloc;

@end

Again, very simple. This Person interface has first name(_firstName) and last name(_lastName) members and is initialized by passing it an NSDictionary*. So far, it looks pretty easy, right? Right!

The next thing we need to do is implement Person. Once again, no rocket science here. It’s straight Objective-C.

@implementation Person

@synthesize firstName = _firstName;
@synthesize lastName = _lastName;

- (id)initWithDictionary:(NSDictionary *)dict;
{
    if ((self = [super init]))
    {
        _firstName  = [dict valueForKey:@"firstName"];
        _lastName   = [dict valueForKey:@"lastName"];
    }
    
    return self;
}

- (void)dealloc;
{
    [_lastName release];
    [_firstName release];
    
    [super dealloc];
}

- (NSString*)description
{
    // Overriding description allows you to print something meaningful
    // to the debug output window. In this case we'll print 
    // Rob Fahrni.
    return [NSString stringWithFormat:@"%@ %@\n", _firstName, _lastName];
}

@end

Ah! Now we’re getting somewhere. Notice the Person is constructed with an NSDictionary* that should contain at least two entries; firstName and lastName. Note “firstName” and “lastName” just so happen to match our simple JSON constant, defined as kSampleJSON. That’s because it’s the source of our data.

Something else of note is the method description. By overriding NSObject description we allow NSLog to dump something meaningful when we give an instance of Person as an argument. You’ll see that used below. It’s darned handy when you’re debugging.

UPDATE 12/31/2011: I noticed I’d used objectForKey instead of valueForKey when assigning to _firstName and _lastName.

Finally we can test our code to see what it does.

int main(int argc, char *argv[])
{
    // Pretend like you've called a REST service here and it returns a string.
    // We'll just create a string from the sample json constant at the top
    // of this file.
    NSString* responseJSON = [NSString stringWithFormat:@"%@", kSampleJSON];
    
    // 1) Create a dictionary, from the result string,
    // using JSONKit's NSString category; objectFromJSONString.
    NSDictionary* dict = [responseJSON objectFromJSONString];
    
    // 2) Dump the dictionary to the debug console.
    NSLog(@"Dictionary => %@\n", dict); 
    
    // 3) Now, let's create a Person object from the dictionary.
    Person* person = [[[Person alloc] initWithDictionary:dict] autorelease];
   
    // 4) Dump the contents of the person object
    // to the debug console.
    NSLog(@"Person => %@\n", person);

    return 0;
}

That’s all there is to it? Yep, that’s it! Pretty simple, right?

Categories
Development

Mike Ash on Objective-C Blocks

Duct Tape, fixer of all things!Mike Ash: “Both Objective-C blocks and C++0x lambdas have the same basic goal: to allow writing anonymous inline functions. Called closures, blocks, lambdas, or just anonymous functions, these are a common feature in higher level languages. They are extremely useful for building convenient, succinct libraries for things like array iteration, multithreading, delayed computation, and many others.”

Mike explores Objective-C Blocks and C++ Lambdas. This article is six months old, but it’s still very relevant and great as always. If you’re a Cocoa Head you should definitely add Mike’s RSS feed to your preferred news reader.