diff --git a/Chanllenge_Questions.playground/Contents.swift b/Chanllenge_Questions.playground/Contents.swift new file mode 100644 index 0000000..90d7585 --- /dev/null +++ b/Chanllenge_Questions.playground/Contents.swift @@ -0,0 +1,48 @@ +//: Playground - noun: a place where people can play + +import Cocoa + +var str = "Hello, playground" +func swapVariables(inout s1:String,inout _ s2:String){ + let s3:String=s1 + s1=s2 + s2=s3 +} +var changedString1 = "My name is David" +var changedString2 = "My last name is Xu" +swapVariables(&changedString1, &changedString2) +print(changedString1) +print(changedString2) + +func addMultipleString(words:String...)->String{ + var newString:String = "" + for word in words{ + newString+=word + } + if words.count==0{return "none"} + else {return newString} +} +print (addMultipleString("my ","name ","is ","David.")) +print (addMultipleString()) + + +func swap(inout a:T, inout with b:T) { (a, b) = (b, a) } //demo code +var a = "Marin", b = "Todorov" +swap(&a, &b) +[a, b] + +func countFrom(from:Int,_ to:Int){ + print(from,terminator:"") + if from String { + var b:String = a + var c:String + c.append(b.endIndex.predecessor()) + +} + diff --git a/Chanllenge_Questions.playground/contents.xcplayground b/Chanllenge_Questions.playground/contents.xcplayground new file mode 100644 index 0000000..06828af --- /dev/null +++ b/Chanllenge_Questions.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Chanllenge_Questions.playground/playground.xcworkspace/contents.xcworkspacedata b/Chanllenge_Questions.playground/playground.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/Chanllenge_Questions.playground/playground.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Chanllenge_Questions.playground/playground.xcworkspace/xcuserdata/davidxu.xcuserdatad/UserInterfaceState.xcuserstate b/Chanllenge_Questions.playground/playground.xcworkspace/xcuserdata/davidxu.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..bde9f0b Binary files /dev/null and b/Chanllenge_Questions.playground/playground.xcworkspace/xcuserdata/davidxu.xcuserdatad/UserInterfaceState.xcuserstate differ