-
for in 的 那个i 还不能加var 一声明就报错 for 的必须加 已试查看全部
-
二维数组的初始化 var board = Array< Array<Int>>() for i in 0..10 { board.append( Array(count:10, repeatedValue:0) ) } break 可以跳出多层循环,只要在循环钱加上label,然后break label就可以了。查看全部
-
liuyu讲得超级赞,只是新的章节什么时候上传查看全部
-
试做相同长度的字符串,按字典排序 a长度<b长度 && a首字母 >b首字母查看全部
-
传引用需加入&查看全部
-
import UIKit /**************************************/ var num1 = 8 if num1 == 4 { println("3+4=7!") } else { println("3+7!=8") } var userimput:Int? userimput = 23 /****************************************/ let userimput2 = "45" var age = userimput2.toInt() if (age != nil) { println("your age is " + String(age!)) } else { println("invalid age") } /*****************************************/ var a = 5 var b = 2 var c = 0 a + b a - b a * b a / b a % b /***********************************/ let statusBarHeight = 20 let basicViewHeight = 548 var inFullScreenMode = true var viewHeight = basicViewHeight + ( inFullScreenMode ? statusBarHeight : 0) var score = 62 var rate = score >= 60 ? "PASS" : "FAILED" /***********************************/ for index in 1...10 { index } /**********Logical Operations*******/ var x = true var y = false if x && y { println("TRUE") } else { println("FALSE") } //////////////////////////查看全部
-
var arr = ["A","B","C"] arr.count arr.isEmpty arr.append("D") arr += ["E","F"] arr.insert("Hello", atIndex: 0) arr[1] = "AA" arr arr[2...4] = ["Hi"] arr for index in 0..<arr.count { println(arr[index]) } for item in arr { println(item) } for (index,item) in enumerate(arr){ println("\(index) - \(item)") }查看全部
-
var arr = ["A","B","C"] var arr2:[String] = ["A","B","C"] var arr3:Array<String> = ["A","B","C"] var arr4 = [String]() var arr5 = Array<String>() var arr6:[String] = [] var arr7:Array<Int> = [] // 初始化10个0的数组 arr7 = [Int](count: 10, repeatedValue: 0) var arr8 = [1,2,3] var arr9 = arr7 + arr8查看全部
-
import UIKit var str = "Welcome to Play Swift! Step by Step learn Swift language from now!" // range str.rangeOfString("Step") str.rangeOfString("Step", options: NSStringCompareOptions.BackwardsSearch) str.rangeOfString("welcome", options: NSStringCompareOptions.CaseInsensitiveSearch) str.startIndex str.endIndex let strRange = Range<String.Index>(start: str.startIndex, end: str.endIndex) let startIndex:String.Index = str.startIndex; let endIndex:String.Index = advance(startIndex, 10) let searchRange = Range<String.Index>(start: startIndex, end: endIndex) str.rangeOfString("Step", options: NSStringCompareOptions.CaseInsensitiveSearch, range: searchRange) // substring var toIndex = advance(startIndex, 4) str.substringToIndex(toIndex) // insert var insertIndex = advance(startIndex, 22) str.insert("!", atIndex: insertIndex) // remove str.removeAtIndex(insertIndex) str // replace var replaceEndIndex = advance(str.startIndex, 13)查看全部
-
为何没有协议、范型的章节查看全部
-
使用insert功能时,str一定是变量,let生成的常量无法进行此操作查看全部
-
定义~查看全部
-
var ge:GameEnding = GameEnding.Lose 貌似不能直接赋值,木有意义查看全部
-
有函数是编程的灵活,亦有面向对象编程的严谨,swift!查看全部
-
利用hasPrefix和hassuffix方法来对数组里的字符串进行判断识别,同时还用for in 对数组进行遍历查看全部
举报
0/150
提交
取消