Wednesday, 19 November 2014

How to start developing apps for Apple Watch using WatchKit framework iOS 8.2 and Xcode 6.2

It was a wonderful day yesterday (Nov-18th, 2014) for iOS developers, finally Apple  released Xcode 6.2 Beta with WatchKit framework to start developing apps for Apple Watches. It started a new chapter in iOS developers  life to play with Watchkit framework and make relationship with Apple watches.

I am not sure about What the NDA restrictions are, but I am just having thing on the basis of publicly information the  Apple WatchKit
But its not so limited information, its too much to learn with Beta release.

Software and tools required to start developing apps for Apple Watch using WatchKit framework are.

1- Xcode 6.2 or latter
2- Mac OSx 10.10
3- iOS 8.2 or latter

Lets first go through some basic but interesting things about Apple Watch Architecture and Watchkit Layout.

* iPhone Device:  It works like a "Model" and "Controller" of the  app. iPhone Device contains all the code of the application and responds to all the events like app launch, button taps etc.

* Apple Watch: It works like a "View" of the  app. All the Static images and Storyboard are contains in it. It is an user interface of the app. It process user inputs but did not run any code.

Communication between Apple Watch and  iPhone get automatically. Wow interesting! WatchKit SDK handles this communication via Bluetooth behind the scenes.
One issue for developers is that Animations are not supported in WatcKit. It means Developers will try for third party API (if any) or They will use set of .GIF images to achieve animations.

Two new words are seen to represent Watchkit, Glances and Notifications.

1-Glances: Provides a Quick overview of the contents within app

2-Notifications: Let us receive notifications on our watch.

Sunday, 9 November 2014

How to Scan Barcode using iOS native framework

Prior to iOS 7, It was a big problem for iOS developer to add a native QR code scanner. So some third party code library were used to achieve barcode scanning. But iOS 7 brings a bunch of new features. The AVFoundation framework is  one of them where some new API/classes are added, as a result AVFoundation provided the ability to discover and read bar codes in real time.

In this tutorial we are going to scan a QR Code, its known as Quick Response Code. QR Code is 2D barcode. Its design can have horizontal and vertical lines. So you can scan 1D (vertical lines) and 2D (Vertical and Horizontal lines).

What can be store in QR code ?
QR Code can contain information of like web URL, Phone number, SMS text and other Simple text.

Lets start how to Implement QR Code Scanning with Native iOS framework.

1- Open Xcode and create a new project  (I pick single view application  ), name it "BarcodeScanner".

2-Open Storyboard and Create a UIbutton to Start/Stop scanning, a UILabel to print scanning status/scanned information, And a UIView inside that a camera will be open to scan QR code.

QR Code scan and read using native iOS framework

3- Open ViewController.h and  define some properties

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@interface ViewController : UIViewController<AVCaptureMetadataOutputObjectsDelegate>

@property (nonatomic, strong) AVCaptureSession *captureSession;
@property (nonatomic, strong) AVCaptureVideoPreviewLayer *videoPreviewLayer;
@property(nonatomic,assign) BOOL IsScanning;

@property(weak, nonatomic)IBOutlet UILabel *lblScanStatus_info;
@property(weak, nonatomic)IBOutlet UIButton *btnStartStop;
@property(weak, nonatomic)IBOutlet UIView *vwCameraPreview;


4- Connect IBOutlet from starboard, Connect "StartStop_Scan" method to Button.
Open ViewController.m
Define two private method one for Start Scan and Second one for Stop scan

@interface ViewController ()


@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _IsScanning = NO; //

#pragma mark IBAction

    NSLog(@"Inside startstopmethod");
    //If start button  pressed
        [self StartScanning];
    ////If Stop button  pressed
        [self StopScanning];
    //set the flag opposit to earlier ;
    _IsScanning = !_IsScanning;

