Swift Weekly – Issue 02 – The Swift Runtime (Part 1)

In this edition, I wanted to write about arrays and dictionaires and take the easy route. But I thought to myself: wouldn’t be cool if _somebody_ dug deep into the Swift runtime for crying out loud? Then I thought that I cannot wait for somebody to do that so I’m going to have to do that myself. So here, this edition of Swift Weekly is about the Swift runtime. At least the basics.

Please note that I am using a disassembler + dSYM file. I am disassembling the contents of the AppDelegate with some basic code in it and then hooking my disassembler up with the dSYM file to see more details.

Also in this article I am testing the output disassembly of Xcode 6.1 on the x86_64 architecture, not ARM which is available on iOS devices.

Continue reading this article on Swift Weekly’s Github page: https://github.com/vandadnp/swift-weekly/tree/master/issue02

Loading a Nib file, Programmatically (Objective-C)

If you want to load a Nib file at run time by simply allocating and initializing a View object, then you should take a rather strange approach to how you create your class files. Suppose you have a subclass of UIView called MyView and what you want is to allocate and initialize an instance of MyView but have MyView load its outlets and actions from a Nib file. Well, you will need to do two things:

  1. In Interface Builder, change the class name of your View object to MyView.
  2. Then you will have to override MyView’s initWithFrame method like so:

- (id)initWithFrame:(CGRect)paramFrame
{

NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"MyView"
owner:nil
options:nil];

if ([arrayOfViews count] < 1){
[self release];
return nil;
}

MyView *newView = [[arrayOfViews objectAtIndex:0] retain];
[newView setFrame:paramFrame];

[self release];
self = newView;

return self;

 

}

Then you can go ahead and initialize your view like this:

MyView *myView = [[MyView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:myView];
[myView release];

And here an instance of MyView will get added to the view of a view controller. That simple. I hope it helps some of you out there 🙂

Mac OS X Lion is out

Only for developers though! It’s a developer preview version. Here is what Apple said today:

Apple today released a developer preview of Mac OS X Lion, which takes some of the best ideas from iPad and brings them back to the Mac for the eighth major release of the world’s most advanced operating system. Lion features Mission Control, an innovative new view of everything running on your Mac; Launchpad, a new home for all your Mac apps; full-screen apps that use the entire Mac display; and new Multi-Touch gestures. Lion also includes the Mac App Store, the best place to discover, install, and automatically update Mac apps. The Lion preview is available to Mac Developer Program members through the Mac App Store today, and the final version of Lion will ship to customers this summer.

Have you tried it? Do you like it? What do you think about the king?