Popular Posts

Better approach to manage IBOutlets,IBActions in Objective-C

| December 26, 2014 | 0 Comments

Managing IBOutlets and IBactions, Better and Clean approach

Author: Asif Noor (asef.noor@gmail.com)
Follow me on Twitter: Click to view
Get in touch with me on Linkedin: Click to view profile

You can download source Code
Tools : XCode 6.1

Before class extensions, we used to have all our IBOutlets in .h file. Problem with this approach was that Our .h file should only exposed those items that should be accessible outside our class. Keeping outlets and IBActions in .h file is not good approach. We should make only those parts of the class public, which are mandatory for us.

Then Apple introduced class extensions and we used to keep our IBOutlets in .m file, in anonymous categories. For example, If we have a viewcontroller named as ViewController then in .m file, we have this kind of section (Class extension)

@interface ViewController ()

//Outlets goes here

However, when there are too many outlets, then it will look like following

@interface ViewController ()

//Outlets goes here
@property (weak, nonatomic) IBOutlet UILabel *firstNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *lastNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *emailLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UITextField *firstNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *lastNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *emailTextField;
@property (weak, nonatomic) IBOutlet UITextField *addressTextField;

Problems with above approach
1. If there are too many outlets and IBactions, then my .m file will not look clean and there will be a mess.
2. If I have to do unit test in future, I can not access any of these outlets and action to write unit test. For example, if I want to write unit test to verify that iboutlet is connected to nib or storyboard, I can’t access them. [You might be thinking that I don’t write unit testing but it might the case in future or someone else will be writing unit tests for your code]

So to solve this problem and keep .m file clean, here are the steps.

1. If you have view controller with name “ViewController” and you have connected all your outlets but they are in .m file. Take them out in class extension.
2. Create a new class with h file only (remove m file) and create class extension with name ViewController+Private.h like following and import your ViewController.h in this class extension

//import foundation #import , please uncomment this, I have did this because my wordpress has not language support for Obj-c.
#import "ViewController.h"

@interface ViewController ()


3. Copy all your outlets and IBactions in this ViewController+Private.h. Now your ViewController+Private.h will look like this

//import foundation #import 
#import "ViewController.h"

@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *firstNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *lastNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *emailLabel;
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;
@property (weak, nonatomic) IBOutlet UITextField *firstNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *lastNameTextField;
@property (weak, nonatomic) IBOutlet UITextField *emailTextField;
@property (weak, nonatomic) IBOutlet UITextField *addressTextField;


4. Import this class extension ViewController+Private.h in your view controller m file (remember don’t import in h file).

Unit Testing part

Now if you want write unit test to check if you can access these outlets to verify, if they are connected to storyboard or not, you can write unit test