Don't forget to check camera support in device, Simulator don't support camera so we need a device to run this tutorial.

    AVCaptureDevice *captureDevice = nil;
    AVCaptureDeviceInput *input = nil;
    //Check for device camera existance
    NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
    if ( [videoDevices count] > 0 ) // This device has one or more cameras
        NSError *error;
        captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        // Get an instance of the AVCaptureDeviceInput class
        input = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error];
        if (!input) {
            // If any error occurs, simply log the description
            NSLog(@"error desc:%@", [error localizedDescription]);
            // init the captureSession .
            _captureSession = [[AVCaptureSession alloc] init];
            // Set  input device at the capture session.
            [_captureSession addInput:input];
            // Initialization of a AVCaptureMetadataOutput object and set it to output sessioncapture
            AVCaptureMetadataOutput *captureMetadataOutput = [[AVCaptureMetadataOutput alloc] init];
            [_captureSession addOutput:captureMetadataOutput];
            // make a serial dispatch queue.
            dispatch_queue_t dispatchQueue;
            dispatchQueue = dispatch_queue_create("QRCodeScanQueue", NULL);
            [captureMetadataOutput setMetadataObjectsDelegate:self queue:dispatchQueue];
            [captureMetadataOutput setMetadataObjectTypes:[NSArray arrayWithObject:AVMetadataObjectTypeQRCode]];
            //  video preview layer and adding at subview _vwCameraPreview
            _videoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:_captureSession];
            [_videoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
            [_videoPreviewLayer setFrame:_vwCameraPreview.layer.bounds];
            [_vwCameraPreview.layer addSublayer:_videoPreviewLayer];
            // Start video capturing.
            [_captureSession startRunning];
            [_btnStartStop setTitle:@"Stop Scan" forState:UIControlStateNormal];
            [_lblScanStatus_info setText:@"Scanning for QR Code:-----"];

        NSLog(@"Camera is not supported here");
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Current device does not supporting camera " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];

    // Stop video capture
    [_captureSession stopRunning];
    _captureSession = nil;
    // Remove video preview layer.
    [_videoPreviewLayer removeFromSuperlayer];
    [_btnStartStop setTitle:@"Start Scan" forState:UIControlStateNormal];
    [_lblScanStatus_info setText:@"QR Code Scan is not started"];

#pragma mark Implememntaion of AVCaptureMetadataOutputObjectsDelegate method

-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection{
    if (metadataObjects != nil && [metadataObjects count] > 0) {
        // Get the metadata object.
        AVMetadataMachineReadableCodeObject *metadataObj = [metadataObjects objectAtIndex:0];
        //Check QR type meta data object
        if ([[metadataObj type] isEqualToString:AVMetadataObjectTypeQRCode]) {
            // If the found metadata is equal to the QR code metadata then update the label status info text,
            // Proecees of main thread done.
            [_lblScanStatus_info performSelectorOnMainThread:@selector(setText:) withObject:[metadataObj stringValue] waitUntilDone:NO];
            //and stop reading
            [self performSelectorOnMainThread:@selector(StopScanning) withObject:nil waitUntilDone:NO];
            [_btnStartStop performSelectorOnMainThread:@selector(setTitle:) withObject:@"Start Scan" waitUntilDone:NO];
            _IsScanning = NO;

To test QR code scan you may find some images from Google and or use the image shown above for sample QR code.

Hope you will enjoyed this code. If you have any concern please share your comments.

Sunday, 2 November 2014

How to fix CLLocationManager location updates issue in iOS 8

It was  time consuming issue for me to  fix CLLocationManager location update issue in iOS 8.x, I was too much worried, why my code is not working in iOS 8 neither asking for user permission nor the location update delegate. 

CLLocationManager fails to work with  [self.locationManager startUpdatingLocation]. CLLocationManager not working for updating location updates. Its neither giving any error nor warning so it is more complex to figure out why this is not working.
Even Application did not ask for location related permission. So you might get irritate, don’t worry here the solution.

What are extra updates for iOS 8:
There are two more things need to be add to working with location.
1- Add one or both below keys to (app-name)info .plist file:

* NSLocationAlwaysUsageDescription
* NSLocationWhenInUseUsageDescription

Above keys take a string as description of why your app need location services. You may enter a string like “To Find out your location”
Note: iOS will not ask an user for permission to use their location until you have given a reason as why you are requesting it.

2- Request authorization for related location method, i.e WhenInUSe or Always. Use one of below method calls.

[self.locationManager requestWhenInUseAuthorization];
[self.locationManager requestAlwaysAuthorization];

WhenInUseAuthorization:  It allows the application to get location updates when the application is in foreground state and not in other state.
requestAlwaysAuthorization: It allows the application to get location updates in both when the application  is in the foreground and or in the background.
Below is the sample code for help.

Before using this code make sure you already added NSLocationWhenInUseUsageDescription in the  (app-name)info .plist  file.

- (void)viewDidLoad
    [super viewDidLoad];
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    // Check for iOS 8 Vs earlier version like iOS7.Otherwise code will
   // crash on ios 7
    if ([self.locationManager respondsToSelector:@selector
                       (requestWhenInUseAuthorization)]) {
        [self.locationManager requestWhenInUseAuthorization];
    [self.locationManager startUpdatingLocation];

// CLLocationManager Delegate Methods
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:
(NSArray *)locations
    NSLog(@"location info object=%@", [locations lastObject]);
I hope You will enjoyed this post and if you any suggestion or feedback
 your most welcome

Thursday, 9 October 2014

Making ad hoc build from command line without signing to developer account in Xcode 6 and iOS 8

It was the first problem I face during the use of xcode 6 first time, how can i share .ipa to my clients for demo purpose? I was unable to share an .ipa without signing Apple developer account. Xcode 6 was asking to sign with Developer account to export an .ipa file. Although I had the developer account details but it was the challenge how to make a adhoc build  without signing developer account.
After lots of Googling and consulting with other friends, I found  an alternate solution to achieve ad-hoc  build without signing developer account, solution is  command line/Terminal, you can create a adhoc build using command line tool and or a terminal on mac system.

Let me share the simplest way to create adhoc build using command line tool.

I note down 3 things to create quickest Xcode 6 build. So get ready for these 3 things before opening Terminal.

1- Project path: it will be required in terminal command as a parameter.

2- scheme name: it will be required in terminal command as a parameter.

3- Provisioning Profile name: it will be required in terminal command as a parameter.

Finding scheme name: Default scheme name is the project name but once verify. scheme name displays next to RUN icon in Xcode that is used to execute the app.

Finding Provisioning Profile name: This parameter value will be exact same as it display in Xcode; Provisioning Profile list under Code Signing Identity in build settings section of Xcode 6.

There are three steps two create build from command line tool

1- Clean project
2- Make Archive
3- Export to .ipa file

 Lets start with first. To clean project we will execute below command in Terminal  and or command line tool of mac system.
xcodebuild clean -project <projectname.xcodeproj> -configuration Release -alltargets

here  <projectname.xcodeproj> will be replace with the project path with .xcodeproj extension 

For example on my system's terminal
xcodebuild clean -project /Users/ajsharma/Documents/iPad/testApp/testApp.xcodeproj -configuration Release -alltargets

Terminal will show you some process and updates and show you success message regarding project clean.
Lets go for next step to Make an archive using below command

xcodebuild archive -project <projectname.xcodeproj> -scheme <schemename> -archivePath <projectname.xcarchive>

<projectname.xcodeproj> will be replace with the project path with .xcodeproj extension 
<schemename> will be replace with the shceme name of the project as I discussed above.

<projectname.xcarchive> will be replace with the project path with .xcarchive extension

For example on my system's terminal
xcodebuild archive -project  /Users/ajsharma/Documents/iPad/testApp/testApp.xcodeproj -scheme testApp -archivePath /Users/ajsharma/Documents/iPad/testApp/testApp.xcarchive

I used same path for as project Path for archivePath you may change it. So an archive file will be create at same path as project path.

Sorry I forgot to mention important command for those who have configured their projects under a WorkSpace or using pods in their projects.
For those people there would be slightly change in  command to make an archive. But I was not using workspace.

xcodebuild -workspace <projectname.xcworkspace> -scheme <schemename> archive -archivePath <projectname.xcarchive

<projectname.xcworkspace > will be replace with the project path with .xcworkspace extension.
<schemename> will be replace with the shceme name of the project as I discussed above.

<projectname.xcarchive> will be replace with the project path with .xcarchive extension

Lets go for  final step to Export to .ipa  using below command

xcodebuild -exportArchive -archivePath <projectname.xcarchive> -exportPath <projectname> -exportFormat ipa -exportProvisioningProfile “Provisioning Profile Name”

<projectname.xcarchive> will be replace with the project path with .xcarchive extension
<projectname>  will be replace with the project path with out .xcarchive or .xcodeproj extension
“Provisioning Profile Name”  will be replace with the Provisioning Profile Name  as I discussed above.

For example on my system's terminal
xcodebuild -exportArchive -archivePath /Users/ajsharma/Documents/iPad/testApp/testApp.xcarchive -exportPath /Users/ajsharma/Documents/iPad/testApp/testApp -exportFormat ipa -exportProvisioningProfile TestProvision

If everything works fine the final result screen would be some thing like below text as per my project path.

Moving exported product to '/Users/ajsharma/Documents/iPad/testApp/testApp.ipa'

You can get the .ipa file from the above path as per your project path at your system and share with your client.

If you have any other best way to create adhoc build without using developer account, please share your comments.

Wednesday, 8 October 2014

2 steps to use UITableViewCell separatorinset in ios 8 and setLayoutMargins in iOS 8

During porting from iOS 7.x objective-C based code in to iOS 8.x objective-C, I noticed that UITableviewCell separator disturbed from left and right side. Separator line got margin from left and right. It was fixed in iOS 7.x code using separator "inset" to 0. but it become default 15 in iOS 8 storyboard. even setting it  to zero (0) it didn't worked.

Actually in iOS 8 layoutMargins a new property is introduced. So problem comes in mind;  How to use layoutMargins on the cells and tableview in iOS 8?
it is missing in earlier version. so we need to put a check also to its availability.

Two fix it in iOS 8.x, need to use below 2 steps

1- For Cell

-(void)tableView:(UITableView *)tableView willDisplayCell:
(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];

    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];

2- For Tableview

    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) 
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];

    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) 
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];

