Skip to content

Instantly share code, notes, and snippets.

@starhoshi
starhoshi / UIWindow+Ex.swift
Created June 27, 2017 12:30
rootViewController を別の ViewController に入れ替える [Swift3]
import UIKit
extension UIWindow {
func changeRootViewController(new viewController: UIViewController) {
UIView.transition(
with: UIApplication.shared.keyWindow!,
duration: 0.5,
options: .transitionCrossDissolve,
animations: {
UIApplication.shared.keyWindow?.rootViewController = viewController
@starhoshi
starhoshi / UIWebView+Ex.swift
Last active June 27, 2017 12:31
UIWebView で Custom UserAgent をセットする [Swift 3]
import UIKit
extension UIWebView {
func setCustomUserAgent() {
let classiSuffix = Constants.userAgent
let originalUserAgent = stringByEvaluatingJavaScript(from: "navigator.userAgent")!
let customUserAgent = originalUserAgent + "+CustomUA"
UserDefaults.standard.register(defaults: ["UserAgent": customUserAgent])
print("new userAgent: \(pbUserAgent)")
}
@starhoshi
starhoshi / ManageViewController.swift
Created February 4, 2017 15:05
SnapKit で画面を作ってみる遊び
import UIKit
import SnapKit
import RxSwift
import RxCocoa
final class ManageView: UIView {
let descriptionLabel = UILabel()
let greetingTitleLabel = UILabel()
let greetingLabel = UILabel()
let segmented = UISegmentedControl(items: ["挨拶の始まり選択", "自由入力"])
@starhoshi
starhoshi / observer.swift
Created January 12, 2017 16:47
Swift observer pattern.
import Foundation
protocol Observer {
var id: String { get }
func update(_ string: String)
}
extension Observer {
func update(_ string: String) {
print("\(type(of: self)) に届いた新しい値は \(string) です。")
@starhoshi
starhoshi / ios9-transport-security.sh
Last active January 4, 2016 06:12
cordova ios9 App Transport Security (project_root/after_prepare/ios9-transport-security.sh)
#!/bin/bash
PLIST=platforms/ios/*/*-Info.plist
cat << EOF |
Add :NSAppTransportSecurity dict
Add :NSAppTransportSecurity:NSExceptionDomains dict
Add :NSAppTransportSecurity:NSExceptionDomains:dev.example.com dict
Add :NSAppTransportSecurity:NSExceptionDomains:dev.example.com:NSExceptionAllowsInsecureHTTPLoads bool YES
Add :NSAppTransportSecurity:NSExceptionDomains:dev.example.com:NSExceptionRequiresForwardSecrecy bool NO
set nosmoothscroll
set noautofocus
let searchlimit = 30
let scrollduration = 10
let scrollstep = 70
let locale = "jp"
let searchalias g = "google"
let blacklists = ["chrome://*","https://mail.google.com/*","http://feedly.com/*","https://www.google.com/calendar/*","https://my.omniture.com/*"]
let barposition = "bottom"