This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIViewController { | |
class func instantiateFromStoryboard<T: UIViewController>() -> T { | |
if let name = NSStringFromClass(T.self)?.componentsSeparatedByString(".").last { | |
let storyboard: UIStoryboard = UIStoryboard(name: name, bundle: nil) | |
if let vc = storyboard.instantiateInitialViewController() as? T { | |
return vc | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GetClassName { | |
class func getClassName(obj: AnyObject) -> String? { | |
return NSStringFromClass(obj.dynamicType)?.componentsSeparatedByString(".").last | |
} | |
class func getClassName(aClass: AnyClass) -> String? { | |
return NSStringFromClass(aClass)?.componentsSeparatedByString(".").last | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol NibInstantiatable { | |
static var NibName: String { get } | |
} | |
extension NibInstantiatable { | |
static var NibName: String { return String(Self) } | |
static func instantiate() -> Self { | |
return instantiateWithName(NibName) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum ValidationResult { | |
case Success | |
case Failure(ValidationErrorType) | |
} | |
enum ValidationErrorType: ErrorType { | |
case WrongLength(Int) // マイナンバーの桁数(文字数)が不正の場合 | |
case NotANumber // 数字以外が含まれている場合 | |
case InvalidNumber // 検査して不正なマイナンバーだった場合 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i in 1...100{print((i%3>0 ?i%5>0 ?String(i):"":"Fizz")+(i%5>0 ?"":"Buzz"))} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
usage() { | |
cat <<HELP | |
SYNOPSIS: | |
$0 [-d] [iOS(default)|watchOS|tvOS|Mac] | |
$0 [-h] | |
ARGUMENTS: | |
iOS print paths for iOS (default) | |
watchOS print paths for iOS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
private func convertFullWidthToHalfWidth(reverse: Bool) -> String { | |
let str = NSMutableString(string: self) as CFMutableString | |
CFStringTransform(str, nil, kCFStringTransformFullwidthHalfwidth, reverse) | |
return str as String | |
} | |
var hankaku: String { | |
return convertFullWidthToHalfWidth(false) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func autoreleasepool(@noescape code: () throws -> ()) rethrows { | |
try { | |
var error: ErrorType? | |
autoreleasepool { | |
do { | |
try code() | |
} catch (let e) { | |
error = e | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new-podspec () { | |
if [ $# -lt 1 ] | |
then | |
echo "Library name required." | |
exit 1 | |
fi | |
: ${2:=1.0.0} | |
cat <<PODSPEC > "$1.podspec" | |
Pod::Spec.new do |s| | |
s.name = "$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol EnhancedErrorType: ErrorType, CustomStringConvertible { | |
var domain: String { get } | |
var code: Int { get } | |
var userInfo: [NSObject: AnyObject]? { get } | |
} | |
extension EnhancedErrorType { | |
var _domain: String { | |
return domain | |
} |
OlderNewer