Tuesday, 30 June 2015

Data Types In Swift

Data Types In Swift

As i described in my last tutorial how to setup environment for windows as well as mac users.
If you have not studied click here:Environment Setup in Swift

Learn Objective C from Here:Click Here

What are the data types?

I describe about data types while studying objective c.
Data Types in Objective C: click here


Data Types describe the nature of data stored in memory addresses.
Developers has provided some memory to run application.
If they stored data according to their types then memory is proper ally maintained.
You have Integer Value which is maintained at 8bit to 32bit according to their types short and long integer. If you use string data type for integer value storage that is not the good way.

Generally in Swift support all data types.

Integer
Float
Double Float
Bool 
Character
String



How to Write Variables in Swift?

Swift is very fast language and safe language. Its compiler is very smart. You do not need to write  data types with swift like javascript. Swift compiler automatically inferred it for you.
If you declare variable in swift you need to write only

var x=90

If you declare in objective c  you need to write the 

int x=90;

Swift compiler automatically convert the type to integer.

Same case for String and any other type;

var print="Hello World"


For objective c you need to write Pointer like this:

NSString *print=@"Hello World";

Even you do not need to write semicolon in writing at end of statements.Also do not need to write @ sign each time writing Strings. As i told you swift compiler is such a smarter compiler.

For float

var a=9.78


In case of objective c

Double Float a=9.78;

You can also specify the data types with swift if you have free time. But if compiler anything do for you why to write It.

Like below statements is also legal in swift

var q:int16=49

In general, Swift is loosely Typed language.


How to print statements at console in Swift?

You need to write only println("Some statements")

Hello World Example in swift:

var name="suraj"
println("Your name is: \(name)")


In Objective c

NSString *name=@"suraj";
NSLog(@"The name is:%@",name);


Which one is more easy and readable.
Obiously Swift has easy syntax.

You think how compiler  behave when first you initialised with integer and then string.


Like var q=90

q="Suraj'

It generates error. It only takes data types of first initialisation.

So q will be only Integer.

So it is one of the safe language.Its compiler generates error and work Safer.

You can change initialisation while inferring types to data type.
With keyword typeAliases

typeAliases Name=String

Var p:Name="Suraj"

println(p)

Swift is very fast language you can see output side by side.
For learning and testing purposes apple provide the Playground features to run apps just like below:







Create Table View in IOS With Objective C : Click here

I hope you like my tutorials. If you have any query can mail me here and comment here.


My Next Tutorial will be Methods,Classes,Objects.

Monday, 29 June 2015

Environment Setup in Swift

Environment Setup in Swift

Have you read last tutorial of Swift or not?
Click here:Learn Swift

For learn Objective C Click here:Learn Objective C

As you learn How best is swift. Now its time to learn setup environment in Mac,window.

Learn environment setup for objective c from here:Click here For window: 

For window you can also run Swift  Online in browser. But do not think you can execute cocoa control. For executing User Interface you need mac.
But still who have craze about learning swift, having do not have mac can compile online and learn.

The link is here:

http://swiftstub.com

A very good online compiler to learn online swift.


For mac:

You need Xcode 6 or lator for running Swift Program. 

And mac could be Mavericks 10.9.5 or lator.

Learn IOS application development with objective c from here :IBOutlets and IBAction

I hope you like this simple tutorial and Have any query can mail me or comment here.

My next tutorial will be Data Types in Swift.




Swift overview

Swift Language Overview

Swift language is powerful language announced by apple last year for IOS,OS X and Watch OS.First version of apple announced as Swift 1.0.

At WWDC 2015 apple Declared Swift version 2.0 which is open source. Open Source means all the Frameworks from which it is made will be public to all.By declaring Open Source of Swift apple wants more companies can work on it for making different application Whether it is for macintosh or IOS.

Swift language is made on the best of Objective C.
Where Objective C is made from Strict Superset of C. 
If you have not learned Objective C you can learn from here: Click here

It is not mendatory to learn objective c before going to swift.But if you learn, you will know more how the cocoa control bounds.

Swift is very fast language as compared to others. It is such fast language you can see output while writing programs evens games of higher graphics.

Swift is safer language. you can use side by side Swift with Objective C.
You can make new apps with swift and Extend existing apps with side by side along Objective C.

Why Swift choose over Objective C?

