IOS Mobile Application Development
Session 20 Swift IOS Code
---Generic
var variable:Int = 1
func change(num:inout Int)
{
num = 2
print(num)
}
change(num: &variable)
func exchange(a: inout Int, b: inout Int) {
let temp = a
a = b
b = temp
}
var numb1 = 100
var numb2 = 200
print("Before Swapping values are: \(numb1) and \(numb2)")
exchange(a: &numb1, b: &numb2)
print("After Swapping values are: \(numb1) and \(numb2)")
func exchange<T>(a: inout T, b: inout T)
{
let temp = a
a = b
b = temp
}
var num1 = "Fahad"
var num2 = "Hussain"
print("Before Swapping Int values are: \(num1) and \(num2)")
exchange(a: &numb1, b: &numb2)
print("After Swapping Int values are: \(num1) and \(num2)")
No comments:
Post a Comment
Fell free to write your query in comment. Your Comments will be fully encouraged.