// // ViewController.swift // learn // // Created by myhaspl on 16/1/26. // Copyright (c) 2016年 myhaspl. All rights reserved. // import Cocoa class ViewController: NSViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override var representedObject: AnyObject? { didSet { // Update the view,if already loaded. } } @IBOutlet weak var hashresult: NSTextField! @IBOutlet weak var sourcestr: NSTextField! @IBAction func hashbutton(sender: AnyObject) { let sourcestring=sourcestr.stringValue var hashres:Int64=1 var str:String for charascii in sourcestring.utf8{ str="\(charascii)" hashres = str.toInt()! + 33 * hashres } hashresult.stringValue=String(hashres) } }
字符串HASH