Objective C is derived from NextStep with smalltalk messaging feautres included to C.
In objective c You need to write Pointers and NextStep classes like NSIntegers,NSString etc.
Passing of messages through pointer in complex TableView causing its performance to low.

Features of Swift Language

Swift is such a  smarter language you do not need to write data types with variables its Compiler automatically resolve it.Also you do not need to write semicolon at end It means Memory addresses are also resolved automatically by compiler.
Few other features of Swift are like generics ,blocks in objective c having replaced by closures as like in javascript.

Swift language has modern approach to syntax.
You can return  multiple values with single statments.


How to write swift Code for practise like Console in Objective C?


Apple introduce the fastest features of Playground by which you can see the output side by side even for high graphics games.

I will describe you in  next tutorial how to set up environment for swift.

I hope you like my tutorial.If you have any query can mail me or comment here.
You can learn IOS application development side by side with objective c from here:Click here

My next tutorial will be Environment Setup in Swift.

Saturday, 27 June 2015

Handling Row Selection In Table View(didSelectRowAtIndexPath,WillSelectRowAtIndexPath,DidDeselectRowAtIndexPath,WillDeSelectRowAtIndexPath)

Handling Row Selection In Table View(didSelectRowAtIndexPath,WillSelectRowAtIndexPath,DidDeselectRowAtIndexPath,WillDeSelectRowAtIndexPath)


Learn Objective C From Here:Click Here

 Learn IOS tableView from start:Click here

Learn Swift From Here:Click Here

Have you studied my last tutorial of setting customise tableview cell in storyboard? not Click Here.


Sorry the tutorial for objective c and swift is transferred to This link Please Click Here.

My Next Tutorial will be Accessary View and Attractive Table View.

Customize table view cell using storyboards

Customize Table View Cell Own with Objective C


Before going to my this tutorials read how to create Table View in IOS with objective c:Click here

Learn objective c from here:Click here

Learn Swift from here:Click here

As you have read in my last tutorials of creating Table View with Objective c by using default template. That is very easy to create having Already connected label,image view,Detail label.

But that is used in some cases where you have very less time to write. In cases like simple display of data.

You can not customise Cell of that table view.According to that template Image View comes first so you can not change.

But with the introduction of prototyping of cell in stroyboard it is now easy to customise the cell.
You can create your table view according to need.
Whereever place image view,button,label or else.

Before the introduction to prototyping of cell in storyboard , you need to add xib files cell implementation and load in project as UItableViewstyle. Now it is easy with storyboards.


Final Output will be:

It is looking bad but currently think of Custom cell setting i will also write tutorial on setting separate background setting images.





Lets go with Customize the Table View Cell Implementation.


First create simple view controller project as like below:






Now go to storyboard and make design like following:

Drag table View .





Change prototyping of cell to 1 in Right Identity Inspector.




Drag Image view and label towards the table view.Xcode automatically change inside the cell view.
For simplicity i have also Drag Navigation Bar and shows about Student Details.But currently i have not applied Auto Layout in this Tutorials.I will write tutorials also about it.






Add class file inside project.Name it as SampleStudent.


In SampleStudent.h write property for each UI Control.

@property(nonatomic,weak) UIImageView *studentimage;
@property(nonatomic,weak) UILabel *studentlabel;
@property(nonatomic,weak)UIImageView *studentimage2;


And make sure that class must be inherited from UITableViewCell.


In SampleStudent.m

@synthesize studentimage=_studentimage;
@synthesize studentlabel=_studentlabel;
@synthesize studentimage2=_studentimage2;



You think i have not write IBOutlet for connecting Properties.
 Hows the Controls binds with property?


Just put in mind that IBOutlets can not work for Repeating attributes.Our 1 Prototypes cell is repeating. So each time when IBOutlet Make request to UI Control.It is time consuming process.Also Xcode generates Error for it.Xcode is very smarter.

But How we connect?

Just put tag number in identity inspector of property inside table view cell.

like that:


Now In View Controller.h

Add Protocols UITableViewDelegate,UITableViewDataSource 

@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>


{
    NSArray *studentdata;
}
-(void)loadStudentData;


In View Controller.m

load data before view is loaded from viewDidLoad method.

 [self loadStudentData];


Add data loading method with data from array.

