swift练习一

前端之家收集整理的这篇文章主要介绍了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,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,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,2,1]

A.isSubsetOf(B)

A.union(B)

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

var arr = [1,3]

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

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

猜你在找的Swift相关文章