Skip to content

Commit 1a38e7d

Browse files
committed
Convert to Swift 1.2
1 parent 9c7ac4f commit 1a38e7d

File tree

6 files changed

+90
-90
lines changed

6 files changed

+90
-90
lines changed

Source/Client.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public class Client {
6363
}
6464

6565
public let appID: String
66-
public let hostnames: [String]
6766

67+
private var hostnames: [String]
6868
private let manager: Manager
6969
private var requestBuffer = RingBuffer<Request>(maxCapacity: 10)
7070

@@ -78,9 +78,9 @@ public class Client {
7878
/// :param: tagFilters value of the header X-Algolia-TagFilters
7979
/// :param: userToken value of the header X-Algolia-UserToken
8080
public init(appID: String, apiKey: String, hostnames: [String]? = nil, dsn: Bool = false, dsnHost: String? = nil, tagFilters: String? = nil, userToken: String? = nil) {
81-
if countElements(appID) == 0 {
81+
if count(appID) == 0 {
8282
NSException(name: "InvalidArgument", reason: "Application ID must be set", userInfo: nil).raise()
83-
} else if countElements(apiKey) == 0 {
83+
} else if count(apiKey) == 0 {
8484
NSException(name: "InvalidArgument", reason: "APIKey must be set", userInfo: nil).raise()
8585
}
8686

@@ -108,7 +108,7 @@ public class Client {
108108
}
109109
}
110110

111-
let version = NSBundle(identifier: "com.algolia.AlgoliaSearch")!.infoDictionary!["CFBundleShortVersionString"] as String
111+
let version = NSBundle(identifier: "com.algolia.AlgoliaSearch")!.infoDictionary!["CFBundleShortVersionString"] as! String
112112
var HTTPHeaders = [
113113
"X-Algolia-API-Key": self.apiKey,
114114
"X-Algolia-Application-Id": self.appID,
@@ -336,8 +336,8 @@ public class Client {
336336
for query in queries {
337337
if let query = query as? [String: AnyObject] {
338338
convertedQueries.append([
339-
"params": (query["query"] as Query).buildURL(),
340-
"indexName": query["indexName"] as String
339+
"params": (query["query"] as! Query).buildURL(),
340+
"indexName": query["indexName"] as! String
341341
])
342342
}
343343
}
@@ -357,16 +357,16 @@ public class Client {
357357
if let block = block {
358358
switch(statusCode) {
359359
case 200, 201:
360-
block(JSON: (data as [String: AnyObject]), error: nil)
360+
block(JSON: (data as! [String: AnyObject]), error: nil)
361361
case 400:
362-
let errorMessage = data!["message"] as String
362+
let errorMessage = data!["message"] as! String
363363
block(JSON: nil, error: NSError(domain: "Bad request argument: \(errorMessage)", code: 400, userInfo: nil))
364364
case 403:
365365
block(JSON: nil, error: NSError(domain: "Invalid Application-ID or API-Key", code: 403, userInfo: nil))
366366
case 404:
367367
block(JSON: nil, error: NSError(domain: "Resource does not exist", code: 404, userInfo: nil))
368368
default:
369-
if let errorMessage = (data as [String: String])["message"] {
369+
if let errorMessage = (data as! [String: String])["message"] {
370370
block(JSON: nil, error: NSError(domain: errorMessage, code: 0, userInfo: nil))
371371
} else {
372372
block(JSON: nil, error: NSError(domain: "No error message", code: 0, userInfo: nil))
@@ -388,7 +388,7 @@ public class Client {
388388
/// Cancel a queries. Only the last ten queries can be cancelled.
389389
func cancelQueries(method: HTTPMethod, path: String) {
390390
for request in requestBuffer {
391-
if request.request.URL.path == path {
391+
if request.request.URL!.path! == path {
392392
if request.request.HTTPMethod == method.rawValue {
393393
request.cancel()
394394
}

Source/Index.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public class Index {
148148
if let object = object as? [String: AnyObject] {
149149
requests.append([
150150
"action": "partialUpdateObject",
151-
"objectID": object["objectID"] as String,
151+
"objectID": object["objectID"] as! String,
152152
"body": object
153153
])
154154
}
@@ -180,7 +180,7 @@ public class Index {
180180
if let object = object as? [String: AnyObject] {
181181
requests.append([
182182
"action": "updateObject",
183-
"objectID": object["objectID"] as String,
183+
"objectID": object["objectID"] as! String,
184184
"body": object
185185
])
186186
}

Source/Network.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Manager {
7272
return URLRequest
7373
}
7474

75-
var mutableURLRequest: NSMutableURLRequest! = URLRequest.mutableCopy() as NSMutableURLRequest
75+
var mutableURLRequest: NSMutableURLRequest! = URLRequest.mutableCopy() as! NSMutableURLRequest
7676
var error: NSError? = nil
7777

7878
if let data = NSJSONSerialization.dataWithJSONObject(parameters!, options: .allZeros, error: &error) {

Source/Query.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public class Query : Printable {
249249
var error: NSError?
250250
let data = NSJSONSerialization.dataWithJSONObject(facetFilters, options: .PrettyPrinted, error: &error)
251251
if error == nil {
252-
let json: String = NSString(data: data!, encoding: NSUTF8StringEncoding)!
252+
let json: String = NSString(data: data!, encoding: NSUTF8StringEncoding)! as String
253253
url.append(Query.encodeForQuery(json, withKey: "facetFilters"))
254254
} else {
255255
NSException(name: "InvalidArgument", reason: "Invalid facetFilters (should be an array of string)", userInfo: nil).raise()

0 commit comments

Comments
 (0)