Skip to content

Instantly share code, notes, and snippets.

View susieyy's full-sized avatar

yohei sugigami susieyy

View GitHub Profile
@susieyy
susieyy / PreviousViewController.swift
Created August 4, 2016 10:41
Access previous view controller in navigation stack
extension UIViewController {
var previousViewController: UIViewController? {
guard let navigationController = navigationController else { return nil }
let count = navigationController.viewControllers.count
return count < 2 ? nil : navigationController.viewControllers[count - 2]
}
}
@susieyy
susieyy / swagger-codegen-config-help.sh
Created September 6, 2017 00:35
swagger-codegen config-help swift
java -jar ./swagger-codegen-cli.jar config-help -l swift
CONFIG OPTIONS
sortParamsByRequiredFlag
Sort method arguments to place required parameters before optional parameters. (Default: true)
ensureUniqueParams
Whether to ensure parameter names are unique in an operation (rename parameters that are not). (Default: true)
allowUnicodeIdentifiers
@susieyy
susieyy / CombineMergeManyWithFutureTest.swift
Last active November 17, 2020 14:20
Use Future to work around an issue where the Combine's MergeMany operator may not perform background processing.
import Foundation
import Combine
// see: not working https://gist.github.com/susieyy/3e1059d5dc9d0f2278db07e3fb73332f
// Use Future to work around an issue where the Combine's MergeMany operator may not perform background processing.
// $ swift --version
// Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8)
// Target: x86_64-apple-darwin20.1.0
@susieyy
susieyy / CombineMergeManyTest.swift
Last active November 16, 2020 10:41
Examines an issue where the MergeMany operator in Combine may not perform background processing.
import Foundation
import Combine
// see: workaround https://gist.github.com/susieyy/95e8f55fd077162c7e02c13b541e8309
// Examines an issue where the MergeMany operator in Combine may not perform background processing.
// $ swift --version
// Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8)
// Target: x86_64-apple-darwin20.1.0
@susieyy
susieyy / PushTransitionWithCustomAnimation.swift
Created February 23, 2017 08:57
push transition with custom animation
let transition = CATransition()
transition.duration = 0.2
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
transition.type = kCATransitionFade
navigationController?.view.layer.addAnimation(transition, forKey: nil)
navigationController?.pushViewController(con, animated: true)
final class OverridedCell: UITableViewCell {
static let identifier = "OverridedCell"
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
prepareView()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
final class SearchContainerViewController: UIViewController {
let hoge: Hoge
convenience init(hoge: Hoge) {
self.init(nibName: nil, bundle: nil)
self.hoge = hoge
}
override init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) { super.init(nibName: nil, bundle: nil) }
required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }
final class SwipeContainerViewController: UIPageViewController {
convenience init() {
self.init(transitionStyle: .Scroll, navigationOrientation: .Horizontal, options: nil)
}
override init(transitionStyle style: UIPageViewControllerTransitionStyle, navigationOrientation: UIPageViewControllerNavigationOrientation, options: [String : AnyObject]?) {
super.init(transitionStyle: style, navigationOrientation: navigationOrientation, options: options)
}
@susieyy
susieyy / SeparatorInset.swift
Created August 9, 2016 06:30
UITableView's separator inset
// Hide
cell.separatorInset = UIEdgeInsets(top: 0, left: tableView.bounds.width, bottom: 0, right: 0)
cell.layoutMargins = UIEdgeInsetsZero
// Show
cell.separatorInset = UIEdgeInsetsZero
cell.layoutMargins = UIEdgeInsetsZero
@susieyy
susieyy / Check_if_view_controller_is_presented_modally__or_pushed_on_a_navigation_stack.swift
Last active August 3, 2016 09:40
Check if view controller is presented modally, or pushed on a navigation stack
// @see http://stackoverflow.com/a/23620428/1002412
// @see http://level49.com/119
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
if isBeingDismissed() {
// being dismissed
} else if isMovingFromParentViewController() {
// being poped
} else {