iOS - First iPhone Application

Creating the First App

Now we are going to make a easy individual perspective program (a empty app) that will run on the iOS simulation.
The actions are as follows.
Step 1 − Open Xcode and select Create a new Xcode project.
Step 2 − Select Single View Application.
Step 3 − Get into the item name, i.e., the name of the program, organization name, and then the organization identifier.
Step 4 −Make sure that Use Automated Referrals Keeping track of is chosen in order to instantly launch the sources assigned once it goes out of opportunity. Click Next.
Step 5 − Select the directory for the project and select create.
Step 6 − You will see a screen as follows −

In the screen above, you will be able to choose the reinforced orientations, build and launch configurations. There is a area implementation concentrate on, the product edition from which we want to support, allows choose 4.3, which is the lowest implementation concentrate on permitted now. For now, these are not required and let's concentrate on running the program.
Step 7 − Now, select iPhone simulator in the drop down near Run button and select run.

Step 8 − That's it; you have successfully run your first application. You will get an output as follows −
 Now let's modify the qualifications shade, just to have a start with the interface designer. Choose ViewController.xib. Choose qualifications option in the right side, modify along with and run.
In the above venture, by standard, the implementation focus on would have been set to iOS 6.0 and auto-layout will be allowed. To make sure that our program operates on gadgets that are on iOS 4.3 forward, we have already customized the implementation focus on at the begin of development of this program, but we did not turn off auto-layout.

To turn off auto-layout, we need to deselect the auto-layout checkbox in the computer file examiner of each nib, i.e., the xib information. The various segments of Xcode venture IDE are given in the following determine (Courtesy: The apple company Xcode 4 Customer documentation).

File examiner is discovered in the examiner selector bar as proven above and automatic structure can be uncontrolled there. Auto structure can be used when you want to focus on only iOS 6 gadgets. Also, you'll be able to use many new functions like passbook if you increase the implementation focus on to iOS 6. For now, let's adhere to iOS 4.3 as the implementation focus on.

Code of the First iOS Application

You will find five different files that would have been generated for your application. They are listed as follows −
  • AppDelegate.h
  • AppDelegate.m
  • ViewController.h
  • ViewController.m
  • ViewController.xib

AppDelegate.h

// Header File that provides all UI related items. 
#import <UIKit/UIKit.h> 

 // Forward declaration (Used when class will be defined /imported in future)
@class ViewController;  

 // Interface for Appdelegate
@interface AppDelegate : UIResponder <UIApplicationDelegate>

// Property window 
@property (strong, nonatomic) UIWindow *window; 

 // Property Viewcontroller

 @property (strong, nonatomic) ViewController *viewController;
//this marks end of interface 
@end  
Important items in code −
  • AppDelegate gets from UIResponder that manages iOS activities.
  • Implements the assign techniques of UIApplicationDelegate, which provides key program activities like completed releasing, about to cancel and so on.
  • UIWindow item to deal with and co-ordinate the various opinions on the iOS system display. It's like the platform perspective over which all other opinions are packed. Generally there is only one screen for an program.
  • UIViewController to deal with the display circulation.

AppDelegate.m

// Imports the class Appdelegate's interface
import "AppDelegate.h" 

// Imports the viewcontroller to be loaded
#import "ViewController.h" 

// Class definition starts here
@implementation AppDelegate 


// Method to intimate us that the application launched successfully
- (BOOL)application:(UIApplication *)application 
 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
   
   // Override point for customization after application launch.
   self.viewController = [[ViewController alloc]
   initWithNibName:@"ViewController" bundle:nil];
   self.window.rootViewController = self.viewController;
   [self.window makeKeyAndVisible];
   return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
   /* Use this method to release shared resources, save user data,
   invalidate timers, and store enough application state information
   to restore your application to its current state in case it is 
   terminated later. If your application supports background 
   execution, this method is called instead of
   applicationWillTerminate: when the user quits.*/
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
   /* Called as part of the transition from the background to the 
   inactive state. Here you can undo many of the changes made on 
   entering the background.*/
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
   /* Restart any tasks that were paused (or not yet started) while 
   the application was inactive. If the application was previously in 
   the background, optionally refresh the user interface.*/
}

- (void)applicationWillTerminate:(UIApplication *)application
{
   /* Called when the application is about to terminate. Save data if 
   appropriate. See also applicationDidEnterBackground:. */
}

- (void)applicationWillTerminate:(UIApplication *)application
{
   /* Called when the application is about to terminate. Save data if appropriate.
   See also applicationDidEnterBackground:. */
}

@end
Important items in code −
  • UIApplication associates are described here. All the techniques described above are UI program associates and contains no customer described techniques.
  • UIWindow item is assigned to hold the program assigned.
  • UIViewController is assigned as the window's preliminary view operator.
  • To make the screen noticeable, makeKeyAndVisible method is known as.

ViewController.h

#import <UIKit/UIKit.h> 

// Interface for class ViewController
@interface ViewController : UIViewController 

@end
Important items in code −
  • The ViewController class inherits the UIViewController, which provides the fundamental view management model for the iOS applications.

ViewController.m

#import "ViewController.h"

// Category, an extension of ViewController class
@interface ViewController ()

@end

@implementation ViewController  

- (void)viewDidLoad
{
   [super viewDidLoad];
   // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
   [super didReceiveMemoryWarning];
   // Dispose of any resources that can be recreated.
}

@end
Important items in code −
  • Two techniques applied here are described in the platform category UIViewController.
  • Do preliminary installation in viewDidLoad which is known as after the perspective plenty.
  • didReceiveMemoryWarning method is known as in case of storage caution.

1 comments :

Write comments
veera
AUTHOR
3 September 2020 at 04:13 delete

Very nice post,keep sharing more posts with us.

Thank you....

ios online training

Reply
avatar