swift练习一

//: Playground - noun: a place where people can play

import UIKit


var mystr:String = " she o h";
mystr.uppercaseString
mystr.lowercaseString
mystr.hasPrefix("s")
mystr.hasSuffix("e")
mystr.capitalizedString
mystr.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
mystr.stringByTrimmingCharactersInSet(NSCharacterSet(charactersInString: ""))
mystr.componentsSeparatedByString(" ")

var sep = ";"
sep.join(["1","2"])

mystr
mystr.rangeOfString("o")
mystr.rangeOfString("o", options: NSStringCompareOptions.BackwardsSearch)
var start:String.Index = mystr.startIndex
var end:String.Index = mystr.endIndex
let range = Range<String.Index>(start: start, end: end)


//
for index in 1..<5
{
    println(index)
}

var dict = ["red":(red:255,green:255,blue:255)]
var tuple = dict["red"]!

for (index,item) in enumerate(dict)
{
    println("\(index):\(item)")
}

for (key,value) in dict
{
    println("\(key):\(value)")
}
///
var a:String?
var t = a ?? "guest"
println("hello,"+t)

/
var backView = UIView(frame: CGRectMake(0.0, 0.0, 200, 400))

backView.backgroundColor = UIColor.blueColor()


var colorLabel = UILabel(frame: CGRectMake(0.0, 0.0, 200, 40))
colorLabel.backgroundColor = UIColor(red: CGFloat(tuple.red/255), green: CGFloat(tuple.green/255), blue: CGFloat(tuple.blue/255), alpha: 0.8)

var label = UILabel(frame: CGRectMake(0.0, 0.0, 200, 40))

label.font = UIFont(name: "Arial", size: 20)
label.textColor = UIColor.yellowColor()
label.textAlignment = NSTextAlignment.Right
label.text = "hello";

colorLabel.addSubview(label)

backView.addSubview(colorLabel)
//
var A:Set<Int> = Set([2,3,1,5])

A.insert(2)

var B:Set<Int> = [6,5,3,2,1]

A.isSubsetOf(B)

A.union(B)

var str = "hello";
(str as NSString).containsString("o")

var arr = [1,2,3]

var d:[Int:String] = [1:""]

var myarr:[Int] = [1,3]


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值