Created
July 6, 2019 10:31
-
-
Save cafielo/59c7ed1923adef1aaf2aca5a3b0f630b to your computer and use it in GitHub Desktop.
Swift Basic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: var, let 이해 | |
let numOfEyes = 2 | |
var fisrtName = "John" | |
// MARK: Array, Dictionary 이해 | |
let scores: [Int] = [56, 92, 100, 80] | |
let firstScore = scores[0] | |
let libraryInfo: [String: Any] = ["name": "Coffee and Library", "price": 12000, "location": "Bundang"] | |
let libaryName = libraryInfo["name"] | |
// MARK: 조건문 | |
if firstScore > 90 { | |
print("you are very smart") | |
} else { | |
print("you are smart, too") | |
} | |
let nameKey = "name" | |
let priceKey = "price" | |
let locationKey = "location" | |
var anyKey = nameKey | |
switch anyKey { | |
case nameKey: | |
print("value is \(libraryInfo[anyKey])") | |
case priceKey: | |
print("value is \(libraryInfo[anyKey])") | |
case locationKey: | |
print("value is \(libraryInfo[anyKey])") | |
default: | |
print("there is no such a key in dictionary") | |
} | |
// MARK: 반복문 | |
// print all scores | |
for score in scores { | |
print("score is \(score)") | |
} | |
// MARK: Class | |
class Student { | |
var score: Int | |
var name: String | |
init(score: Int, name: String) { | |
self.score = score | |
self.name = name | |
} | |
func printScore() { | |
print("my score is \(score)") | |
} | |
func nameAndSchool() -> String { | |
return "my name is \(name), I'm a student of XX univ." | |
} | |
} | |
// MARK: Struct | |
struct Book { | |
let author: String | |
let title: String | |
let price: Int | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment