Creating first iPhone application - Get Started

An overview about the iPhone SDK

The iPhone SDK was announced officially on March 6, 2008, the first beta release was on July 11, 2008 which demanded a firmware update for all iPhone and iPod users. The SDK continued to develop with time until the Beta3 update to the 2.1 SDK was released on August 8, 2008.

The iPhone SDK package contents

The SDK is broken down to the following:

Cocoa Touch

The Cocoa Touch layer is one of the most important layers in iPhone OS. It comprises the UIKit and Foundation frameworks (UIKit.framework and Foundation.framework), which provide the basic tools and infrastructure you need to implement graphical, event-driven applications in iPhone OS.

It also includes several other frameworks that provide key services for accessing device features, such as the user’s contacts.

This framework is used to implement the core set of features.

  • Application management
  • Graphics and windowing support
  • Event-handling support
  • User interface management
  • Objects representing the standard system views and controls
  • Support for text and web content
  • Accelerometer data
  • The built-in camera (where present)
  • The user’s photo library
  • Device-specific information

Media

The graphics and media technologies in iPhone OS are geared toward creating the best multimedia experience available on a mobile device. More importantly, these technologies were designed to make it easy for you to build good-looking and -sounding applications quickly. The high-level frameworks in iPhone OS make it easy to create advanced graphics and animations quickly, while the low-level frameworks provide you with access to the tools you need to do things exactly the way you want.

  • OpenAL
  • Audio mixing and recording
  • Video playback
  • Image file formats
  • Quatrz
  • Core Animation
  • OpenGL ES

Core Services

The Core Services layer provides the fundamental system services that all applications use. Even if you do not use these technologies directly, every other technology in the system is built on top of them.

  • Networking
  • Embedded SQLite database
  • GeoLocation
  • Threads

OS X Kernel

The Core OS layer encompasses the kernel environment, drivers, and basic interfaces of the operating system. The kernel itself is based on Mach and is responsible for every aspect of the operating system. It manages the virtual memory system, threads, file system, network, and inter-process communication.

The drivers at this layer also provide the interface between the available hardware and the system frameworks that vend hardware features. Access to kernel and drivers is restricted to a limited set of system frameworks and applications. iPhone OS provides a set of interfaces for accessing many low-level features of the operating system.

Your application accesses these features through the LibSystem library. The interfaces are C-based and provide support for the following:

  • Threading (POSIX threads)
  • Networking (BSD sockets)
  • File-system access
  • Standard I/O
  • Bonjour and DNS services
  • Locale information
  • Memory allocation

Develop your first iPhone application:

Things you need before going any further:

  • A “MAC OS X” platform of version 10.5.3 or later. You can get an original MAC box or you can simply get one of the hacked versions of the MAC OS, for more information click here.
  • The iPhone SDK “Software Development Kit” you can get one from the iPhone developer program home page, or simply click here.
  • Xcode, the IDE “Integrated Development Environment” used to develop applications and software for MAC based platforms. Although one of Xcode’s goals is to reduce the time you spend writing code, you still devote a considerable part of your development in the text editor. To that end, the text and source editor provide many features with the aim of making your source-code editing a productive and efficient endeavor. Code folding, code completion, Edit All in Scope, Refactoring, and other features allow you to focus your attention on the right areas and to use your time as efficiently as possible. It’s packed with the iPhone installer, so no need to worry about it.
  • Interface builder, this application lets you design compelling user interfaces graphically. Your work is saved as nib files that your application loads at runtime. This means that you what you design is exactly what users of your application see; you work with the actual controls that iPhone OS places on the users’ screens. It also means that you spend less effort codifying the user-interface–related aspects of your application in source code. It’s also supplied in the SDK package.

Other developing applications you may use:

  • Debugger, as you start testing your application, you may need to step through your code to the cause of unexpected behavior. Xcode’s debugging facilities provide the usual debugging features, such as breakpoints, viewing variables, and so forth. But Xcode provides these and other debugging features right in the text editor. That is, you can make a change in your code, add a breakpoint, start your application, and perform most debugging tasks in the same window.
  • Instruments, as you near the end of the development process, you must ensure your application uses the resources of the device on which it’s running as efficiently as possible, so that battery power is not wasted and your application does not gather system resources unnecessarily. “Instruments” shows your application’s resource usage, including memory, CPU, and network, in a graphical timeline that lets you see how your application behaves over time.

The MVC design pattern:

The structure of iPhone applications is based on the Model-View-Controller (MVC) design pattern because it benefits object-oriented programs in several ways. MVC–based programs tend to be more adaptable to changing requirements—in other words, they are more easily extensible than programs that do not use MVC. Furthermore, the objects in these programs tend to be more reusable and their interfaces tend to be better defined.

