This file contains hidden or 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 { | |
func replace(_ dictionary: [String: String]) -> String { | |
dictionary.reduce(into: self) { result, data in | |
result = result.replacingOccurrences(of: data.key, with: data.value) | |
} | |
} | |
} |
This file contains hidden or 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
let dispatchGroup = DispatchGroup() | |
let dispatchQueue = DispatchQueue(label: "queue", attributes: .concurrent) | |
(1...10).forEach { index in | |
dispatchGroup.enter() | |
dispatchQueue.async(group: dispatchGroup) { | |
// --- 処理 --- | |
sleep(UInt32(Int.random(in: 1..<4))) | |
print("index: \(index)") | |
// --- end --- | |
dispatchGroup.leave() |
This file contains hidden or 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 Data { | |
static func async(contentsOf url: URL, completion: @escaping (Data?) -> Void) { | |
DispatchQueue.global().async { | |
DispatchQueue.main.async { | |
let result: Data? = try? Data(contentsOf: url) | |
completion(result) | |
} | |
} | |
} | |
} |
This file contains hidden or 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 UIImage { | |
/** | |
指定画像の色を変更した新しい画像を生成する (alpha値が0以外のものを全てを変える) | |
- parameter originalImage: 対象画像 | |
- parameter color: 変更カラー | |
- returns: 生成された画像 | |
*/ | |
static func differentColor(originalImage: UIImage, color: UIColor) -> UIImage { |
This file contains hidden or 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
<?php | |
$deviceToken = "デバイストークンをいれる"; | |
$host = "gateway.push.apple.com"; | |
$port = 2195; | |
$cert = "apn_dist.pem"; // 同じディレクトリに”apn_dist.pem”という名前で証明書を置いておく | |
$aps = array(); | |
$aps["aps"] = array( | |
"alert"=>"テスト" | |
,"badge" =>1 |
This file contains hidden or 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 Hoge { | |
let disposeBag = DisposeBag() | |
func fuga(completed: (error: ErrorType?) -> () = { _ in} ) { | |
let createProc = { (deviceToken: String) -> Observable<String> in | |
Observable.create { observer in | |
// 非同期。エラーにしてみる | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)) { | |
observer.onError(NSError(domain: "", code: 1, userInfo: nil)) | |
observer.onCompleted() | |
} |
This file contains hidden or 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 NSDate { | |
class func NowLocalDate() -> NSDate { | |
return NSDate(timeIntervalSinceNow: Double(NSTimeZone.systemTimeZone().secondsFromGMT)) | |
} | |
} |
This file contains hidden or 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 NSData { | |
func hexString() -> String { | |
return (0..<length).reduce("") { (hex, index) in | |
var byte = UInt8(0) | |
getBytes(&byte, range: NSMakeRange(index, 1)) | |
return hex + String(format: "%02x", arguments: [byte]) | |
} | |
} | |
} |
This file contains hidden or 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 Hoge { | |
var fuga = 0 | |
} | |
let array = [Hoge(), Hoge()] // letでOK | |
// forEachで配列データをいじる | |
array.forEach { $0.fuga = 1 } | |
array // [{fuga 1}, {fuga 1}] | |
// mapで配列のデータをいじる | |
let _ = array.map { $0.fuga = 2 } |
This file contains hidden or 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
+ (CFTimeInterval)fadeDuration { | |
CFTimeInterval result = 0.1f; // フェードインする時間 | |
return result; | |
} |