Both steps need to be follow to achieve Separatorinset in iOS 8

This is the best way to use UITableViewCell separatorinset in ios 8 and  setLayoutMargins in iOS 8.

If you have some better way please share your valuable ideas in comment section.

Monday, 6 October 2014

How to change UISegmentedControl text font and color

UISegmentedControl is mainly used to toggle between two screen or functionality from a common screen. but some times it requires to change the font size of the UISegmentedControl text. Interface builder is not providing the option to change the text font size.

Let me share the way how to change UISegmentedControl text font size and text color.

Create a new viewcontroller in your project or may create a new project if you dont want to modify your existing project for safety point of view.

I am creating UIsegmented control using code but if you using IBOutlet you can go with that also.

in .h file

@interface ViewController : UIViewController

@property (strong, nonatomic)  UISegmentedControl *segment1;

@property (strong, nonatomic)  UISegmentedControl *segment2;

in .m file

 - (void)viewDidLoad
    [super viewDidLoad];
     NSMutableArray *segtitleArr=[[NSMutableArray alloc]initWithObjects:@"First1",@"Second2", nil];
    _segment1 = [[UISegmentedControl alloc]initWithItems:segtitleArr];
    _segment1.frame = CGRectMake(30, 50, 252, 29);
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                [UIFont fontWithName:@"Helvetica" size:17], NSFontAttributeName,
                                [UIColor redColor], NSForegroundColorAttributeName, nil];

    [_segment setTitleTextAttributes:attributes forState:UIControlStateNormal];
    [self.view addSubview:_segment];