- (void)setUp {
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    viewController = [mainStoryboard instantiateViewControllerWithIdentifier:@"ViewController"];
//If you will not write following line, you will always get your outlets nil. So wait for this method to execute and then write unit test
    [viewController performSelectorOnMainThread:@selector(loadView) withObject:nil waitUntilDone:YES];

Unit test 

- (void)testIfFirstNameLabelConnectedWithStoryboard
    XCTAssertNotNil(viewController.firstNameLabel,"FirstName label should be connected to storyboard");  

This test should pass.

I have kept my code with both approaches on Github. You can download source Code

I hope it helps. Your comments, thoughts are welcomed.


Interview Questions for Senior iOS developers

| November 6, 2014 | 10 Comments
interview Questions for experienced iOS developers

Advance level interview Questions for iOS developers

Author: Asif Noor
Follow me on Twitter: Click to view
Get in touch with me on Linkedin: Click to view profile

I am writing this post regarding interview questions for experienced developers based on my experience in different companies. Also, I have been part of interview panel for assessing senior iOS developers. So, I have compiled set of interview questions which you should go through before showing up for interview. I hope it will give you confidence when you walk in for interview.
1. What steps you followed to convert iOS 6 compatible app to make it work for iOS 7?
2. Any quick way to convert iOS 6 app to iOS 7.
3. What are deltas in iOS?
4. What is difference between ARC and Garbage collector?
5. When you plan to start a project, will you prefer to use ARC or manually memory management?
6. With ARC, is it guaranteed that there will be no leaks?
7. What are disadvantages of ARC?
8. What are __bridge, __bridge_transfer, __bridge_retained, __unsafe_unretained:.
9. What are threads in Objective-C. What are thread types like UI thread and background thread? How you create a new thread ?
10. If you want to update UIWebView, will you perform this operation in main thread or background thread?
11. Can you perform main thread or UI thread operation in background thread?
12. If you want to download 10 MB file quickly from remote server, how you will tackle this issue?
13. Write custom setter for assign,retain,copy .
14. Difference between error and exception?
15. How you handle exceptions in objective-C applications?
16. Have you used blocks? What are their advantages?
17. Advantages of using storyboard? Can we use multiple storyboards in one application?
18. What design patterns that you used in Objective-C?
19. What are protocols in Objective-C. How delegation works?
20. Differentiate between KVO, Notifications, Delegate? Describe in which scenario you will prefer which technique?
21. What are push notifications? For example you have 100 users in app and you want to send notification to 20 users, how you will do it. Describe flow in terms of push notifications?
22. Is Core Data multi threaded? How will you handle multi threading in Core Data?
23. We have already application on Appstore and we want to add one entity to our core data and we also don’t want to crash existing users’ applications and integrate this also. How you will solve this problem?
24. If you want to design an app which takes data from webservices ,parse data and dump it into core data? What technique you will use to design such app?
25. You have audio or video file to upload to remote server through webservice. Give a solution to upload file quickly and without blocking other flows of applications?
26. How you gather analytics of applications?
27. View Controller life cycle method execution sequence?
28. Any changes in view controller life cycle methods in iOS 6 or iOS 7?
29. What problem you face when you run iOS 6 app on iOS 7 ?
30. How you design architecture for RESTful services based app?
31. There are multiple libraries for handling Web requests like (ASIHTTP, AFNetworking, REST Kit). Which one you have used and your preference?
32. If You say you have worked with REST Kit they will ask questions regarding RestKit for example describe flow of sending request, receiving response, mapping.
33. If you have web request with 50 different urls, how you design a solution for this in RestKit?

Please comment, rate or opinion? Let me know at asef.noor@gmail.com

Author: Asif Noor
Linkedin: http://linkd.in/10uulev

AFNetworking 2.0 POST request working example code snippet

| July 22, 2014 | 0 Comments

I was trying to send json in POST request using AFNetworking but it started behaving strange. It gave me 400 bad request error. After struggling alot I am able to run it. Please find working example below.


+ (void)login:(BOUser *)user responseBlock:(APIRequestResponseBlock)responseBlock {

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.requestSerializer = [AFJSONRequestSerializer serializer];

[manager.requestSerializer setValue:@"parse-application-id-removed" forHTTPHeaderField:@"X-Parse-Application-Id"];
[manager.requestSerializer setValue:@"parse-rest-api-key-removed" forHTTPHeaderField:@"X-Parse-REST-API-Key"];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
manager.securityPolicy.allowInvalidCertificates = YES;

NSString *URLString = [NSString stringWithFormat:@"%@login", BASE_URL_STRING];
NSDictionary *params = @{@"email": user.username,
@"password": user.password};

[manager POST:URLString parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
responseBlock(nil, FALSE, error);


I hope it will save someone’s time.

Author: asif.noor@techipost.com

Open Source Multi Values Selector Dropdown in iOS

| April 26, 2013 | 0 Comments

Most of the time, we need multiple values selector in iOS for example selecting multiple days of the week, selecting multiple contacts, selecting multiple countries from dropdown. If there is one country selected in dropdown, then it will show selected country. If there are multiple countries selected then it will show “Multiple Countries

Continue Reading

Responsive Business Portfolio: Folio

| November 7, 2012 | 0 Comments

Folio is a responsive html  business portfolio template.The template is exclusively  designed/developed  for techipost.com by Sarfraz Shaukat. Its intuitive text/image slider gives you a good showcase to project your Business Portfolio, Projects,Products etc. Its simple and clean design makes it more attractive and eye catching for users.

Continue Reading

How to become an iOS developer

| October 17, 2012 | 4 Comments

Developer: asif.noor@techipost.com

Motivation behind learning iOS development or becoming iOS developer

Well ! to be honest, I started iOS application development in mid of 2010 because everyone was talking about iOS and being an iOS developer you can earn more than developing for other platforms. Mobile development is dominating the market.Moving from developing applications for PC to mobile was exciting transition. Flows of application on iOS was different. Because of less memory available on phone, developers also need to do memory managements which was new to me at start when shifting from .Net development to iOS development. Tuning applications for performance is always a key goal in iOS. Do you also plan to start iOS development? then why not !

Continue Reading

One pager WordPress theme

| October 11, 2012 | 27 Comments

I recently developed this one pager business portfolio wordpress theme for Egrappler . Here is the Standardized version of this theme without using any external Option Tree framework. This version is perfect for those user who are getting issues with the  Option Tree version.

Continue Reading

Brownie-Free WordPress Theme

| October 8, 2012 | 0 Comments

Brownie is a  clean , beautiful and responsive Premium WordPress theme developed by Umair Ashraf . The template of this theme is designed by  Sarfraz Shaukat  Brownie template .  You can visit his site Egrappler.com for his other valuable and excellent designs and resource.

Continue Reading

Free Responsive Portfolio WordPress Theme :Creative

| October 1, 2012 | 0 Comments


IAmCreative is another simple, clean and responsive HTML5 portfolio WordPress theme developed by Umair Ashraf. It helps you to effectively project your work and it is perfect for any designer, photographer, illustrator, creative person or agency. It focuses on displaying a high quality portfolio, large typo presented in a really elegant way.

Continue Reading

MVC (Compound design pattern) in Objective-C

| September 24, 2012 | 7 Comments

Continue Reading