micromax canvas hd lollipop update
I rewrite this tutorial from forum.xda-developers.com : The users of Micromax A116 Canvas Hd can now update their handsets to Android 5.0 Lo...
The Blog You Will Love To Revisit.





Book and set its subclass to NSObject. As we saw earlier, by making the new class a subclass of NSObject, the new class will inherit the attributes and behavior of NSObject. This means that the new Book class gets some functionality for free.
Book class and exposes the class interface as we saw earlier. A class interface contains the properties and methods of the class, and it also specifies the class's superclass. Book.m is the implementation file of the class and defines its behavior by implementing the methods declared in class header file.Book class has access to the classes and protocols declared in the Foundation framework.
1
| #import <Foundation/Foundation.h> |
@interface and ends with @end, which are both compiler directives, that is, commands or instructions for the compiler. The @interface directive is followed by the name of the class, a colon, and the class's superclass—if applicable. As we saw earlier, the parent class or superclass is the class from which it inherits attributes and behavior.
1
2
| @interface Book : NSObject@end |
NSObject is the root class of the majority of Objective-C classes. The first two letters,NS, refer to its origins, NeXTSTEP, as we saw earlier in this article. By inheriting fromNSObject, classes behave like Objective-C classes and inherit a basic interface to the runtime system.Book class, let's take a quick peak at Book.m, the class's implementation file. Instead of importing the Foundation framework, the implementation file imports the header file of the Book class. Why is this necessary? The implementation file needs to know what properties and methods are declared in the header file before it can implement the behavior (i.e. methods) of the class. The import statement is followed by the implementation of the class, indicated by@implementation and @end.Book class isn't very useful in its current implementation. Head over to the header file and add three properties year, title, and author, and add a method namedbookInfo.@property keyword and can be declared anywhere in the class's @interface block. The @property keyword is followed by the type and the name of the property. Don't forget the asterisk in front of the title and authorproperties, because a Cocoa object is always referenced as a pointer.
01
02
03
04
05
06
07
08
09
10
11
| #import <Foundation/Foundation.h>@interface Book : NSObject@property int year;@property NSString *title;@property NSString *author;- (NSString *)bookInfo;@end |
NSString, and the name of the method. The method declaration ends with a semicolon.NSString is and why it needs to be referenced as a pointer. The NSString class is a member of the Foundation framework. It declares the interface for an object that manages an immutable string. In the previous article, we saw that a string in C can be represented by an array of characters and that is exactly what the NSString class does, it manages an array of characters under the hood. The advantage of using NSString is that it make working with strings much easier.bookInfobookInfo method in the class's header file, it is time to implement it in the class's implementation file. Open Book.m and add the following code snippet somewhere in the @implementation block. Before we break the implementation of bookInfo down, we first need to talk about object messaging.
1
2
3
4
| - (NSString *)bookInfo { NSString *bookInfo = [NSString stringWithFormat:@"%@ was written by %@ and published in %i", self.title, self.author, self.year]; return bookInfo;} |
@ sign.
1
2
3
| NSString *string = @"This is a string of characters.";int length = [string length];NSLog(@"The length of the string is %i.\n" length); |
length to the string instance. In other words, we call the method length on the string instance and the method returns an integer. The integer is assigned to the length variable of type int. In the last line, we log the length variable to the console by calling the NSLog function as we saw in the previous article.
1
| [object message]; |
NSString class, for example, has another method named substringFromIndex:. The colon at the end of the name indicates that this method accepts an argument. Calling this method on a string looks like this:
1
| NSString *substring = [string substringFromIndex:5]; |
1
| NSString *anotherString = [string stringByPaddingToLength:5 withString:@"some string" startingAtIndex:2]; |
bookInfo. The method implementation starts by repeating the method declaration. The trailing semicolon is replaced with a pair of curly braces, which wrap around the implementation of the method. We first declare a new string, bookInfo, and assign to it a new string, created with the attributes of our book instance (title, author, and year). At the end of thebookInfo method, we return the new string, bookInfo, because that is what the method expects, a string as the return type.stringWithFormat: is a class method and not an instance method. We know this because the method is called on the class itself, NSString, not on an instance of the class. Class methods are common in object oriented programming languages. Second, the format specifier for an object is represented by the @ symbol (preceded by the percent sign). Both titleand author are objects—strings to be precise. Third, the self keyword always references the class instance. In this case, self refers to the Book instance to which the method bookInfo belongs.self.title. This is nothing more than a shortcut for [self title]. The latter means that we use the getter method to ask the instance for the instance variable named title. The same is true for setting an instance variable. Take a look at the following code snippet. As you can see, the use of self.title is nothing more than syntactic sugar.
1
2
3
4
| // This assignment ...self.title = @"The Hobbit";// ... is equivalent to ...[self setTitle:@"The Hobbit"]; |
id, nil, and NULLidBook class, I want to talk about a few keywords that confuse people from time to time. Whenever you want to store an object without explicitly defining the type of that object, you use the id data type, which is also the default type for return and argument declarations for Objective-C methods.id data type goes much further, though. The id data type is a key component of Objective-C's dynamic typing and dynamic binding. It is important to understand that the id data type does not hold any information about the object itself other than that it's an object.isa variable) and this is critical. Why is that? One of the strengths of Objective-C is its dynamic typing, which means that type checking is performed at runtime instead of compile time.id data type does not tell the compiler anything about the class the object belongs to, the object itself needs to provide this information to the compiler.id data type.nil and NULLnil is defined as a null object, that is, an id with a value of 0. Under the hood, there is no difference between nil, Nil, and NULL, and it is possible to send messages to each of them without an exception being thrown.nil for objects, Nil for classes, and NULL otherwise. Being able to send messages to nil, Nil, and NULL has benefits but it also has downsides. For more information about nil, Nil, and NULL, take a look at thisquestion on Stack Overflow.Book class. Instead of using angle brackets, we use double quotes to import the header file of theBook class. Double quotes are used for local files, whereas angle brackets are used for global includes, using the project's include path.
1
2
| #import <Foundation/Foundation.h>#import "Book.h" |
NSLog call, add the following snippet to create an instance of the Book class.
1
2
3
4
| Book *book1 = [[Book alloc] init];book1.title = @"The Hobbit";book1.author = @"JRR Tolkien";book1.year = 1937; |
Book and initialize it. This is a good example to illustrate nested method calls. The first method called on the Book class is alloc. The details of this call are not important. The gist is that memory is allocated for the new object and the object is created.init method is called on the new object that was created by the alloc method. The init method initializes the new object, setting up the object and making it ready for use. The init method returns the instance and, in our example, assigns it to the book1 variable.
1
2
3
4
5
6
| Book *book2 = [[Book alloc] init];[book2 setTitle:@"The Fellowship of the Ring"];[book2 setAuthor:@"JRR Tolkien"];[book2 setYear:1954];NSArray *books = [[NSArray alloc] initWithObjects:book1, book2, nil]; |
NSArray, another class of the Foundation framework. The NSArray class is an array that can store an ordered list of objects. Just like we did with the book instances, we allocate memory and initialize the new array.init, however, we call initWithObjects:. initWithObjects: is a designated initializer, which means that it's an init method with some extra bells and whistles to facilitate object initialization.initWithObjects: accepts any number of objects that you wish to store in the array. The list of objects should always end with nil.if/else statement to check if the array contains any objects. By sending the array a message of count, it will return the number of objects it contains.for loop to iterate over the objects in the array. During each iteration, we ask the array for the object at index i and send the object—an instance of the Book class—a message of bookInfo. As we saw earlier,bookInfo returns an instance of NSString, which we log to the console.
1
2
3
4
5
6
| if ([books count] > 0) { for (int i = 0; i < [books count]; i++) { Book *aBook = [books objectAtIndex:i]; NSLog(@"%@", [aBook bookInfo]); }} |
Get our latest updates direct in your inbox.Just enter your wail address below....
Your privacy and email address are safe with us!