//creating second segment.
    NSMutableArray *segtitleArr2=[[NSMutableArray alloc]initWithObjects:@"Third3",@"Fourth"4, nil];
    _segment2 = [[UISegmentedControl alloc]initWithItems:segtitleArr2];
    _segment2.frame = CGRectMake(30, 152, 252, 29);
    _segment2.tintColor = [UIColor colorWithRed: 8/255.0 green:83/255.0 blue:131/255.0 alpha:1.0];
    NSDictionary *attributes2 = [NSDictionary dictionaryWithObjectsAndKeys:
                                [UIFont fontWithName:@"Helvetica" size:10], NSFontAttributeName,
                                [UIColor orangeColor], NSForegroundColorAttributeName, nil];

    [_segment2 setTitleTextAttributes:attributes2 forState:UIControlStateNormal];
    [self.view addSubview:_segment2];

Best way to change UISegmentedControl text colr and  size

Above code will show you two segment control in different text size and font color and selected segmented color change using tint color property.
In both UISegmented control one thing is common that is a NSDictionary having objects of Font/Text and color these you can change as per your requirement.

If you find another best way to change UISegmentedControl  text  size and color, Please share using your comments below.



Friday, 3 October 2014

DataCalculation: How to use User Defined Runtime Attributes in Xcod...

DataCalculation: How to use User Defined Runtime Attributes in Xcod...: What is the mean by “User Defined Runtime Attributes” ? “User Defined Runtime Attributes” are featured from Xcode 4 and iOS 5,  great fea...

