1、NSMutableAttributedString to String
var attributedString = NSMutableAttributedString(string: "hello, world!")
var str = attributedString.string
2、swift中的交换元素
使用swift中的Tuple(多元组)
var a = 10
var b = 20
(a,b) = (b,a)
print(a,b)//a = 20,b = 10
3、判断字符串相等
var str = "hello, world!"
if str == "hello, world!" {
print("equal")
}
4、获取字符串长度
var str = "hello, world!"
print(str.characters.count)
5、transform
self.textField.transform = CGAffineTransform.init(translationX: 0, y: 100)
6、character to string
let greeting = "Guten Tag!"
let index = greeting.index(greeting.startIndex, offsetBy: 0)
var myStr:String = String(greeting[index])
7、获得键盘的高度
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
let contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height, right: 0)
// ...
}
网友评论