In the MVC design pattern, the model layer consists of objects that represent the data your application manages. The objects in this layer should be organized in the way that makes the most sense for the data. External interactions with model objects occur through a well-defined set of interfaces, whose job is to ensure the integrity of the underlying data at all times.

The view layer defines the presentation format and appearance of the application. This layer consists of your application’s windows, views, and controls. The views can be standard system views or custom views you create. You configure these views to display the data from your model objects in an appropriate way. In addition, your view objects need to generate notifications in response to events and user interactions with that data.

The controller layer acts as the bridge between the model and view layers. It receives the notifications generated by the view layer and uses them to make the corresponding changes in the data model. Similarly, if the data in the data layer changes for other reasons (perhaps because of some internal computation loop), it notifies an appropriate controller object, which then updates the views.

Developing the iCalculator application:

Here is a fast overview of what we will do:

  • Creating the project.
  • Implementing the Model Object.
  • Implementing the Controller Object.
  • Implementing the View Object by use of the “Interface Builder”.
  • Customizing the app delegate to incorporate the view controller object, and add it to the application window.
  • Connecting the view controller to its view.
  • Finalizing the application and setting its icon.

Creating the project

1) Launch Xcode. You can find it in the developer folder > Applications > Xcode.

2) Choose File > New Project.

3) Choose from the iPhone OS templates.

4) Choose Window-Based Application.

5) Name your project “iCalculator”.

Figure 1: New Project.


Figure 2: The iCalculator Project.

Note:

iCalculator.app: The application binary, the project’s product. It’s in red because the product hasn’t been built yet.

iCalculatorAppDelegate.h, iCalculatorAppDelegate.m: The files that implement the application’s delegate.

MainWindow.xib: The nib file that defines the application’s main window. Despite its name, iPhone applications normally have only one window.

Implementing the Model Object

We will create a new class whose instance represents an object of the calculator, follow the following steps:

1) Click on the “Classes” folder.

2) Choose File > New File.

3) Choose Cocoa Touch Classes > NSObject subclass.

4) Name the class “iCalculator”, make sure that creating the header file option is selected.

5) Insert the following Code into iCalculator.h:

Figure 3: iCalculator.h.

6) Insert the following Code into iCalculator

Figure 4: iCalculator.m part I.

Notes for newbies:

1) The “retain” and “release” methods are used mainly in the memory management of iPhone applications, that’s because there isn’t any garbage collection in the iPhone OS.

Thus, memory management is done manually; you can’t simply call “dealloc” to free the resources and references of a certain object, because this object may contain references to other objects that will not be de-allocated, and thus will cause memory leaks, so we use retain which will increment the value of a certain variable for this instantiated object, and release decrements the value, and when it reaches zero, the referenced object is de-allocated.

For more information about this topic, read more about memory management in Objective C++ 2.0.

2) If ( Self = [ super init ] )

What does this mean? This means that init of the parent class “NSObject” function will be called and if self is not equals to null do the following.

Figure 5: iCalculator.m part II.

Figure 6: iCalculator.m part III.

Implementing the controller object:

1) Click on classes.

2) Choose File > New File

3) Choose iPhone OS> Cocoa Touch Classes > UIViewController subclass.

4) Name the class “iCalcViewController”.

5) Modify the iCalcViewController.h header file as the following:

Figure 7: iCalcViewController.h

6) Modify the iCalcViewController.m file as the following:

Figure 8: iCalcViewController.m part I.

Figure 9: iCalcViewController.m part II.

Implementing the View Object

To get users excited about your application, it should have the best user interface possible. Interface Builder allows you to build beautiful, more importantly, useful user interfaces by dragging controls from a library of user-interface elements and laying them out n a view as you want them to appear to the user, your user-interface designs are known nib files. Your application loads these resources at runtime to reconstitute the use interface you designed. This means that you can make substantial changes to the user interface layout (and even some behavior) without having to edit source code. This is the main benefit of the Model-View-Controller paradigm.

1) Expand the “Resources” folder.

2) Double click on “mainWindow.xib” and the interface builder will open.

3) From the interface builder choose File > New file.

4) Choose Cocoa Touch and then press on View.

Figure 10: iPhone OS UI templates.

5) Choose save, name it as “CalcView” and navigate till you reach the location of your project and save it under the “Resources” folder and press ok.

6) Xcode will ask you to update the project to accommodate the new file, confirm this process.

7) Press on the File’s Owner icon.

a. Choose Tools > Inspector.

