How to get the Power of Integer in Swift

In Swift we can use pow(::) for making power of any number. For Example if we need 2 power 3 –

import Foundation 

let a = 2.0
let b = 3.0
let output = pow(a,b)// prints 8

Further you can also typeCaste to Int as     let output = Int(pow(a,b))// prints 8
Remember to add import Foundation for get rid of compile time error.

Leave a Comment

Your email address will not be published. Required fields are marked *