Skip to content

Instantly share code, notes, and snippets.

View cafielo's full-sized avatar
💭
I may be slow to respond.

Joonwon Lee cafielo

💭
I may be slow to respond.
View GitHub Profile
@cafielo
cafielo / env.swift
Created February 27, 2021 14:57
Env Configuration
enum Env: String {
case debug
case testFlight
case appStore
}
struct App {
struct Folders {
static let documents: NSString = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as NSString
static let temporary: NSString = NSTemporaryDirectory() as NSString
let alertController = UIAlertController(title: nil, message: "Alert message.", preferredStyle: .actionSheet)
let defaultAction = UIAlertAction(title: "Default", style: .default, handler: { (alert: UIAlertAction!) -> Void in
// Do some action here.
})
let deleteAction = UIAlertAction(title: "Delete", style: .destructive, handler: { (alert: UIAlertAction!) -> Void in
// Do some destructive action here.
})
@cafielo
cafielo / UIAlertController+Presneting.swift
Created January 31, 2021 01:45
General UIAlertController Presenting
let alertController = UIAlertController(title: nil, message: "Alert message.", preferredStyle: .actionSheet)
let defaultAction = UIAlertAction(title: "Default", style: .default, handler: { (alert: UIAlertAction!) -> Void in
// Do some action here.
})
let deleteAction = UIAlertAction(title: "Delete", style: .destructive, handler: { (alert: UIAlertAction!) -> Void in
// Do some destructive action here.
})
@cafielo
cafielo / GeneralWayOfRounding.swift
Created January 30, 2021 18:34
general way of rounding view
let redBox = UIView(frame: CGRect(x: 100, y: 100, width: 128, height: 128))
redBox.backgroundColor = .red
redBox.layer.cornerRadius = 25
@cafielo
cafielo / RoundCornerView.swift
Created January 30, 2021 18:32
How to round only specific corners
extension UIView {
func roundCorners(corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
layer.mask = mask
}
}
@cafielo
cafielo / CoreMotion.swift
Created January 30, 2021 18:15
import coremotion
// 1 import
import CoreMotion
// 2 create property that can store CMMotionManager
var motionManager: CMMotionManager!
// 3 initialize it
motionManager = CMMotionManager()
// 4 check accelermoter is available
@cafielo
cafielo / ViewProtocolDemo.swift
Last active January 6, 2021 12:57
SwiftUI ViewProtocol
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Text("Hello, world!")
Image(systemName: "swift")
}
}
}
// MARK: var, let 이해
let numOfEyes = 2
var fisrtName = "John"
// MARK: Array, Dictionary 이해
let scores: [Int] = [56, 92, 100, 80]
let firstScore = scores[0]
@cafielo
cafielo / UIDevice+Notch.swift
Created October 18, 2018 16:36
how to detect notch device in swift
extension UIDevice {
var hasNotch: Bool {
let bottom = UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0
return bottom > 0
}
}
if UIDevice.current.hasNotch {
//... consider notch
extension String {
func trimTrailingWhitespaces() -> String {
return self.replacingOccurrences(of: "\\s+$", with: "", options: .regularExpression)
}
}
let string = "there is string with trailing whitespace "
let trimmed = string.trimTrailingWhitespaces()