Skip to content

Instantly share code, notes, and snippets.

View AppleCEO's full-sized avatar
๐Ÿ’ป

๋„๋ฏธ๋‹‰ AppleCEO

๐Ÿ’ป
View GitHub Profile
@AppleCEO
AppleCEO / generic2.swift
Created June 18, 2019 01:47
Generic example 2
func **<T: Multipleiable> (lhs: T, rhs: T) -> T {
return lhs * rhs
}
@AppleCEO
AppleCEO / description.swift
Created June 18, 2019 02:59
description example
struct Point {
let x: Int, y: Int
var description: String {
return "(\(x), \(y))"
}
}
let p = Point(x: 21, y: 30)
@AppleCEO
AppleCEO / printStruct.swift
Created June 18, 2019 03:01
print struct example
struct Point {
let x: Int, y: Int
}
let p = Point(x: 21, y: 30)
print(p)
// Prints "Point(x: 21, y: 30)"
@AppleCEO
AppleCEO / CustomStringConvertible.swift
Created June 18, 2019 03:10
CustomStringConvertible example
struct Point: CustomStringConvertible {
let x: Int, y: Int
var description: String {
return "(\(x), \(y))"
}
}
let p = Point(x: 21, y: 30)
let s = String(describing: p)
@AppleCEO
AppleCEO / CustomStringConvertibleToClass.swift
Created June 18, 2019 03:18
CustomStringConvertible example to class
class Point: CustomStringConvertible {
let x: Int, y: Int
var description: String {
return "(\(x), \(y))"
}
init(x: Int, y: Int) {
self.x = x
self.y = y
@AppleCEO
AppleCEO / stringSplited.swift
Last active June 20, 2019 08:47
subsequence example
let string = "a b c d e f"
let stringSplited = string.split(separator: " ")
// stringSplited is String.SubSequence type
@AppleCEO
AppleCEO / typealias.swift
Last active June 21, 2019 02:40
typealias example
typealias MyInt = Int
typealias YourInt = Int
let age : MyInt = 10 // MyInt ๋Š” Int ์˜ ๋‹ค๋ฅธ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
let year : YourInt = 20 // YourInt ๋Š” Int ์˜ ๋‹ค๋ฅธ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
let sum : Int
sum = year + age
// result: 30
@AppleCEO
AppleCEO / readLine.swift
Created June 25, 2019 08:42
readLine example
let input = readLine()
@AppleCEO
AppleCEO / inputed.swift
Created June 25, 2019 08:45
readLine inputed example
let input = readLine()
if let inputed = input {
print(inputed)
} else {
print("Non inputed")
}
@AppleCEO
AppleCEO / MyPoint.swift
Last active June 26, 2019 03:44
point example
struct MyPoint {
private(set) var x = 0
private(set) var y = 0
init(x: Int = 0, y: Int = 0) {
self.x = x
self.y = y
}
}