Skip to content

Instantly share code, notes, and snippets.

View hsleedevelop's full-sized avatar
🔥

HS Lee hsleedevelop

🔥
View GitHub Profile
class ShopFilterParams: NSObject, Codable, DictionaryMapping {
private var config: [String: Any]?
private var defaults: [String: Any]?
private var list: [String: Any]?
var showAreaFilter: Bool?
var showServiceFilter: Bool?
var defaultAreaId: String?
var defaultService: String?
//
// UPCarouselFlowLayout.swift
// UPCarouselFlowLayoutDemo
//
// Created by Paul Ulric on 23/06/2016.
// Copyright © 2016 Paul Ulric. All rights reserved.
//
// https://github.com/ink-spot/UPCarouselFlowLayout/blob/master/UPCarouselFlowLayout/UPCarouselFlowLayout.swift
import UIKit
extension XCUIElement {
func clearText(andReplaceWith newText:String? = nil) {
tap()
press(forDuration: 1.0)
var select = XCUIApplication().menuItems["Select All"]
if !select.exists {
select = XCUIApplication().menuItems["Select"]
}
//For empty fields there will be no "Select All", so we need to check
@hsleedevelop
hsleedevelop / wkWebView.m
Last active July 21, 2020 07:21
WKWebView not opening links with target=“_blank”?
//My solution is to cancel the navigation and load the request with loadRequest: again. This will be come the similar //behavior like UIWebView which always open new window in the current frame.
//
//Implement the WKUIDelegate delegate and set it to _webview.uiDelegate. Then implement:
//https://stackoverflow.com/a/25853806/3374327
- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
{
if (!navigationAction.targetFrame.isMainFrame) {
[webView loadRequest:navigationAction.request];
}
class UserInfoValidator {
enum Validation {
case nickname
var pattern: String {
switch self {
case .nickname:
return "^[a-zA-Z0-9ㄱ-ㅣ가-힣\\-\\.\\_]{1,16}$"
default:
return ""
extension UILabel {
@objc
func set(underLineFor keyword: String) {
guard let text = self.text ?? self.attributedText?.string else { return }
let attributedString = self.attributedText.map(NSMutableAttributedString.init(attributedString:)) ?? NSMutableAttributedString(string: text)
let indices = attributedString.string.indicesOf(string: keyword)
let length = keyword.count
@hsleedevelop
hsleedevelop / UIViewController+Extension.swift
Created April 23, 2020 01:23
ViewController Extension
extension UIViewController {
func isVisible() -> Bool {
if #available(iOS 9.0, *) {
if let view = self.viewIfLoaded {
return view.window != nil
}
return false
} else {
@hsleedevelop
hsleedevelop / ViewController.swift
Last active February 13, 2020 11:04
embed a viewController to another viewController
extension UIViewController {
func embed(_ vc: UIViewController, in _containerView: UIView? = nil) {
let containerView: UIView = _containerView ?? view // Use the whole view if no container view is provided.
containerView.addSubview(vc.view)
NSLayoutConstraint.activate([
vc.view.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 0),
vc.view.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: 0),
vc.view.topAnchor.constraint(equalTo: containerView.topAnchor, constant: 0),
vc.view.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: 0)
])
extension UIView {
func superview<T>(of type: T.Type) -> T? {
return superview as? T ?? superview.flatMap { $0.superview(of: type) }
}
}
// Example usage:
func textFieldDidBeginEditing(_ textField: UITextField) {
// Get the cell containing the textfield.
if let cell = textField.superview(of: TextFieldTableViewCell.self) {
@hsleedevelop
hsleedevelop / BetterXcodeJumpToCounterpartSwift.org
Created November 20, 2019 06:26 — forked from danielmartin/BetterXcodeJumpToCounterpartSwift.org
Add support for a better Xcode's Jump to Next Counterpart in Swift

If you work on a Swift project that follows the Model-View-ViewModel (MVVM) architecture or similar, you may want to jump to counterpart in Xcode from your view to your model, and then to your view model. (ie. by using Ctrl+Cmd+Up and Ctrl+Cmd+Down).

You can do this in recent versions of Xcode by setting a configuration default.

From a terminal, just type this command and press Enter:

defaults write com.apple.dt.Xcode IDEAdditionalCounterpartSuffixes -array-add "ViewModel" "View"