Wednesday, 4 April 2018

Swift Basics

var for variables
let for constants
example
var a = 2
var a :Int = 2


if condition
{
code

}


Switch statement
Switch valuetoconsider
{
case value1:
case value2,value3:
default:
}


Loops
for counter in lower...upper
{

}

for(index in 1...5)
{
print(index)

}
o/p 12345


while loop
while condition{
some code
}


repeat while loop
repeat{
code
}while condition

functions
func name()
{
code
}


func name() -> Datatype
{

return ;
}

arguments
func name(argumentLabel parametername:datatype)
{
}




How to create a object for Class


class name{
func test()
{

}

}
create a class object
let objectOne = name()




Inheritance

class subclass : name{

 override func test()
 {


 }
}

Optionals
--------
var title:string?
It means it could be nil or could contain a string
var author:person?
where person is a class
if let actualTitle : post.title{
print("hellso string is not empty");
print(post.tilte! +"zzzz") //This is force wrapping
}

How to resize a view
Click and hold command and then click =

comand + enter to remove the split screen

How to print name and age
print("\(name) , \(age)")

power operators in swift
pow(height , 2) which is height * height
Convert double to string
String(value)
for number in arrauOfNumbers
for number in 1..<10 where number %2==0
{
print(number)
}
we get all even numbers till 9




Hold on command and click on method to read doc of method
Hold on option key and hover on method to read doc of method
By default all the components have tag 0
label.text = "\(intvalue)"
How to use lib project written in objctectve c in our swift project
copy .h , .m ,.bundle in to supporting files
then in bridging file write import .h
Then directly use where ever needed
option +ctrl+i to reindent code (select all and do)
creating enums
enum CarType
{
case Sedan
case Coupe
case Hatchback
}
var typeOfCar : CarType = .Coupe
convinience init(color : String)
{
self.init()
colorProp = color
}
designated initializers needs all the properties
inheritance
class selfDrivingCar : Car
{
}
Cocoapods.org

No comments:

Post a Comment

Pass a HashMap from Angular Client to Spring boot API

This example is for the case where fileData is very huge and in json format   let map = new Map<string, string>()      map.set(this.ge...