Sunday, November 24, 2013

Messaging in Objective C

In Objective C we know that objects send messages. If you do not know about it you can refer to the one of the previous blogs Object Model of Objective C

Now the messages are not bound to the method implementation until runtime. So how does this binding happens at runtime? There is no magic here is the messaging function which does this at runtime "objc_msgSend". This function takes the receiver and the name of the method - this is the method selector name as argument,

Tuesday, October 29, 2013

ViewController LifeCycle

We had previously discussed ViewController in the topic Introduction to the ViewControllers in iOS and in that topic we had given an overview of the ViewController LifeCycle.

Today we are going to discuss only the ViewController LifeCycle and How we should use each of the methods provided in the lifecycle event.

What is LifeCycle?

A lifecycle is an event which has certain steps from the point of creation to deletion. So how do we know about the steps during this period? A Sequence of methods is called as they progress through the LifeCycle. 

Now we may need to perform a different kind of actions at different steps of the life cycle and thus we commonly override these methods and perform these actions.

Thursday, October 24, 2013

Introduction to Introspection in Objective C

This article is intended for understanding of the beginners. You will not see any advance stuff here. I will be giving some basic introduction to Introspection and what are the syntaxes to perform the Introspection.

We may have an array of objects of different kind of classes. But we might need to be sure of the type of object before sending a message to the object. So How do we do this? We use introspection.

Saturday, October 19, 2013

Introduction to NSAttributedString and NSMutableAttributedString Class

NSAttributedString

This is new in iOS 6. It is really powerful and really useful. Think of NSAttributedString as an NString where each character has dictionary of attributes. The attributes attached to the character can be its font, the color, is it underline etc etc. Thats how you can think of NSAttributedString as conceptually.

However its not like that It is very efficient and it handles the attributes very efficiently. You will know as we progress through the article.

Syntax

How to we get the attributes from the NSAttributed string. here is the syntax.

-(NSDictionary *)attributesAtIndex : (NSUInteger) index effectiveRange : (NSRangePointer) range;

Friday, October 18, 2013

Introduction to ViewController in iOS

We follow MVC Pattern for development of iOS Application. Visit MVC Overview article on wiki to have a brief introduction to the pattern. It has been consumed neatly to implement the iOS applications.

ViewController Life Cycle

Life Cycle define how an object is created an lay out the different kind of stages it pass through before it gets to the end of the life cycle, also on course of the life it send different kind of events which other objects can observe. So what are different methods are involved in the ViewController life cycle? here is the brief introduction to each of them...
  • initWithNibName:bundle - Default Initializer of the view controller.
  • LoadView - Loads the view from the storyboard or the nib file.
  • viewDidLoad - After Initialization and all the outlets are set.
  • viewWillAppear - Called just before the view appear on the screen,.
  • viewWillDisappear - Called before the view disappear from the screen.
  • viewDidAppear and viewDidDisappear - After the view appear and disappear from the screen

Types of controller Objects

In Cocoa there are two types of controller objects. 
  • Mediating Controllers
  • Coordinating Controllers
Each controller is associated with different type of classes and provide different type of Behaviors.

Mediating Controllers

It is an Object that inherit from NSController class. These are used in the Cocoa binding technology. Mediating Controllers mediate the flow of data between the view objects and the model objects. 

Mediating controllers are generally controllers which we drag from the Interface Builder Library. You can configure these to establish binding between the view objects and the properties of the controller object. The abstract class NSController and its concrete subclasses NSObjectController, NSArrayController etc. provide features like supporting commit and discarding the changes.

Coordinating Controllers

A Coordinating Controller is typically an NSWindowController or NSDocumentController objects or Instance of a custom subclass of NSObject. Its role is to coordinated the functionality of the overall application or a part of the application. A coordinating controller provide features like:
  • Respond to Delegation messages or observing notifications
  • Respond to action messages
  • Managing the life cycle of owned objects.
  • Establishing connections between objects.
Instance of Custom NSObject subclass can be entirely suitable as coordinating controller. These kind of controller objects combine both mediating and coordinating functions. For mediating behavior they use mechanisms such as outlets, delegation, and notifications of the movement of data between view and the model. 

Just an overview of the controllers in iOS.

Happy Coding!!!