Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Swift Basic
// 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])")
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 = 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
You can’t perform that action at this time.