Archive for the ‘apple’ Category

By now it seems everyone has some form of opinion on the announced Nokia and Microsoft collaboration. Most of the opinions I’ve read or heard essentially state that Nokia risks becoming a low-margin hardware manufacturer while Microsoft may benefit hugely from using Nokia’s market share to spearhead their reattempt to enter the mobile operating system (OS) war.

So what’s in it for Nokia? I think it depends hugely on the unannounced details in the deal. If Nokia gets some form exclusivity on the Microsoft Windows Phone OS and accompanying app store that they can leverage then I think Nokia’s CEO may have made a very smart move. Nokia wants to avoid Google’s Android OS, which is rapidly becoming a lowest common denominator OS for a variety of manufacturers (for example, Samung, HTC and Sony Ericsson). The best situation for Nokia would probably be if they had their own version of Apple’s iOS. However, for various reasons Nokia failed to execute on this very sensible strategy (the OSs Symbian, Maemo, Meego are seen as non-viable today). Hence the conclusion is that Nokia has now realized their engineering divisions are simply incapable of creating a competitive OS and ecosystem that can rival Apple’s iOS. However, Microsoft can, indeed they have already done this with the Windows Phone OS. Contrary to popular opinion it is a very well-designed system. If you haven’t tried it, you may think Windows Phone is the Windows Mobile disaster all over again. It is not. Try it! Thus Microsoft provides Nokia with their very much wanted exclusive OS and ecosystem that Nokia can use to avoid being diluted to just another hardware manufacturer for Google’s Android OS. However, it really depends on the details in the deal with Microsoft. There is a long list of companies that tried to collaborate with Microsoft and failed miserably. Perhaps this is the first move before a full-scale Nokia takeover by Microsoft? It may not necessarily be a bad move for either company.

When I design an iPhone app I tend to use Interface Builder. However, I always forget how to actually connect the widgets (buttons, labels and so on) in Interface Builder to variables I can reference in my Objective-C code in Xcode. Hence this post. Note that this is one approach, there are several others. However, the procedure I describe below is beneficial as it is quite simple, yet usually all that is required.

Step 1. Design some widgets using Interface Builder

The way I usually do it is to simply start a new project, open the Resources tab in the Groups & Files sidebar, and then double-click on a pre-generated Interface Builder XIB file (for example, MainView.xib).

(Note: The screen captures and code fragments I will show below are from a simple project that was automatically generated from the Utility Application code template provided by Apple. A Utility Application project has two default views: a MainView and a FlipsideView. The procedure I describe works for any iPhone application, so if you don’t understand references to FlipsideView and other objects then just ignore them for now.)

Then I design some rudimentary user interface, like this one (click for a larger image):

Step 2. Create outlets in your code

OK. So we have designed a user interface using Interface Builder. Now, how do we access all these widgets in our code? Here I will describe how we are going to connect the button labeled Next in the above screen capture to a variable named nextBtn.

You have now declared that your class contains a UIButton instance, and this instance variable can be accessed via an IBOutlet. However, no code has been generated to set the value of this variable yet. To do so, open up the corresponding implementation file (for example, MainViewController.m) and introduce the following line somewhere below the @implementation declaration:

@synthesize nextBtn;

Step 3. Connect Interface Builder widgets to your outlets in Xcode

Now that we have created the necessary instance variables and outlets we can open up Interface Builder and connect the widgets to the corresponding variable declarations in the code. First, select File's Owner in Interface Builder’s Inspector window:

Then open the Connections Inspector (Command-2). In the Outlets section you will see a small connector (circle) to the right of a label named nextBtn. If you hover over the connector it will highlight and turn into a plus-sign. Click it and drag the blue thick line that appears to the button in the interface you wish to connect to nextBtn. See below for an illustration (click to enlarge):

Step 4. Create actions for your Interface Builder widgets

The next step is to implement a method that will be called when an action is triggered for the button. To do this we first add the following function prototype to the header file (for example, MainViewController.h):

- (IBAction)respondToButtonClick:(id)sender;

Thereafter we add a function body to the implementation file (for example, MainViewController.m):

Now we need to tell Interface Builder which function it should call when nextBtn is pressed. Open up Interface Builder again and click on the button in the user interface which we previously connected to the nextBtn variable. The Connections Inspector will change and show you a list of possible actions this button can take. Now click on the connector (circle) for the action Touch Up Inside and drag it to File's Owner in the Inspector (click for a larger image):

A menu will pop up and propose possible methods in your code that could receive the action:

Now we can run the program on an iPhone or via the emulator. Whenever you press the button labeled Next a message appears in the console (click to enlarge):

Voila! You can now access the button labeled Next using the nextBtn instance variable in your code. Further, whenever a user presses this button, your method respondToButtonClick: will be invoked and execute any custom code you insert here.

The above procedure used a single button for illustration purposes. However, this procedure generalizes to all widgets and actions supported by Interface Builder. Have fun!

How do you transfer files from an iPhone app to a desktop machine? One would think this is easy. As it turns out, it is relatively easy but not very intuitive.

What you need to do is to locate the property list (.plist) file for your app in Xcode (it is typically found under Resources in the Groups & Files panel). The file is usually called Application-Info.plist (replace Application with whatever the name of your project is). Open the file in plain text mode and then append the following:

<key>UIFileSharingEnabled</key>
<true/>

Now run your app on the iPhone. Then do a sync. Thereafter open iTunes, select the Apps tab, and scroll down. You will see a new section named File Sharing. You can use this section to transfer files generated by an iPhone app to your desktop machine. It will look something like this (click the thumbnail for a larger image):