Thursday, 21 November 2013

ObjectiveC Basic For Extreme Begginers

  

                                        Basic For Programming 

Are you extremely new to programing, don't need to be worry just need to know these basic terms to start learning any programimg language .


  • Variable : Variable is one whoes value vary within a program . such as   var x = 15;
  • Function : — var name = John.getName();
  • Loop — for (var x = 0; x < 10; x++)
  • Conditional — if (== 20)
  • Array — var things = array("dog", "cat");

  • Now let's talk about Objective-C.

    Introduction To Objective-C

    Objective-C is the language that most Mac and iOS developers use to write native applications. There are alternative ways to write Mac and iOS apps .
    If you're looking to build mobile websites or web apps then you don't need to learn Objective-C or Cocoa and probably don't need to go any farther in this tutorial. If you're looking to learn a new programming language and build native apps for the Mac and iOS, then this is the place for you!

    • Objective-C is a superset of C programming language, which makes C object oriented.

    • It was developed by Brad J. Cox at Stepstone Corporation in early 80’s, by adding Smalltalk-80 extensions to C-language.

    • It was originally the main language on NextStep OS which was further adopted by Apple.

    • It is used by Apple as a primary language to develop applications for MAC system and iPhone.


    Objective-C, C and Smalltalk
    • Objective-C is an object oriented programming language that combines features of both, C and Smalltalk.
    • Objective-C extends the procedural C-language with the addition of some new keywords and compiler directives, and uses Smalltalk style for sending messages to objects.
    • The extension of C language into Objective-C is made possible by a runtime library (libobjc) that is generally transparent to the developer.
    • It is possible to compile any C program with Objective-C compiler and therefore, code written in C-language can be freely included in any Objective-C class.
    • Syntaxes of all non-object oriented operations in Objective-C are identical to that of C-language and object oriented operations are the implementation of Smalltalk style messaging.

    • Features of Objective-C

    Being a derivative of C and Smalltalk, Objective-C comprises many features:
    • It is an object-oriented version of C-language.It is a powerful language which is easy to learn and sophisticated to work with.
    • Better understandability of code.
    • Programmer can use both object oriented and procedural programming strategies as per the requirements.
    • It provides open dynamic binding via Objective-C runtime library which makes it true object oriented.
    • It also uses protocols for implementing multiple-inheritance.


    Objective-C: Programming fundamentals:

    To write an Objective-C program, it requires basic knowledge of programming in C-language and object oriented concepts. As Objective-C is primarily used by Apple, providing its own developer tool (Xcode) for developing MAC and iPhone applications, a developer can also write programs on Terminal window by using the GNU Objective-C compiler (gcc).

    Data Types is Objective C :
    Data type specifies the type of data a variable holds. In Objective-C, the primitive data types are same as that of C-language and some new data types are also included in its library that are as follows:
    Type Description
    • char   A character of the local character set
    • int An integer (whole numbers), e.g. 1, 2, …
    • float Floating point number, e.g. 1.2, 1.7, 5.8, …
    • short A short integer
    • long     A double precision of short
    • double A double precision of float
    • signed Specifies a integer value either +ve or –ve
    • unsigned   Specifies only +ve integer values
    • Bool     Used for conditions, either True(1)/False(0)
    • id Used to store  reference to an object

     Identifiers:
    An identifier is any combination of alphanumeric characters that specifies a variable, type, function or class in the program.
    An identifier must start with alphabet and may include underscore and digits but with limited length, for example,
    int a=5;

    Here a is an integer type variable, whose identifier is a.

    Note that a keyword can never be used as an identifier.



    Literals:

    Literals are constant values that are stored in variables.

    There are 5 types of literal constants that are generally used while programming namely, Integer, Floating-point, Characters, String and Boolean values, for example, when we wrote:

    a = 3;

    3 is the literal constant in this statement.



    Integer literals: Numerical constants that identify integer values are called integer literals, for example,
                      512           : Decimal value

                      023           : Octal value

                      0×2           : Hexadecimal value



    Floating-point literals: Numerical constants that identify decimal and exponential values are called floating-point literals, for example,
                      4.5           

                      4.5e12      : 4.5 x 1012



     Characters literals: Non-numeric constants with single characters within single quotes are called character literals, for example,
                      ‘x’



     String literals: Non-numeric constants with collection of characters within double quotes are called string literals, for example,
                     “hello! This is a string literal”



    Boolean literals: There are only two values: true and false, and these are represented as values via type bool by literals true and false. 

    Constants:

    Constants are values that never change. Other than using literal constants while programming, we can also declare or define constants as per our requirements.

    Declaring constants

    Constant can be declared by using keyword- const, as prefix with the type of variable as follows:

    const int aAsconstantinteger = 10;

    const float bAsconstantfloat = 5.2; 

     Now, the values of these two variables cannot be modified as they are declared as constants.  

    Defining constants 

    Constants can also be defined by the developer with a desired name via using #define preprocessor directive as follows:

    #define pi 3.14

    Now, this constant pi can be used in the code directly.   

    Common Objects & Functions

    Regardless of what your app looks like there are some objects, functions and data structures that you'll use over and over so it's important to become familiar with them.

    NSString

    A string is a sequence of characters, and in Objective-C, a string is an NSString object with a lot of built-in functionality. The shorthand way of referring to a string @"looks like this" with an @ sign in front of a double-quoted run of characters. NSStringobjects can be compared to one another, converted to other encoding formats, used to hold the contents of a file or URL, changed to C-style strings, used in regular expression matches or turned into numbers.
    Once you create a string it cannot be modified. This may sound odd if you're coming from PHP or JavaScript, but if you want to modify a string after it has been created, you should use NSMutableString instead, a mutable (modifiable) subclass of NSString.
    Here's an example of how you might construct an NSURL object by using a string:
    NSURL *url = [NSURL URLWithString:@"http://google.com/"];
    And here's an example of using a mutable string:
    NSMutableString *myString = [NSMutableString stringWithString:@"Reading"];
    [myString replaceOccurrencesOfString:@"Read" withString:@"Writ"
      options:NSLiteralSearch range:NSMakeRange(0, [myString length])];

     TheNSMutableString instance method -replaceOccurrencesOfString:
    withString
    :options:range:
     finds a string within a string, then replaces it with something else. Notice the call to the NSMakeRange() function, part of the Foundation framework. It returns anNSRange struct data type which has two members: location and length.

    NSArray

    An array is an ordered collection of things and if you're using NSArray, those "things" all have to be objects. Just like with an NSString, once it's created it cannot be modified unless you useNSMutableArray instead. Here's an example of making an array:
    NSArray *myArray = [NSArray arrayWithObjects:@"Fish", @"Dogs", nil];
    When creating an NSArray using the +arrayWithObjects: class method, the list of objects needs to be nil-terminated or it won't compile. It's not very intuitive at first, but it's important to remember to add it at the end of your list of objects or your code will crash and burn.
    Organizing objects into an array is useless if you never do anything with your new collection. Here are some examples of what you can do with a filled array.
    id myObject = [myArray objectAtIndex:3];
    [myArray makeObjectsPerformSelector:@selector(runTowardsTheMoon)];
    NSUInteger howMany = [myArray count];
    The -objectAtIndex: instance method returns an id, a generic object in Cocoa. Since you can hold any type of object you want in an NSArray, when you access an object it gives you back a generic object type. It doesn't know what types of objects are being stored. Also, in the second example, what's a @selector? A @selector in Objective-C is basically a method signature. In this example, we're telling each object in the array to call their -runTowardsTheMoon instance method. In the third example the method returns anNSUInteger, a Foundation framework primitive type that's an unsigned integer, that is, an integer that's greater than zero.

    NSDictionary

    Almost all languages have the concept of a data structure that holds key-value pairs. Perl and Ruby have hashes, Python has dictionaries, PHP has associative arrays and Objective-C has the NSDictionary class. The Foundation framework provides us with NSDictionary(and its mutable brother NSMutableDictionary) to hold key-value pairs where all keys and values have to be objects. Let's define some dictionaries:
    NSDictionary *myDict = [NSDictionary
      dictionaryWithObjectsAndKeys:@"aObj", @"aKey", @"bObj", @"bKey", nil];
    NSArray *objs = [NSArray arrayWithObjects:@"One", @"Two", @"Three", nil];
    NSArray *keys = [NSArray arrayWithObjects:@"Blue", @"Green", @"Yellow", nil];
    NSDictionary *anotherDict = [NSDictionary
      dictionaryWithObjects:objs forKeys:keys];
    In the first example we're calling the class method +dictionaryWithObjectsAndKeys:which has to be nil-terminated just like with some NSArray methods. In our object listing at the end we alternate object, key, object, key until we're done with all the pairs.
    In the second example we're creating two different NSArray objects — one to hold the keys and another to hold the objects — and then we pass these two arrays into theNSDictionary class method +dictionaryWithObjects:forKeys: to build our dictionary. Again, notice that we're not using +alloc or -init to manually allocate memory for these dictionaries. This means we don't have to worry about their memory or calling -releasewhen we're done using them.
    A common use of NSDictionary is within an array: each element in the array is anNSDictionary object. For example, if you're building a Twitter app, the information for each tweet could sit in an NSDictionary, then each of these dictionaries is kept in order within an NSArray.
    // First, find the dictionary in the 4th position in the array.
    // Then, access the object paired with the key "tweet_text"
    NSString *status = [[myArray objectAtIndex:4] objectForKey:@"tweet_text"];
    Organizing NSDictionarys within an NSArray is a simple way to store some structured data.

    NSNumber

    If you want to store a primitive number in an NSArray or NSDictionary you'll have to package it up into an NSNumber object first. NSNumber has a number (ha!) of convenient class methods so you'll rarely need to manage the memory yourself.
    NSNumber *myNumber = [NSNumber numberWithInt:326];
    int myInt = [myNumber intValue];
    You can get the primitive value of an NSNumber object just as easily as you can store it.

    NSLog()

    NSLog() is a C function to send output to the console, useful when debugging your application.
    NSArray *myArray = [NSArray arrayWithObjects:@"Yo", @"Hey", nil];
    NSLog( @"My array: %@", myArray );
    int myInt = 2011;
    int anotherInt = 2012;
    NSLog( @"My int: %d and another int: %d", myInt, anotherInt );
    Writing static text out to your log isn't that useful, so NSLog() lets you output variables as well. To include a variable in your output, you need to know what type of variable it is because NSLog() has different format specifiers based on the variable type. For example, an array is an object so you'd use %@. The specifier for a plain int is %d. These format specifiers are "stand-ins" for the actual value of the variable listed at the end of the function call. Apple provides the full list of string format specifiers to be used in NSLog()so make sure to always use the right one.

    Wednesday, 13 November 2013

     About IOS Development     


    Why To Learn Objective C And IOS Development ?

    iOS Development is the world's most advanced mobile OS and it is contoniously growing in almost each and every country in world due to its unique design, graphics and quality. Together with the iOS SDK and Xcode IDE you can make it easy and more revoloutionary application .  iPhone currently holds a large portion of market shares in mobile platform . That's the main reason why you should learn to develop the iPhone application developmnet.

    Let's Start With Introduction :

    Objective C is the core programing language used for thr development of Apple iOS and OSX operating System. Along with objective C , you will develop iPhone app with Cocoa Touch. 

    Cocao Touch is a collection of  framework and API used for development of ios application . Some of Important framework of cocoa touch are as :


    Foundation Framework :

    Foundation framework is very basic framework and contain all wrapper classes and data structure classes. It include the root object class, classes representing basic data types such as string , array , dictionary and other collection classes for storing objects.

    We don't need to import this framework into our project as it is added by default. We can directly access its clasess by creating thier object and acessing thier methods. Such as :

    To Store Value in a Dicttionary in Objective C we can do as :

    # We create object of NSDictionary class and allocate it.
      NSDictionary *mydictionary=[[NSDictionary alloc]init];

    # We have inserted value in NSDictionary with some key.
    [mydictionary setObject:@"value" forKey:@"one"];

    Dictionary store data  in key valur pair , so we have store value with some unique key so that we can retrive it later on using that key.

    UIKit Framework :

    UIKit Framework consist of all basic UI classes that is needed to create UserInterface of our Application. It Provides classes needed to create and manage an application's user interface for ios.
    Whatever we see on screen such as Window , view , button , TextView are all contained in thie Framework.

    Game Kit Framework :

    Game Kit Frameowrk is used for creating games in ios platform. It contain all the classes and method that you can use to create your own games.

    iAd Framework : 

    iAd Framework is just for developer to earn revenue from thier application by allowing Apple to display advertisements on thier application.

    Map Kit Framework:

    MapKit Framework is used to integerate map directly into ios application . We can add annotaion , adding overlay , show used location and perform reverse- geocoding lookups to determine placemark information for a given map coordinates.

       
                 Basic tool that we used for creating ios Applocation is : XCode 


     XCode : 

    It is a tool that is used to create ios application . It is very user friendly and have code sense feature that help developer is writting correct code. Xcode check for gramatical and syntax error and gives warning and error .










    1. What is Class  ? 

    Class is a collection of  variable and methods . It binds them together into a single unit and thus implement concept of encapsulation. The Class define all the common properties of different object s that it contain .

    For Example :  There might be a class shape that contains objects which are circle , rectangle and triangles ( These objects might have property like colour , height , width , Area ).

    2. Object 

    Objects can be any real world entity having some physical characterstics and property .

    In the above Example : Shape is a class and circle , rectangle , traiangle are its objects and have thier own charcterstics such as thier color , size etc .

    3. OOP Concept  ( Object Oriented Programing ) 

    OOP stands for Object Oriented Programming language . In Generals in OOP we consider every real world entity as  objects and these objects were used to interact with each other to do certain well defined task.

    Object-oriented problem solving approach is very similar to the way a human solves daily problems. It consists of identifying objects and how to use these objects in the correct sequence to solve the problem. In other words, object-oriented problem solving can consist of designing objects whose behavior solves a specific problem. A message to an object causes it to perform its operations and solve its part of the problem.

    The object-oriented problem solving approach, in general, can be devided into four steps.

    They are:

     (1) Identify the problem.
    (2) Identify the objects needed for the solution.
    (3) Identify messages to be sent to the objects.
    (4) Create a sequence of messages to the objects that solve the problem.

    Basic OOPs Feature are :

    # Polymorphism
    # Encapsulation
    # Abstraction
    # Inheritance

    Polymorphism : It simply means many forms . It is a state in which an object can be treated as different type for different purpose. A single object with many forms.

    Simple example of polymorphism is :

    A Person is an object and It can behave differently with different people. Such as person can be someone Friend , For some other it can be brother , father and son to some other . so Object " Person " can have different property and behaviour under different circumstances.

    so this different role of single person can be termed as polymorphism.


    Encapsulation : It is wraping up of data and function into a single unit . Class is an exapmple of encapsulation.

    A class group all method and fucntion and support Encapsulation.

    Abstraction :  Abstraction is act of representing essential features without including background details.

    In Abstraction we hide the complexity of a task and show only necessary information to user so as to carry out that task . Its general example can be a Capsule

    In Capsule we hide all compext medicine and patient can take it easily .


    Inheritance :  It means to inherit features from one class to other . It is same as a child inherit some qualities from his parent.  By Inhertance we can get some code reusability . The class which is inherited is called base class and Class that inherit property from base class is called derived class.