How to use User Defined Runtime Attributes in Xcode Interface Builder

What is the mean by “User Defined Runtime Attributes” ?

“User Defined Runtime Attributes” are featured from Xcode 4 and iOS 5,  great feature supported in interface builder. But bad thing is that most of the intermediate developers are not aware about it.

Where can I found in Interface builder ?
take a look under Identity Inspector tab.

User Defined Runtime Atrributes screen in interface builder

Key Path- Its like properties of controls and or setter methods.
Value- Assigned values to those properties and or setter methods.
What about the 'Type' ?

Below are the supported Attributes types 

User Defined Runtime Atrributes Supported types


Lets come to the point.

How can we  use these in our application.
It is not possible to set a View's CornerRadius or borderWidth using interface builder's Attributes Inspector. To achieve this we unnecessarily creates a IBOutlet and use CALayer for this.


    _myBGview.layer.borderWidth = 3;
    _myBGviewlayer.cornerRadius = 15;

Lets do the same using Interface builder

Configure User Defined Runtime attributes in interface builder

Wow its so simple Just fill out the objects property and select type and set the value

One problem is here that I required to set the color of the border but CALayer's color is CGColorRef type not UIColor type

So we can use a trick of Objective-C's Category. Just implement a setter method.

@implementation CALayer (Enhancement)

     self.borderColor = mycolor.CGColor;

Configure User Defined Runtime attributes of unsupported types in interface builder

 Its all about Using User Defined Runtime Attributes from my side. If  you have any other best way to configure User Defined Runtime Attributes in Interface builder
 Please share using comments section.
It would be much appreciated.

Sunday, 28 September 2014

Learning Swift with iOS 8 tutorials part 1

What is Swift ?

Swift is Apple's latest programming language for iOS and OS X apps that builds on the best of C and Objective-C, without the constraints of C compatibility. Swift adopts safe programming patterns and adds modern features to make programming easier, and flexible.

The Basics:
Swift Providing below data types in his way of syntax. 

Int             : Used for integer type values.
Double      : Used for floating points values.
Float         : Used for floating points values.
Bool          : Used for Boolean values.
String        : Used for Text data values
Array         : Used for collection.
Dictionary  : Used for collection.

Constants and Variables
In Swift, Constants and Variables need to be declared first before using them.

let  x = 10
var y = 0

You can declare multiple constants and variables in a single line using coma as a separator.
let x = 10, y=11,z=0
var  a = 1, b=10, c=3

Thursday, 25 September 2014

Best iOS interview questions on swift programming language

I started this post to all  iOS developers/beginners to prepare your self for Swift Interview questions. As its time to prepare with Swift interview questions. Swift is going to replace objective-c so we all have to prepare for best iOS interview questions on swift.

What is Swift ?

Swift is Apple's latest programming language for iOS and OS X apps that builds on the best of C and Objective-C, without the constraints of C compatibility. Swift adopts safe programming patterns and adds modern features to make programming easier, and flexible. 

Swift will replace Objective-C as the primary language in which iPhone and Macintosh applications are written.

How we declare variables in Swift ?

Constants and variables must be declared before they are used. Declare constants with the 'let' keyword and variables with the 'var' keyword.

What is difference between 'let' and 'var' declaration ?

constants are expressed with the ‘let’ keyword. So once assigned value can not be change, but assigned values using 'var' keyword can be change.

In terms of objective -c or compare with  objective -c, 'var' is  Mutable and  'let' is NonMutable.

let kMyConstant = 40
let  kMyConstant: Int = 40

var myString = "This is my string."

What is Initialization ?

Initialization is the process of preparing an instance of a class, structure, or enumeration for use. This process involves setting an initial value for each stored property on that instance and performing any other setup or initialization that is required before the new instance is ready for use.
You implement this initialization process by defining initializers, which are like special methods that can be called to create a new instance of a particular type. Unlike Objective-C initializers, Swift initializers do not return a value. Their primary role is to ensure that new instances of a type are correctly initialized before they are used for the first time. 