-(void)loadStudentData
{
    studentdata =[NSArray arrayWithObjects:@"abc",@"def",@"ghi",@"jkl",@"mno",@"pqr",@"stu",@"vwx",@"uza",@"iop",@"uio",@"asd",@"cvb",@"mnb",@"qwe",@"ert",@"poi",
                  nil];
}

If you do not know about these below method: Click here

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [studentdata count];
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *studentidentifier=@"StudentId";
    SampleStudent *studentcell=(SampleStudent *)[tableView dequeueReusableCellWithIdentifier:studentidentifier];
    studentcell.studentlabel=(UILabel *)[studentcell viewWithTag:100];
    studentcell.studentlabel.text=[studentdata objectAtIndex:indexPath.row];
    studentcell.studentimage=(UIImageView *)[studentcell viewWithTag:200];
    studentcell.studentimage.image=[UIImage imageNamed:@"images.jpeg"];
    studentcell.studentimage2=(UIImageView *)[studentcell viewWithTag:300];
    studentcell.studentimage2.image=[UIImage imageNamed:@"flower.jpg"];
    return studentcell;
}

Above code is very easy.Just make the reference with dequeuereusablecellwithidentifier through SampleStudent class.

Now that object has contain all property of sample class. But property do not bind with UI Control. You can bind with UI Control Through tag number having NSInteger value. 
And cell is then Returning.

I have also write delegate method to make height of cell.If you do not know about delegate object click here:Life Cycle Of IOS.




-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 78;
}


If you want i will publish my next tutorial in Customize table View cell with Xib then comment below. Otherwise I will Publish my next tutorial on Handling row selection.

And Final Output will be Resulted as:






Some of you think its ugly i will make tutorial also on setting background images. Do not worry about just think of setting custom cell yet.

Source Code Available here:Download Here


I hope you like my tutorials.If you have any query comment here or mail me.




Create TableView in IOS

Create TableView in IOS

Have you read last tutorial of View Controller or not ? Click Here

Learn Objective C from here:Click here
Learn Swift from here:click here

TableView is the main common UI elements in IOS.Whenever you make app for iphone You most probably familiar with TableView.

In General If you want to display data for your office work Tables are used due to their flexible and easy implementation.
Table is collection of rows and columns arranged in the form of cell.

Similarly in IOS if you want to display data UITableView class is used who manages Table View User Interface Control.

There are two protocol delegates and datasource who manages the behaviour to data for TableView Control respectivally.

If you have not study Protocols click here:Protocols in Objective C


DataSource:It is used to control data inside the Table View.

Delegate:It is used to control behaviour of table.

What is delegate object?
For checking App life cycle:Click here.


You can add header and footer in table view according to need.

My system runs on Xcode 6.1.1 for running following tutorials. You can use according to your needs.


There could be many types of TableView
From according to static and dynamic,grouped or ungrouped,section or rows.

Static Table View: Static Table View Display those data which is grouped or divide in sections and having data not changed their value at run time. 

Dynamic TableView: Dynamic Table View display data in the form of ungrouped or rows and columns with containing data at run time.

First i describe tutorials on Dynamic Table View.
After that i will write Static Table View.

In Dynamic Table View i will describe following contents:

create table view.
Handling row selection in Table View.
Delete row from table view.
dynamic self sizing Cell.
create swipeable table view with more display options.
create pulling and then refreshing cells of table view.
play videos from tableviews and many more.


TableView tamplate can be according to your choice manually or default template.

First we use default template.
Default Template can be
UITableStyleDefault,UITableStyleSubTitle,UITableStyleValue1,UITableStyleValue2..


I will describe all these default table template time to time when there used. Read my tutorials carefully
In this tutorial i used UITableStyleDefault,UITableStyleSubTitle.


Lets start with creating Table View Application.

Final output will be shown below:








There are three methods used behind the loading of data source.
1.)Sections of table view: it is used to describing how many sections included in Table View. It is Optional method describe in Protocols.
You can check here how to create optional method in protocols: click here
This method is used when creating static table view.

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

above method is used by passing UITableViewControl as arguments.


2.)Rows in Table View: How many rows you want to create in table view.Rows can be depend on you length of data you need not to remember only passing indexpath as agrument. see in method written below:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 

It has two arguements one is table view your UI control and other is section.

It returns the integer value.

3.)Cell for rows at index path: Above method only count number of rows but how to make cells it is the work of CellforRowsAtIndexPath

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath


