There are several questions on Stack Overflow discussing how to find the Greatest Common Divisor of two values. One good answer shows a neat recursive function
let a = 3
let b = 9
func gcd(a:Int, b:Int) -> Int {
if a == b {
return a
}
else {
if a > b {
return gcd(a:a-b,b:b)
}
else {
return gcd(a:a,b:b-a)
}
}
}
print(gcd(a:a, b:b))