Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions learning_swift-daniel_seong.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//: Playground - noun: a place where people can play

import UIKit

func swap<X> (inout a: X, inout no b: X)
{
(a,b) = (b,a)
}

var a = "hello"
var b = "bye"
swap(&a, &b)
[a,b]


func flexStrings(s1: String = "", _ s2: String = "") -> String {
if (s1 + s2 == "")
{
return "none"
}
return s1 + s2
}

var flex = flexStrings("hi", "you")
var newflex = flexStrings()

func sumAny<T>(a1: T...) -> String
{
let convert = a1.map({(b1: T) -> Int in
switch b1
{
case "" as String, 0 as Int:
return -10
case let x as String where Int(x) > 0:
return Int(x)!
case is Int:
return b1 as! Int
default:
return 0
}
})

return String(convert.reduce(0, combine: {(c1: Int, c2: Int) -> Int in c1 + c2}))
}

var test = sumAny ("", 0, "9", 2, "-10")

func countFrom(from: Int, to: Int)
{
if (from <= to)
{
print(from)
countFrom(from + 1, to: to)
}
}




4 changes: 4 additions & 0 deletions learning_swift-daniel_seong.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios'>
<timeline fileName='timeline.xctimeline'/>
</playground>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.