@@ -28,21 +28,21 @@ class MainViewController: UIViewController {
2828
2929 installTextStub ( self . installTextStubSwitch)
3030 installImageStub ( self . installImageStubSwitch)
31- OHHTTPStubs . onStubActivation { ( request: NSURLRequest , stub: OHHTTPStubsDescriptor , response: OHHTTPStubsResponse ) in
32- print ( " [OHHTTPStubs] Request to \( request. URL !) has been stubbed with \( stub. name) " )
31+ OHHTTPStubs . onStubActivation { ( request: URLRequest , stub: OHHTTPStubsDescriptor , response: OHHTTPStubsResponse ) in
32+ print ( " [OHHTTPStubs] Request to \( request. url !) has been stubbed with \( stub. name) " )
3333 }
3434 }
3535
3636 ////////////////////////////////////////////////////////////////////////////////
3737 // MARK: - Global stubs activation
3838
39- @IBAction func toggleStubs( sender: UISwitch ) {
40- OHHTTPStubs . setEnabled ( sender. on )
41- self . delaySwitch. enabled = sender. on
42- self . installTextStubSwitch. enabled = sender. on
43- self . installImageStubSwitch. enabled = sender. on
39+ @IBAction func toggleStubs( _ sender: UISwitch ) {
40+ OHHTTPStubs . setEnabled ( sender. isOn )
41+ self . delaySwitch. isEnabled = sender. isOn
42+ self . installTextStubSwitch. isEnabled = sender. isOn
43+ self . installImageStubSwitch. isEnabled = sender. isOn
4444
45- let state = sender. on ? " and enabled " : " but disabled "
45+ let state = sender. isOn ? " and enabled " : " but disabled "
4646 print ( " Installed ( \( state) ) stubs: \( OHHTTPStubs . allStubs) " )
4747 }
4848
@@ -52,30 +52,30 @@ class MainViewController: UIViewController {
5252 // MARK: - Text Download and Stub
5353
5454
55- @IBAction func downloadText( sender: UIButton ) {
56- sender. enabled = false
55+ @IBAction func downloadText( _ sender: UIButton ) {
56+ sender. isEnabled = false
5757 self . textView. text = nil
5858
5959 let urlString = " http://www.opensource.apple.com/source/Git/Git-26/src/git-htmldocs/git-commit.txt?txt "
60- let req = NSURLRequest ( URL : NSURL ( string: urlString) !)
60+ let req = URLRequest ( url : URL ( string: urlString) !)
6161
62- NSURLConnection . sendAsynchronousRequest ( req, queue: NSOperationQueue . mainQueue ( ) ) { ( _, data, _) in
63- sender. enabled = true
64- if let receivedData = data, receivedText = NSString ( data: receivedData, encoding: NSASCIIStringEncoding ) {
62+ NSURLConnection . sendAsynchronousRequest ( req, queue: OperationQueue . main ) { ( _, data, _) in
63+ sender. isEnabled = true
64+ if let receivedData = data, let receivedText = NSString ( data: receivedData, encoding: String . Encoding . ascii . rawValue ) {
6565 self . textView. text = receivedText as String
6666 }
6767 }
6868 }
6969
7070 weak var textStub : OHHTTPStubsDescriptor ?
71- @IBAction func installTextStub( sender: UISwitch ) {
72- if sender. on {
71+ @IBAction func installTextStub( _ sender: UISwitch ) {
72+ if sender. isOn {
7373 // Install
7474
75- textStub = stub ( isExtension ( " txt " ) ) { _ in
76- let stubPath = OHPathForFile ( " stub.txt " , self . dynamicType )
77- return fixture ( stubPath!, headers: [ " Content-Type " : " text/plain " ] )
78- . requestTime ( self . delaySwitch. on ? 2.0 : 0.0 , responseTime: OHHTTPStubsDownloadSpeedWifi)
75+ textStub = stub ( condition : isExtension ( " txt " ) ) { _ in
76+ let stubPath = OHPathForFile ( " stub.txt " , type ( of : self ) )
77+ return fixture ( filePath : stubPath!, headers: [ " Content-Type " : " text/plain " ] )
78+ . requestTime ( self . delaySwitch. isOn ? 2.0 : 0.0 , responseTime: OHHTTPStubsDownloadSpeedWifi)
7979 }
8080 textStub? . name = " Text stub "
8181 } else {
@@ -88,30 +88,30 @@ class MainViewController: UIViewController {
8888 ////////////////////////////////////////////////////////////////////////////////
8989 // MARK: - Image Download and Stub
9090
91- @IBAction func downloadImage( sender: UIButton ) {
92- sender. enabled = false
91+ @IBAction func downloadImage( _ sender: UIButton ) {
92+ sender. isEnabled = false
9393 self . imageView. image = nil
9494
9595 let urlString = " http://images.apple.com/support/assets/images/products/iphone/hero_iphone4-5_wide.png "
96- let req = NSURLRequest ( URL : NSURL ( string: urlString) !)
96+ let req = URLRequest ( url : URL ( string: urlString) !)
9797
98- NSURLConnection . sendAsynchronousRequest ( req, queue: NSOperationQueue . mainQueue ( ) ) { ( _, data, _) in
99- sender. enabled = true
98+ NSURLConnection . sendAsynchronousRequest ( req, queue: OperationQueue . main ) { ( _, data, _) in
99+ sender. isEnabled = true
100100 if let receivedData = data {
101101 self . imageView. image = UIImage ( data: receivedData)
102102 }
103103 }
104104 }
105105
106106 weak var imageStub : OHHTTPStubsDescriptor ?
107- @IBAction func installImageStub( sender: UISwitch ) {
108- if sender. on {
107+ @IBAction func installImageStub( _ sender: UISwitch ) {
108+ if sender. isOn {
109109 // Install
110110
111- imageStub = stub ( isExtension ( " png " ) || isExtension ( " jpg " ) || isExtension ( " gif " ) ) { _ in
112- let stubPath = OHPathForFile ( " stub.jpg " , self . dynamicType )
113- return fixture ( stubPath!, headers: [ " Content-Type " : " image/jpeg " ] )
114- . requestTime ( self . delaySwitch. on ? 2.0 : 0.0 , responseTime: OHHTTPStubsDownloadSpeedWifi)
111+ imageStub = stub ( condition : isExtension ( " png " ) || isExtension ( " jpg " ) || isExtension ( " gif " ) ) { _ in
112+ let stubPath = OHPathForFile ( " stub.jpg " , type ( of : self ) )
113+ return fixture ( filePath : stubPath!, headers: [ " Content-Type " : " image/jpeg " ] )
114+ . requestTime ( self . delaySwitch. isOn ? 2.0 : 0.0 , responseTime: OHHTTPStubsDownloadSpeedWifi)
115115 }
116116 imageStub? . name = " Image stub "
117117 } else {
0 commit comments