Skip to content

Instantly share code, notes, and snippets.

View devxoul's full-sized avatar
👨‍💻
Always coding

Suyeol Jeon devxoul

👨‍💻
Always coding
View GitHub Profile
import Foundation
let queue = DispatchQueue(label: "test")
var threads: [Thread] = []
for _ in 0..<100 {
queue.async {
threads.append(Thread.current)
// 1) if this line is not commented out
// 2) if this line is commented out
@devxoul
devxoul / UIViewControllerDeallocSync.swift
Last active October 16, 2019 13:04
Does UIViewController get deallocated synchronously? NO. (if view is loaded)
weak var weakViewController: UIViewController?
_ = {
let viewController = UIViewController()
viewController.loadViewIfNeeded() // this line prevents from deallocation
weakViewController = viewController
}()
XCTAssertNil(weakViewController) // (fail) weakViewController = Optional(<UIViewController: 0x7fd55e705080>)
@devxoul
devxoul / MySpec.swift
Last active October 15, 2019 20:41
Verify RxSwift resources and scheduler actions after finishing the tests.
import Quick
import RxSwift
final class MySpec: QuickSpec {
override func spec() {
verifyRxResourcesAreReleased()
it("fails") {
_ = Observable<Int>.interval(.seconds(1), scheduler: MainScheduler.instance).subscribe()
}
@devxoul
devxoul / GradientMaskLineRenderer.swift
Last active October 4, 2019 08:22
A custom gradient mask line renderer for https://github.com/danielgindi/Charts
class GradientMaskLineRenderer: LineChartRenderer {
override init(dataProvider: LineChartDataProvider, animator: Animator, viewPortHandler: ViewPortHandler) {
super.init(dataProvider: dataProvider, animator: animator, viewPortHandler: viewPortHandler)
}
override func drawFilledPath(context: CGContext, path: CGPath, fill: Fill, fillAlpha: CGFloat) {
let rect = viewPortHandler.contentRect
let colorSpace = CGColorSpaceCreateDeviceGray()
let bitmapContext = CGContext(
class Cell {
private let viewBlock: () -> Void
init(viewBlock: @escaping () -> Void) {
self.viewBlock = viewBlock
}
deinit {
print(type(of: self), #function)
}
@devxoul
devxoul / PULL_REQUEST_TEMPLATE.md
Created September 27, 2019 07:07
StyleShare Pull Request Template

배경

작업 내용

테스트 방법

리뷰 노트

@devxoul
devxoul / Date+ISO8601.swift
Created September 19, 2019 13:15
Date+ISO8601.swift
//
// Date+ISO8601.swift
// SSFoundation
//
// Created by Suyeol Jeon on 19/09/2019.
// Copyright © 2019 StyleShare Inc. All rights reserved.
//
import Foundation
class User: Hashable {
let name: String
let age: Int
init(name: String, age: Int) {
self.name = name
self.age = age
}
func hash(into hasher: inout Hasher) {
playgroundShouldContinueIndefinitely()
class Reactor {
lazy var state: Observable<Int> = self.closure().concat(Observable<Int>.never())
private lazy var closure: () -> Observable<Int> = self.closureImplementation()
deinit {
print("DEINIT SUCCESS!!!")
}
@devxoul
devxoul / design.swift
Last active September 23, 2018 10:27
Which do you think is better design? (in the perspective of scalability, consistency, etc.)
////////////////////////////////////////////////////////////////////////////////
// Usage //
////////////////////////////////////////////////////////////////////////////////
struct JoinForm {
var emailField: FormField
var usernameField: FormField
init(email: String?) {
self.emailField = FormField(value: email)