Initializers are called to create a new instance of a particular type. In its simplest form, an initializer is like an instance method with no parameters, written using the init keyword:
init() {
// perform some initialization here

In Swift How to connect UI under Swift Environment ?

UI connectivity has no change, its similar to objective-c. Xib/Storyboard under Interface builder.

Sunday, 21 September 2014

Best way to modular code using multiple Storyboards in iOS app development

In my earlier post  Best way to Avoid merge conflicts with Storyboards I have made clear why to use multiple storyboards in your iOS app.

Xcode creates only single storyboard with name “Main.storyboard” at the time of creating new project. Lets see below image

Xcode Default Storyboard

Xcode is smart IDE tool its provides option to create another storyboard. how? as simple as creating new file. Under File menu choose New and follow below image steps.

Easy way to use multiple storyboards in iOS app development

Next save it with proper name. Finally you can see two storyboards in the same app.  see below image for better idea.

Managing Multiple storyboards in Xcode objective-c

Next Problem is loading another storyboard in iOS application.  But you can not connect a scene and or segue from one storyboard to another storyboard. Don’t worry we have another solution for working with multiple storyboards in iOS app. We can load another storyboard using little bit coding on an IBAction method and or a selector.

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main” bundle:nil];
UIViewController* myStoryBoardInitialViewController = [storyboard instantiateInitialViewController];

[self.navigationController pushViewController:myStoryBoardInitialViewController animated:YES];

You can use another method to load a scene/ View-controller  using identifier. If you given a identifier to a scene.
Loading scene using identifier is very similar to old way where we were using XIB name to navigate from one View-controller to another View-controller.

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main” bundle:nil];
UIViewController* myStoryViewController = [storyboard instantiateViewControllerWithIdentifier:@“sceneIdentfier”];

[self.navigationController pushViewController: myStoryViewController animated:YES];

Using above code you can load UI from multiple storyboards.

If you have some other Best way to use multiple storyboards in iOS app development please share with me in comments section.

Thursday, 18 September 2014

Best way to Avoid merge conflicts with Storyboards

As of using storyboard in iOS app development, it is observed that working as a team on an Application, we face issue of  merge conflicts in storyboard changes. for example, if  same time two developers make changes in UI, it creates issue in merging code because of having single storyboard for all team members.

All though there are lots of compare-merge tools to solve merging issues. These tools are very useful for  merging other files like .h and .m files but these tools are not so useful to compare and merge storyboard changes.

So Creating multiple storyboards in the application is the best way to Avoid merge conflicts in case of working as a team. For big projects, recommends to use multiple storyboards in practice for more modular code.

 Xcode gives option to add multiple storyboards in application. It would be good if we create one storyboard for one module or related screens 
Like Login, Registration and Forgot Password related scenes/Screens can be create in one storyboard and User Profile, Settings can be in separate storyboard.

By doing this, we can work as team even without storyboard conflicts. And without wait for other member to finish his UI changes first and get updated code.

* Small project can have a single storyboard.
* For big projects it is recommended to create multiple storyboards in practice to more modular code.
* Multiple storyboards practice avoid merge conflicts when working as a team.

Saturday, 13 September 2014

How to Convert iPhone Storyboard in to iPad Storyboard

Some times it happens that, first we develop an iOS app for iPhone environment and latter it requires to develop same for the iPad environment in very short time of period. As a developer I face this issue. So I would like to share my experience to all of you. Don’t worry, its very simple to change  iPhone Storyboard in to iPad Storyboard .
Let me share the steps to help you understand.

Would not be a good idea if I share some images in between of textual content?  Wow.. Its great to follow.


1- Open you iPhone application.
2-Select iPhone storyboard (mostly named as “Main.Storyboard”), Using mouse or laptop keypad right click over the storyboard and select option to open As- Source Code.
See below image to better understand.

Source code will open as a XML code for all of the UI. Here is everything written as code. whatever we create UI in Scene it contains the coding part for that.

3- Find in this XML file targetRuntime="iOS.CocoaTouch"
See below image for better understanding.

4- Simple change it to targetRuntime="iOS.CocoaTouch.iPad”.
 See below image for better understanding.

don’t worry I am not going to share more steps its done all about. Now you need to come back from this XML file in to Storyboard.
Write click over Storyboard in left side panel where all files listed and Select open As - Interface builder-iOS Storyboard.

See below Images for better understanding.

Now you will see that all of Scenes of Storyboard changed to iPad size. If this not happens don’t worry we have one more steps to change it manually.
Select your view controller object in storyboard and change it size to iPad-Full screen. See below image for better understanding.

Wow its great. Now enjoy with iPad Storyboard.