Showing posts with label iOS. Show all posts
Showing posts with label iOS. Show all posts

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!!!

Wednesday, October 16, 2013

What's New in XCode 5 Part 3

What's New in XCode 5 Part 3

This is part 3 of the Series What's New in XCode 5. In Part 2 we had discussed what's new in
  • Interface Design
  • Compiler and Language
  • Auto Vectorizer
  • Parsing the Comments
XCode 5 is so fast and stable as the transition from GC to ARC has be completed with XCode 5... :) It has been 2 years since ARC has come into picture and has been great thing happen. Apple has announced that GC is deprecated technology and those developers who are using GC in Mac should switch to ARC and they will notice the change. Besides this enhancement there are still other features which we need to discuss..

XCode Debugger

Similar to Compiler XCode supported two different Debuggers "LLDB" and "GDB". Now with XCode 5 only LLDB debugger is available and gdb is gone. New features of debugger are:

Monday, October 14, 2013

What's New in XCode 5 Part 2

What's New in XCode 5 Part 2

In Part 1 of this series we had discussed about:
  • Documentation
  • Performance
  • SourceControl
  • Automatic Configuration
in XCode 5. Today we will discuss about more in features of XCode 5.

Monday, October 7, 2013

What's New in XCode 5 Part 1

What's New in XCode 5 Part 1

As we all know that iOS 7 has been the major release of iOS and it has brought us developers so many cool features. iOS 7 What's a new link to know more about it.

iOS 7 release brings the release of iOS 7 SDK and XCode 5, iOS 7 SDK and Xcode 5 download is available. Once you download and Installed XCode 5 you must be wondering now what's new in this... Right? That's what we are going to discuss in this very Blog.. and of course as IDE XCode do a lot of things and you know being a programmer it won't be easy to explain all the things in place. :) So I will be writing series of blogs to cover the features and this is the Beginning.. :) 

So What's New in XCode 5? Here are features:

Sunday, October 6, 2013

TypeCasting objects in Objective C

Type Casting

Type Casting a process converting one type of object to another type of object. Every language a semantics of TypeCasting. Today we will discuss about type casting in Objective C.

E.g We have two class BaseClass and DerivedClass.



@interface BaseClass : NSObject
@property (nonatomic,strong) NSString *baseProperty;
-(void)baseMethod;
@end

Thursday, October 3, 2013

Memory Management in Objective C

In this topic, we will discuss Reference Counting and some other memory management topics related to Objective C.

Reference Counting


Reference Counting is a technique of storing a number of reference to an Object at any given state. As soon as the reference count goes to the Zero object is released from the memory. It is important from the development point of view of application where memory is critical and to maintain responsiveness. It is the most simple algorithm for memory management. 

Objective C provides two methods of Memory Management

  1. MRR - Manual Retain-Release: In this method, you explicitly keep track of the Objects you own. 
  2. ARC - Automatic Reference Counting uses the same algorithm of MRR, However, while using ARC Compiler insert appropriate statements in your code at compile time. 

Thursday, September 26, 2013

What's new in iOS 7?

iOS 7 Major release of iOS. It has come up with a lot of things for users and the developers. UI has been completely redesigned and also come with a new animation system for creating games. 

I will list what's new in iOS 7.

  • What's new in User Interface

    • UI Redesign - UI has been completely redesigning and throughout the system, the focus has been on the functionality and making sure that things are easier than before. Introduction of the Control Center, Navigation around the settings menus with the swipe, Updated Notification Center, Accessibility updates, and Siri has just become more helpful than before.  

Common Objective C coding errors

I am going to introduce the common coding errors made while programming in Objecive C language.

1. Declaring the const char * strings. Yes this the common coding error while programming, You almost never want to declare a const char * string, e.g. see the below line of code.



self.selectedLabel.text = [NSString stringWithFormat:@"Selected : %d", self.selectedCount];

Object Model of Objective C

Object Model of objective C is derived from SmallTalk. It has its basis in SmallTalk. Few things to know before understanding the Object Model.


What is Object?

Think of Object as a real world entity. What is a real world entity? It is something which have some data in its possession and perform different kind of functions. e.g. Think of a Tap as an object. It perform different kind of functions like start water flow, stop water flow, control the rate at which water should flow. Objects hold the data and the methods it perform.

Tuesday, September 24, 2013

IBAction and IBOutlet keywords




(IBAction)selectedCard:(UIButton *)sender {

IBAction is nothing but typedef void. Xcode puts this to keep track that this not a random method that returns void but an Action method that connects view to the controller.



@property (weak, nonatomic) IBOutlet UILabel *selecedLabel;

IBOutlet is typedef of void. Xcode puts this just to keep track that it not some random @property, but it is an Outlet i.e. connection to the view.


Monday, September 23, 2013

Application Delegate

Every iOS application must contain an application delegate object. Application Delegate class is responsible for handling all kind of events happen in the application. The root class is UIApplication. 

We do not subclass the UIApplication class to customize the handing of different kind of events, rather we provide an AppDelegate class that implements UIApplicationDelegate protocol. We provide this delegate class to the UIApplicaiton class which will sendd notifications to AppDelegate class for each of the application level event.


Wednesday, September 11, 2013

Difference between Weak and Strong keywords

Strong means you want to keep control over the lifetime of the object. If an object is marked as strong mean object remains in the heap until you point that object strongly. If you send the object to nil only than it will be collected by the Garbage collection.

Weak means you don't want to keep control over the lifetime of the object. A weak reference does not extend the lifetime of the object it points to, and automatically becomes nil when there are no strong references to the object. If no one is pointing the object strongly than the object will be collected by the heap.


you can find more details about ARC(Automatic Reference Counting) Click Here...




Tuesday, September 10, 2013

What is "id" in Objective C

id

'id' is a typedef in objective C. This means "Pointer to an Object". This Object can be any object of Objective C.


typedef struct objc_class *Class;
typedef struct objc_object {
    Class isa;
} *id;


typedef struct objc_selector    *SEL;    
typedef id          (*IMP)(id, SEL, ...); 

Monday, September 9, 2013

Pointers in Objective C

Pointer?
A pointer references a location in the memory. In simple words it keeps the address of the memory where actual data is stored. Obtaining the content of the pointer is called deferencing the pointer.
Pointers to data significantly improve performance for repetitive operations such as traversing strings, lookup
tables, control tables and tree structures. In particular, it is often much cheaper in time and space to copy and dereference pointers than it is to copy and access the data to which the pointers point. you can learn more about pointers here.

Sunday, September 8, 2013

Introduction to Objective C

Learning any kind of language starts with learning basics of the programming language. If one needs to understand than I would say he must understand the basics keywords of C language like printf, unsignedint, const char, malloc, alloc, etc. It would be of great help if one can go through few chapters of c language before going into objective C.

If you are programming in Java, .Net or any other High Level Language, than I would say you better tighten your seat belts because once you will see the objective c in active you are gonna be on a roller coaster ride. The syntax, semantics, object oriented approach etc are implemented in a sophisticated way.