Skip to content

Instantly share code, notes, and snippets.

View ppth0608's full-sized avatar
🍕
Stay hungry

Ben.Park ppth0608

🍕
Stay hungry
View GitHub Profile
@ppth0608
ppth0608 / Gradient.swift
Last active July 2, 2019 15:59
Add Gradient Layer(.clear to .black) on UIView
import UIKit
protocol GradientEffect {
var gradientEffectEnabled: Bool { get set }
}
extension GradientEffect where Self: UIView {
func setGradientView() {
@ppth0608
ppth0608 / ArrayToDictionaryGroupBy.swift
Last active July 2, 2019 15:59
Array to Dictionaty group by value
struct Person: CustomDebugStringConvertible {
var name: String
var age: Int
var debugDescription: String {
return "\(name)(\(age))"
}
}
let persons = [
@ppth0608
ppth0608 / Clip.swift
Created July 2, 2019 15:58
How to use RxMoya
import Foundation
public struct Clip: Codable, Equatable {
public var id: Int
public var category: ClipCategory
public var title: String
public var userTitle: String
public var imageURLString: String
public var source: String
@ppth0608
ppth0608 / TimeInterval+Project.swift
Created July 3, 2019 04:02
How to convert TimeInterval to Milliseconds or Seconds
import Foundation
extension TimeInterval {
var seconds: Int {
return Int(self.rounded())
}
var milliseconds: Int {
return Int(self * 1_000)
@ppth0608
ppth0608 / ForceTouchGestureConvertible.swift
Last active July 3, 2019 09:10
How to use Force Touch Gesture to view
import UIKit
/// Protocol that must be concatenated for the convenient use of`ForceTouchGestureRecognizer`
protocol ForceTouchGestureConvertible: class {
var forceTouchGestureRecognizer: UIGestureRecognizer? { get set }
}
extension ForceTouchGestureConvertible where Self: UIView {
@ppth0608
ppth0608 / Extension.Swift
Last active July 4, 2019 13:43
String to date, Date to String
import Foundation
exntension Date {
func toString(format: String) -> String {
let formatter = DateFormatter()
formatter.calendar = Calendar(identifier: .gregorian)
formatter.dateFormat = format
return formatter.string(from: self)
}
}
@ppth0608
ppth0608 / Service.swift
Created July 7, 2019 09:58
How to implement `DI(Dependency Injection)` with `Service` pattern
protocol ServiceProviderType {
var clipService: ClipServiceType { get }
}
class ServiceProvider: ServiceProviderType {
lazy var clipService: ClipServiceType = ClipService(provider: self, clipAPI: ClipAPI())
}
@ppth0608
ppth0608 / AppDelegate.swift
Last active July 13, 2019 08:20
Refactoring the function 'didFinishLaunchingWithOptions' in the `AppDelegate' file using the class 'Launcher'
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var launcher: Laucher?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let window = UIWindow(frame: UIScreen.main.bounds)
self.window = window
launcher = AppLauncher(application: application, launchItem: AppLaunchItem(window: window))
@ppth0608
ppth0608 / UIStoryboard+Ben.swift
Created July 13, 2019 09:14
How to make UIViewController when using storyboard
enum Storyboard {
case main
var filename: String {
switch self {
case .main: return "Main"
}
}
}
@ppth0608
ppth0608 / UIAlertController+Ben.swift
Created July 14, 2019 04:22
How to using UIAlertController with RxSwift
import RxSwift
import UIKit
extension UIAlertController {
struct AlertAction {
var title: String?
var style: UIAlertAction.Style
static func action(title: String?, style: UIAlertAction.Style = .default) -> AlertAction {