b. Display the identity pane.

c. In the Class text field enter “iCalcViewController”, note that it will auto-complete.

And by this way, we’ve connected between our view object and the controller object.

Figure 11: “calcView”’s Components.

8) Press on the View icon.

a. Choose the Inspector Attribute pane.

b. Customize your view as you desire, here we changed the background’s color to black.

Figure 12: “calcView”’s View designer.

9) Add input and output controls to the view

a. Choose tools > Library.

b. In the organization pane, select Library > Cocoa Touch Plug-in > Inputs & Values.

c. Select the Text Field item and drag it to the View.

Figure 13: Drag and drop components.

d. Resize the text field, by enlarging it, such that it contained by most of the view’s width.

Figure 14: resize text field.

e. Display the Inspector Attribute pane.

f. Set the text field text to 0.

g. Set the alignment to right-align.

h. Set the title typeface and size, by setting the focus on the text field in the view > Choose Fonts, set it to bold and size 36.

Figure 15: Set font.

i. Add a rectangular button.

  • Choose “Round Rect Button” from the library and drag and drop.
  • In the inspector size pane, set the button’s width to 64 and height to 70.

Figure 16: Set font.

  • Connect the button’s “Touch Down” event to the “press:” action method of the “iCalcViewController” class.
  • Select the button in the view
  • Display the Inspector Attributes pane.
  • Set the title color to black.
  • Set the button title to 7.
  • Set the font size to 48.

Figure 17: Set button attributes.

j. Create the button grid:

  • Choose the button from the view.
  • Choose Edit > Duplicate.
  • Position the clone beside the original button.

Figure 18: Clone the button.

  • Select both buttons and do exactly as the previous steps.

Figure 19: Clone the two buttons.

  • Select the four buttons and with the same steps we can generate the following view.
  • But by changing the text of each button and making sure that the action event of each button is the “press” method

Figure 20: The final calculator view.

Editing the application delegate:

1) Double click on the iCalculatorAppDelegate.h to modify it, edit it to look like this:

Figure 21: iCalculatorAppDelegate.h.

2) Double click on the iCalculatorAppDelegate.m to modify it, edit it to look like this:

Figure 22: iCalculatorAppDelegate.m.

Connecting the View controller to the View

As mentioned before, we have connected between the view and the controller, but that was an initial connection.

We have to be more precise, for example we have to mention which controls do certain actions, and which preview certain data, so here is what we have to do:

1. In the CalcView.xib window, select the File’s Owner proxy (which represents an instance of the “CalcViewController” class).

2. In the Inspector Connections pane, connect the displayField outlet to the text field in the view.

Figure 23: Connecting the view with the controller.

3. Connect the view outlet to the view.

4. Save the “CalcView.xib” file.

Note: If you pressed on one of the buttons, you will find that their action event handler is already set, as we set it before during designing the view to the “press” function.

Setting the application icon

1. In Interface Builder, take a snapshot of the Calc button grid:

a) Place the pointer at the top-left corner of the grid.

b) Press Shift-Comand-4 and hold down the mouse button.

c) Drag the pointer to the bottom-right corner of the grid and release the mouse button.

Figure 24: Taking a snapshot.

Mac OS X places the snapshot file in your desktop using the name Picture 1.jpg (or a name with a higher number if you’ve captured other snapshots).

2. Rename the snapshot file, icon.jpg.

3. In the Groups & Files list, select Resources.

4. Choose Project > Add to Project.

5. Navigate to your Desktop directory and choose icon.jpg.

6. In the dialog that appears, ensure the copy option is selected, and click Add.

7. In the Groups & Files list, double-click Resources > Info.plist.

8. In the editor window, set the value of the Icon file key to icon.jpg,

Figure 24:Info.plist.

9. Save the Info.plist file.

Running your application

Build your application and run it on your simulator, if you have an iPhone connected to Xcode you can choose to deploy and run on it.

Please not that, you have to have a developer’s certificate from apple to develop for iPhones, which will cost you $99 or $299 a year depending on what kind of certificate you want, for more details click here.


