1.FunctionHelper.swift
class FunctionHelper { // 產生亂碼 len-需要亂碼長度 func randomString(len:Int) -> String { let charSet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" var c = Array(charSet) var s:String = "" for n in (1...len) { s.append(c[Int(arc4random()) % c.count]) } return s } }2.ViewController.swift
class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let funHelper = FunctionHelper() var number = funHelper.randomString(8) //取8位 println("產生得亂碼:\(number)") } }參考來源:
https://gist.github.com/szhernovoy/276e69eb90a0de84dd90
沒有留言 :
張貼留言