It returns the cell for table view.
This method has two arguements IndexPath and tableView.
IndexPath manages Indexes for data Rows.


First create View Controller Project as shown in figure.




Now Drag and drop TableView in Storyboard.


Now run your app it look like this in IOS simulator.







Now think that when data comes, Data source methods are not called. From where these methods comes as i write above UITableViewDataSource Protocol is used.

Now in ViewController.h 
write below code


@interface ViewController : UIViewController<UITableViewDataSource>
{
 NSArray *studentdata;   
}
-(void)loadStudentData;


Where array is used to store data of student. 
A method is used to load data in array.
Learn array from here:click here

In ViewController.m

-(void)loadStudentData
{
  studentdata =[NSArray arrayWithObjects:@"abc",@"def",@"ghi",@"jkl",@"mno",@"pqr",@"stu",@"vwx",@"uza", nil];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [studentdata count];
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *studentidentifier=@"studentid";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:studentidentifier];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:studentidentifier];
    }
    cell.textLabel.text=[studentdata objectAtIndex:indexPath.row];
    return cell;
}

Above code is easy to remember just except dequeueReusableCellWithIdentifier.
for Performance issues in IOS when you drag the table view instead of creating new cell checking done in dequeue for those cell containing cell area are behind the screen then those area will be occupied by NewContent and cell is rewrite with that value.

Where to call loadStudentData in ViewDidload method.
It is the method responsible for loaded data before view is printed.

Now Data Source is not connected just hold down ctrl  key on table view and drag towards view controller. You see datasource and delegate click on data source.

You can see the connections on connections inspector.As shown below:







Now the output will be:


For displaying image view Place this code after cell.textlabel.text line.

cell.imageview.image=[uiimage image named:@"images.jpeg"];


As you have seen it shows same image you can pass array as like above for taxtlabel.

Also it looks odd you need to add auto layout.I will write auto layout tutorial lator for now take my below auto settled project.

Final output will be:



For UITableStyleSubTitle:


change code after cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStylesubtitle reuseIdentifier:studentidentifier];

and add code after cell.imageview


cell.DetailTextLabel.text=@"Student Names";

Output will be:





Now you have seen width between the cells are very less and image is too small you can change or customise own cell in table view.

Source Code Available here:download here

I hope you like my this tutorial. If you have any query  can mail me or comment here.

My next tutorial will be: Customise Own Cell for Table View.

Thursday, 25 June 2015

View Controller and Application Life Cycle in IOS

View Controller and Application Life Cycle in IOS

If you have not study my last tutorials click here: Learn Objective c

For Learn Swift Click here:Learn Swift

Application Life Cycle in IOS:

Whenever your application run in IOS your code and System Framework plays role behind that.
System Framework includes all the required User Interface Cocoa Control(button,tableview etc) That demand by your code while running application.
Also that above dependency between code and system work depends upon MVC model.
If you have some programming background you already familiar with it. I will describe lator about it.

As you have seen my last tutorial of Objective C i have used console widely with main class. But in IOS you have not seen. Actually it does not appear but Xcode creates it automatically When you click on Any template of view controller,DetailviewController or takes the assumptions with every basic project.


In general C programming you need to write Main function even in java ,In C++ each of your class executed by creating object inside of main function.

you can see main function when some error occured while building application in Xcode.
There is UIApplicationMain function in Xcode who manages MVC.


Model View Controller:

The UIApplicationMain function manages when to load view and where data comes in model and when to control application in controller from delegates.

Model: Model describes the model about application.General A model describes the data used in Real world object from application is derived.

It stores the data needed for run apps. Like If you have created apps for University or academic work of student record The Database used for app stored in model.

Learn Last tutorial of IBoutlets and IBAction click here: IBoutlets and IBAction in IOS 

Controller: Controller who control the code behind the scenes whether it is delegate or some other.
Controller include Application Delegate which generally linked with model time to time.

Like if you want to handle row selection in table view of Student record apps then delegate object request time to time with Model for data manipulation.

There is also UIApplication object in Controller includes all the bundle required to run apps.

View: View include all the front end required elements like Cocoa Control like button,TableView ,Sliders etc.
There is UIWindow object who worked behind it.

How to appears on IOS simulator or iPhone Device ?

It is the work of UIWindow object to manage or run the application.

Now Take a quick look at how application run in IOS?

