This repository has been archived by the owner on Sep 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5b178a
commit 14c09f7
Showing
10 changed files
with
686 additions
and
28 deletions.
There are no files selected for viewing
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
35 changes: 35 additions & 0 deletions
35
Examples/ExampleFramework/ExampleFramework/Networking.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Networking.swift | ||
// ExampleFramework | ||
// | ||
// Created by Kishikawa Katsumi on 2015/06/04. | ||
// Copyright (c) 2015 Realm. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public class Networking { | ||
let requesetURL: NSURL | ||
|
||
public init() { | ||
if let URL = NSURL(string: "http://www.google.com") { | ||
requesetURL = URL | ||
} else { | ||
fatalError("Unknown error occurred") | ||
} | ||
} | ||
|
||
public init(URL: NSURL) { | ||
requesetURL = URL | ||
} | ||
|
||
public func request(completion:(data: NSData?, response: NSURLResponse, error: NSError?) -> Void) -> Void { | ||
var session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration()) | ||
var request = NSMutableURLRequest(URL: requesetURL) | ||
|
||
session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in | ||
completion(data: data, response: response, error: error) | ||
}).resume() | ||
} | ||
|
||
} |
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
42 changes: 42 additions & 0 deletions
42
Examples/ExampleFramework/ExampleFrameworkTests/NetworkingTests.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// NetworkingTests.swift | ||
// ExampleFramework | ||
// | ||
// Created by kishikawakatsumi on 2015/06/04. | ||
// Copyright (c) 2015年 kishikawakatsumi. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
import ExampleFramework | ||
|
||
class NetworkingTests: XCTestCase { | ||
|
||
override func setUp() { | ||
super.setUp() | ||
} | ||
|
||
override func tearDown() { | ||
super.tearDown() | ||
} | ||
|
||
func testAsyncNetworking() { | ||
let expectation = expectationWithDescription("networking") | ||
|
||
let networking = Networking(URL: NSURL(string: "http://www.google.com")!) | ||
networking.request { (data, response, error) -> Void in | ||
if let response = response as? NSHTTPURLResponse { | ||
XCTAssertEqual(response.statusCode, 200) | ||
} else { | ||
XCTFail("Request failed") | ||
} | ||
expectation.fulfill() | ||
} | ||
|
||
waitForExpectationsWithTimeout(5.0, handler: { (error) -> Void in | ||
if let error = error { | ||
XCTFail("Connection timeout") | ||
} | ||
}) | ||
} | ||
|
||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
-: 0:Source:/Users/katsumi/Dropbox/Xcode Projects/SwiftCov/Examples/ExampleFramework/ExampleFramework/Networking.swift | ||
-: 0:Runs:1 | ||
-: 0:Programs:1 | ||
-: 1:// | ||
-: 2:// Networking.swift | ||
-: 3:// ExampleFramework | ||
-: 4:// | ||
-: 5:// Created by Kishikawa Katsumi on 2015/06/04. | ||
-: 6:// Copyright (c) 2015 Realm. All rights reserved. | ||
-: 7:// | ||
-: 8: | ||
-: 9:import Foundation | ||
-: 10: | ||
-: 11:public class Networking { | ||
-: 12: let requesetURL: NSURL | ||
-: 13: | ||
-: 14: public init() { | ||
#####: 15: if let URL = NSURL(string: "http://www.google.com") { | ||
#####: 16: requesetURL = URL | ||
#####: 17: } else { | ||
#####: 18: fatalError("Unknown error occurred") | ||
-: 19: } | ||
-: 20: } | ||
-: 21: | ||
-: 22: public init(URL: NSURL) { | ||
1: 23: requesetURL = URL | ||
-: 24: } | ||
-: 25: | ||
-: 26: public func request(completion:(data: NSData?, response: NSURLResponse, error: NSError?) -> Void) -> Void { | ||
1: 27: var session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration()) | ||
1: 28: var request = NSMutableURLRequest(URL: requesetURL) | ||
-: 29: | ||
2: 30: session.dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in | ||
1: 31: completion(data: data, response: response, error: error) | ||
2: 32: }).resume() | ||
-: 33: } | ||
-: 34: | ||
-: 35:} |
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
Oops, something went wrong.