Thursday, July 10, 2014

Hello Word with Swift

7:13 AM Posted by MAC , No comments
Hello Word! with Swift programming language

Today we will gonna learn how to create first Hello Word! program with Swift. Hope you have already gone through our previous post. If not I suggest you to go though first post that will help you to get basic idea about Swift programming language.

To run any Swift program you will need following xCode 6 (beta), as we have discussed in previous post Apple have launched new concept called Playground. So no need to compile and no need to run code. It will show you real time output of code. Steps to create first Hello Word! Program with Swift
Step 1: Open xCode 6- Click on Get started with a playground



open xcode 6 and click get started with a playground
Step2 : Save your first Playground on hard disk HelloWord.playground



Step3: Now you will have first playground in front of you.


As of now you have followed steps 1, 2, 3 you will have your first swift program. Right now it will have default text called "Hello, playground".

You will see there is only variable declaration named str still you can see output there. It displays current values of that variable. From out previous post you can borrow some code any try play with here on this playground. Below is some example code which will help you to do some practice with your first HelloWord.playground
Second very basic program with swift
Here is blow some code where you will be learn
1) How to create class
2) How create variables in class
3) How to initialise class
4) How to create user define function in class
5) How to create object and initialise?
6) How to call class methods using object

1) How to create class ?
class Maths{

}

2) How create variables in class ?
let total: Double
let valOne:Doublelet valTwo:Double

3) How to initialise class ?
init(valOne:Double,valTwo:Double){
        self.valOne=valOne;
        self.valTwo=valTwo;
        total=valOne+valTwo;
}
4) How to create user define function in class ?
func printTotal(){
        println("Total \(total)")
}
5) How to create object and initialise ?
let objMaths = Maths(valOne: 22.25,valTwo: 30.45);

6) How to call class methods using object ?
objMaths.printTotal();

Posted by: Bhavin

0 comments:

Post a Comment