When user click on touch of iPhone, the touch event is fired and the request goes to Operating System which is IOS. Now IOS decide at which port application can run. 
After that a queue of events are generated which means separates object of different control according to their needs like motion,accelerometer,camera.

Now There is main loop who manages all the main thread activities requested to UIApplication object one by one from event queue.

Here UIApplication object processes that request and provides resources if needed like camera to camera,sound like activities etc.


Application can change their states according to condition.

These states are: Foreground,background,suspended

You have seen various methods in app delegate .m like willEnterBackgroundState etc. then what to print.


Foreground is state normal when your application is running.
I am not going into the detail of Application state change. You can study from internet.

The application can be terminated by IOS if any interrupt occurs like low memory issue and multitasking,running apps in background or suspended without informing.

You can study my last tutorial of concurrency: Concurrency In IOS

I hope you like my tutorial. If you have any query can mail me and comment here.


My next tutorial will be Table View Apps.




Tuesday, 23 June 2015

Overview of IOS , IBOutlets and IBactions

Overview of IOS , IBOutlets and IBactions

Before going further read my last tutorial:Learn Objective C

You already know about that Iphone run on operating system which is IOS.
IOS is mobile operating system manages both hardware from Battery,memory to camera and software from Tableview to Animations.
IOS also run IPod and Ipad to manage functions.IOS was released in 2007 but Third party application developement with IOS Standard development kit is available to developer in 2008.

Why IOS is Popular?

IOS is popular due to its customar satisfaction features,advantages to performance and many others.Any customar has first preference to buy IPhone but that is different thing due to its cost some can buy.Where features come you can manage cost.
One other thing is that Any update Announced by Apple available to all IOS devices.Now,more then 80% devices are run on latest update to apple IOS 8 and Will be IOS 9.
Also User Interface is also good.It can not be beat by any other mobile operating system.

Why IOS is Prefer?

IOS is very stable towards the application run.Whenever your application run IOS provide the good performance and Resources(memory,cpu etc.). 
IOS provide the speed to run application.Your application can not wait for deallocation of objects while stopping the application.
IOS do not share your privacy with other third party.
IOS provide proper security.A user can share their bank related information on Apple Pay and do transactions.
If i counting the features Of IOS whole time will be passed. IOS has many uncountable features.

Quick look History of IOS


I started with IOS 4 runs on Iphone 3G phones.
You can check the history of IOS on internet. Now i describe only latest IOS 9 some features:

1.)Power Mode: With IOS 9 you can get 1 hour extra to their daily battery life.Apple make smarter to IOS 9 by adding the capabilty to alert by where your application requires less battery by adding low battery mode.


2.)MultiTasking: With the help of spilt view now you can run two application at same time without any interrupting that is one of biggest features.

Many other features like more supported in apple pay,smarter siri,spotlight,music and news app and much more.


Language used to develop IOS apps

Objective C and Swift. 

Objective C can be learned from here:Click here

swift has latest update announce by appple is swift 2.0 and it will be open source.
Due to demand of people i will also write swift tutorial side by side who having ios application development sharp background can learn.


IBoutlet and IBAction


Final output will be:





IBoutlet: IB means Iterface builder.The easiest way in IOS to add Infront of property data type IBoutlet so that property shows in Storyboard or xib file.

There are two ways to write IBOutlet by manually and tell Xcode.

By manually : 

Just in interface write like below:


IBoulet NSString *studentname;




Tell Xcode: When you are expert in making IBoutlet then just by drag and drop with ctrl button. show in below screenshoot.







First click on assitant editor at top right corner.In ios you can do coding with user interface side by side.

Just click on control and press ctrl button with along side mouse towards viewcontroller.h interface.

Do it same for label.


For button do the same but select action. 



Now the code will be 

In viewcontroller.h

property (strong, nonatomic) IBOutlet UITextField *textfield;
@property (strong, nonatomic) IBOutlet UILabel *label;


IBAction: It is same like to do IBoutlet but has action method with touchupinside like method.

- (IBAction)click:(id)sender;



In view Controller.m


@synthesize textfield=_textfield;
@synthesize label=_label;
- (IBAction)click:(id)sender {
    self.label.text=self.textfield.text;
}

You can change background from there :







Source Code available here: Download here

I hope you like my this tutorial if you have and query can mail me and comment here and tutorial on swift will also published soon.


My next tutorial will be: View controller and application life cycle.