Friday 17 May 2013

Multi-threading

Grand Central Dispatch (GCD) is a C API.  The basic idea is that you have queues of operations, which are specified using blocks. The blocks in the queue run in another thread except main thread.

There are two types of queues.  Serial Queues and Concurrent Queues
In serial queues blocks are executed in order. (one by one)

When do we use Multi-threading:

Accessing the network
Big calculation, hugs loines of code


Creating and releasing queues:
dispatch_queue_t dishpatch_queue_create(const char *label, NULL); // Null means serial queue

Putting blocks in the queue:
typedef void (^dispatch_block_t)(void);
void dispatch_async(dispatch_queue_t queue, dispatch_block_t block); //it puts the block in the queue then returns to main thread immediately

void dispatch_sync(dispatch_queue_t queue, dispatch_block_t block);  // puts the block in the queue and waits until the block finally gets to run to compelition and get backs to current thread

Getting the current or main queue
dispatch_queue_t dispatch_get_current_queue();
dispatch_queue_t dispatch_get_main_queue();


written by: infinitywebseo 

Sunday 12 May 2013

How to add tweet button to iOS app?

iOS includes a framework that you can use to add twitter to your iOS application. Follow the link below to see the full documentation:


What can I do with the framework?

  1. Single Sign-On
  2. Distribution
  3. Instant Personalization


written by: infinitywebseo 

Wednesday 1 May 2013

UITabBarController (Multiple MVCs)


Its a very common controller, It allows user to navigate between different views selecting different tabs.

The tabBarController's view is any number of viewController, simply control drag from the tabBarController to each of the viewControllers that represent the tabs.

By control dragging you are setting up following property in UITabBarController:

@property (nonatomic, strong) NSArray *viewControllers;


Tabs have icon and title which easily can be set on xcode. You can also add a badge on tab icons by the following line of code:

- (void) somethingHappendToCauseUsToNeedShowBadgeValue
{
   self.tabBarItem.badgeValue = @"Something";

}


written by: infinitywebseo 

View Controller Lifecycle

View Controllers are the controllers of your MVC. They have a Lifecycle. (They are created, do some task and they die.)

There are certain methods in view controller which notify you of what's going on. View controller can be created by alloc init by 99% of time MVCs are instantiated out of a story board.

Put set up codes for your view in viewDidLoad:

-(void) viewDidLoad{

 [super viewDidLoad];


}

But remember geometry is not set in viewDidLoad. You can do it in viewWillAppear:


-(void)viewWillAppear: (BOOL)animated;


Your view will only load once, but it may appear and disappear few times.
If your things you are displaying is changing while your app is off screen, you should add the code to viewWillAppear.


didRecievedMemoryWarning

In low memory situation, didRecievedMemoryWarning is called. It is very rare to happen, but if it happens you can set the pointer of the object that causes it to nil and reload your data. Keep in mind to use caching in your program where it makes sense.

awakeFromNib 

This message is sent to every single object that comes out of the story board. It happens before the MVC is loaded and before all the outlets are set.
written by: infinitywebseo