(courtesy : http://www.datasprings.com/Resources/ArticlesInformation/iPhoneSDKGettingStartedExampleCode/tabid/911/language/en-US/Default.aspx)


conflicker remedy tips

Conficker Timeline

The Last Watchdog has compiled a simple timeline to show the evolution of Conficker that begins with Chinese hackers selling a $37 malware kit in September 2008 designed to exploit a security hole in Windows, and ends with what infected PCs will do come April 1 2009.

Conficker C Analysis

The computer science laboratory at SRI International, sponsored by the National Science Foundation and the U.S. Army Research Office, has released a detailed analysis of Conficker C.

Ensure you've got the latest Microsoft patch

Microsoft recommends you manually download the Windows Malicious Software Removal Tool. Note: This is not a replacement for anti-virus software, rather an additional defense.

Disable Autorun

PC World suggests disabling Autorun so that your machine won't be automatically infected when you connect to infected removable media. A how-to can be found here. Note: This involves changing the registry file on Windows and should only be done by those confident in their abilities.

Search for and destroy Conficker with F-Secure

F-Secure has a free and easy-to-use tool to check for and remove worms; including the dreaded Conficker.

Use McAfee's Stinger which will update daily in preparation for April 1

McAfee has created a special build of its standalone cleaning tool Stinger which it will be updating daily to include any new Conficker variants.

No Download: Scan on the Web

Create a free account (registration required) with Panda Security's ActiveScan to perform an online scan of your machine.

Program Files folder in X64

I find this very useful while dealing with msi on 64bit OS.

While qualifying one of our projects for X64, we encountered issue with Program Files folder.

We use Wix for building msi package.

Wix could get %PROGRAMFILES% variable from OS and place files appropriately at C:\Program Files (x86)\

But our product was looking at C:\Program Files.

I prefer picking up any paths from app.config files and delegate task to Wix to update application specific configuration files during installation. This makes life so simple when moving between x86 and x64.

Here I am referring to running x86 stuff as is on x64. Rules change when we compile code for X64.

(Courtesy : Sriharsha Vardhan (sriharshavardhan.blogspot.com)



Kidz/Stundent Laptop

There is a huge hype of netpc/mini laptops around by every manufacturer.
I wonder why these guys do not concentrate on OEM kind of stuff spefic to kidz or stundents.
They can comeup with disney laptops which has all kiddie games and learning applications with minimal software for kidz and low end atom processor
Similarly for stundents, same atom processor with all stundent/express editions of softwares.
Im sure this should attract a good portion of market.

Windows Mobile Recite

Windows mobile recite..a voice search looks gr8 except that it gives ur first recording if your search doesnt match any

Top 5 bad smells in the code

As i feel below are the top 5 bad smells in the code which shoud be taken care while desinging or atleast at refactoring time.

1.       Temporary variables: sometime there will be too many unmanageable temp variables which actually carry some useful object data. Its always good to design class with needed private attributes.

2.       Duplicate Code: undoubtedly this is one of the bad smell in the code. Refactor to a common method when a piece of code/logic is widely used in the program.

3.       Huge Class : a big fat class for the complete functionality. This is quite common mistake that we pack the whole functionality(sometimes usecase) into one class.

But we forget the fact that all the attributes and state of the object of the class lives long in which some part may not be needed in all given instances. So while designing classes we have to take utmost care.

4.       Classes with no encapsulation : most of the times we use class very freely

With attributes as public. Which is very dangerous. Attributes have to be properly encapsulated based on the semantic of the class and should provide the access modifiers for these attributes.

5.       Objects hide internal details. Encapsulation leads to delegation.    

     Sometimes this goes to far.If you look at the interface of a class and find that half of the methods     just delegate to another class it may be time to use Remove Middle Man and talk to the object that really knows what is going on.

Gulon Mein -- another feather for Mohit

Gulon Mein rang bhare..... another soothing and refreshing number sung by Mohit Chouhan in the film Sikandar.
If you are stressed with hectic schedule...wanna refresh...just plug-in your earphones....play..Gulon Mein....you will be entirely into another world...
i give five stars to Justin-Uday.

Editing PRN file

This is not exact solution for the PRN file edit issue , but should be useful.

 

First when you print to file, do the below stuff

 

Add a new local printer - When prompted for which port to use(LPT1, LPT2, etc.), select "File:" and click "Next"
When prompted for a printer manufacturer and model, scroll down the manufacturer list to "Generic" and then select "Generic / Text Only" in the printers column.
Complete the rest of the prompts to your preference.

Now when you print to this Generic/Text Only printer, it will prompt you for a file name. Give it a filename and path. Once it's done, you can edit the file using notepad.

 

Alternatively you can use Hex Editors(as PRN is hex coded file) to edit it.

Use can use Ghost Script or Multiply program as editors to do it.

 

By printing to a file, the file on disk is in a format suitable for printing, but not suitable for manipulation or editing.  When attempting to open it, the file will appear as "garbage" because it's a binary

file, not a file format most word processors can manage.  You can print the file, you can send it via modem to someone else, or you can hand the file on disk to another individual

 

Alternatively you can convert a PRN file to another format like word etc and edit it.