Last active
November 23, 2016 08:50
-
-
Save MTattin/228e6e7239564e665b62452b72443d33 to your computer and use it in GitHub Desktop.
swift 3.0 のメモ ref: http://qiita.com/MTattin/items/5eef69c0530ba7bbe8ba
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
let _0_delay = 3.0 * Double(NSEC_PER_SEC) | |
let _0_time = DispatchTime.now() + Double(Int64(_0_delay)) / Double(NSEC_PER_SEC) | |
DispatchQueue.main.acyncAfter(deadline: _0_time, execute: { | |
}) | |
DispatchQueue.main.acyncAfter(deadline: DispatchTime.now() + Double(Int64(3.0 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: { | |
}) |
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
DispatchQueue.main.async(execute: { [weak self] in | |
guard let _0_weakSelf = self else { return } | |
}) |
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
#selector(Class.method(_:)) // before | |
#selector(Class.method(name:)) // after |
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
#selector(Class.method(_:)) // before | |
#selector(Class.method(name:)) // after |
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
let s: [String] = str.componentsSeparatedBy("=") // before | |
let s: [String] = str.components(separatedBy: "=") // after |
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
let s: [String] = str.componentsSeparatedBy("=") // before | |
let s: [String] = str.components(separatedBy: "=") // after |
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
/// before | |
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask { | |
return UIInterfaceOrientationMask.all | |
} | |
override func prefersStatusBarHidden() -> Bool { | |
return true | |
} | |
override func preferredStatusBarStyle:() -> UIStatusBarStyle { | |
return UIStatusBarStyle.lightContent | |
} | |
/// after | |
override var supportedInterfaceOrientations: UIInterfaceOrientationMask { | |
return UIInterfaceOrientationMask.all | |
} | |
override var prefersStatusBarHidden: Bool { | |
return true | |
} | |
override var preferredStatusBarStyle: UIStatusBarStyle { | |
return UIStatusBarStyle.lightContent | |
} |
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
let req: NSMutableURLRequest = NSMutableURLRequest(url: url) | |
let config: URLSessionConfiguration = URLSessionConfiguration.default() | |
/* setup post data */ | |
let data: NSMutableData = NSMutableData() | |
if let td: Dictionary = txtD { | |
for txtKey: String in td.keys { | |
if let txtVal: String = td[txtKey] { | |
data.append(NSString(format: "--%@\r\n", CommonSession._Boundary).data(using: String.Encoding.utf8.rawValue)!) | |
data.append(NSString(format: "Content-Disposition: form-data;").data(using: String.Encoding.utf8.rawValue)!) | |
data.append(NSString(format: "name=\"%@\"\r\n\r\n", txtKey).data(using: String.Encoding.utf8.rawValue)!) | |
data.append(NSString(format: "%@\r\n", txtVal).data(using: String.Encoding.utf8.rawValue)!) | |
} | |
} | |
} | |
/* add last boundary */ | |
let d: Data = NSString(format: "--%@--\r\n", CommonSession._Boundary).data(using: String.Encoding.utf8.rawValue)! | |
data.append(d) | |
/* setup post request */ | |
req.httpMethod = "POST" | |
req.httpBody = data as Data | |
let session: URLSession = URLSession(configuration: config, delegate: nil, delegateQueue: nil) | |
let task: URLSessionDataTask = session.dataTask(with: req as URLRequest, completionHandler: { [weak self] (data, response, error) in | |
do { | |
} catch let e as NSError { | |
} | |
}) |
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
func SampleFunc(n: NSNotification) { | |
guard | |
let name: String = n.name.rawValue where name == "通知の名前", | |
let info: [NSObject : AnyObject] = n.userInfo | |
else { | |
return | |
} | |
} |
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
NotificationCenter.default.post(name: Notification.Name(rawValue: "通知の名前"), object: nil) |
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
NotificationCenter.default.post(name: Notification.Name(rawValue: "通知の名前"), object: nil) |
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
if let u: String = "http://www.tes.com/あいうえお".addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) { | |
return u | |
} |
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
override func observeValue(forKeyPath keyPath: String?, of object: AnyObject?, change: [NSKeyValueChangeKey : AnyObject]?, context: UnsafeMutablePointer<Void>?) { | |
} |
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
override func observeValue(forKeyPath keyPath: String?, of object: AnyObject?, change: [NSKeyValueChangeKey : AnyObject]?, context: UnsafeMutablePointer<Void>?) { | |
} |
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
CGRect(x: 0, y: 0, width: 0, height: 0) | |
CGSize(width: 0, height: 0) |
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
CGRect(x: 0, y: 0, width: 0, height: 0) | |
CGSize(width: 0, height: 0) |
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 CGRect { | |
static func Make(_ x: CGFloat, _ y: CGFloat, _ w: CGFloat, _ h: CGFloat) -> CGRect { | |
return CGRect.init(x: x, y: y, width: w, height: h) | |
} | |
static var Zero: CGRect { | |
get { | |
return CGRect.init(x: 0, y: 0, width: 0, height: 0) | |
} | |
} | |
} | |
let a: CGRect = CGRect.Make(0, 0, 0, 0) | |
let b: CGRect = CGRect.Zero |
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 CGRect { | |
static func Make(_ x: CGFloat, _ y: CGFloat, _ w: CGFloat, _ h: CGFloat) -> CGRect { | |
return CGRect.init(x: x, y: y, width: w, height: h) | |
} | |
static var Zero: CGRect { | |
get { | |
return CGRect.init(x: 0, y: 0, width: 0, height: 0) | |
} | |
} | |
} | |
let a: CGRect = CGRect.Make(0, 0, 0, 0) | |
let b: CGRect = CGRect.Zero |
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
CGAffineTransform.identity | |
CGAffineTransform(scaleX: x, y: y) | |
CGAffineTransform(translationX: x, y: y) |
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
CGAffineTransform.identity | |
CGAffineTransform(scaleX: x, y: y) | |
CGAffineTransform(translationX: x, y: y) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment