Skip to content

Commit

Permalink
Convert to Swift 1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dethi committed Apr 9, 2015
1 parent 9c7ac4f commit 1a38e7d
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 90 deletions.
20 changes: 10 additions & 10 deletions Source/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public class Client {
}

public let appID: String
public let hostnames: [String]

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

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

Expand Down Expand Up @@ -108,7 +108,7 @@ public class Client {
}
}

let version = NSBundle(identifier: "com.algolia.AlgoliaSearch")!.infoDictionary!["CFBundleShortVersionString"] as String
let version = NSBundle(identifier: "com.algolia.AlgoliaSearch")!.infoDictionary!["CFBundleShortVersionString"] as! String
var HTTPHeaders = [
"X-Algolia-API-Key": self.apiKey,
"X-Algolia-Application-Id": self.appID,
Expand Down Expand Up @@ -336,8 +336,8 @@ public class Client {
for query in queries {
if let query = query as? [String: AnyObject] {
convertedQueries.append([
"params": (query["query"] as Query).buildURL(),
"indexName": query["indexName"] as String
"params": (query["query"] as! Query).buildURL(),
"indexName": query["indexName"] as! String
])
}
}
Expand All @@ -357,16 +357,16 @@ public class Client {
if let block = block {
switch(statusCode) {
case 200, 201:
block(JSON: (data as [String: AnyObject]), error: nil)
block(JSON: (data as! [String: AnyObject]), error: nil)
case 400:
let errorMessage = data!["message"] as String
let errorMessage = data!["message"] as! String
block(JSON: nil, error: NSError(domain: "Bad request argument: \(errorMessage)", code: 400, userInfo: nil))
case 403:
block(JSON: nil, error: NSError(domain: "Invalid Application-ID or API-Key", code: 403, userInfo: nil))
case 404:
block(JSON: nil, error: NSError(domain: "Resource does not exist", code: 404, userInfo: nil))
default:
if let errorMessage = (data as [String: String])["message"] {
if let errorMessage = (data as! [String: String])["message"] {
block(JSON: nil, error: NSError(domain: errorMessage, code: 0, userInfo: nil))
} else {
block(JSON: nil, error: NSError(domain: "No error message", code: 0, userInfo: nil))
Expand All @@ -388,7 +388,7 @@ public class Client {
/// Cancel a queries. Only the last ten queries can be cancelled.
func cancelQueries(method: HTTPMethod, path: String) {
for request in requestBuffer {
if request.request.URL.path == path {
if request.request.URL!.path! == path {
if request.request.HTTPMethod == method.rawValue {
request.cancel()
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Index.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public class Index {
if let object = object as? [String: AnyObject] {
requests.append([
"action": "partialUpdateObject",
"objectID": object["objectID"] as String,
"objectID": object["objectID"] as! String,
"body": object
])
}
Expand Down Expand Up @@ -180,7 +180,7 @@ public class Index {
if let object = object as? [String: AnyObject] {
requests.append([
"action": "updateObject",
"objectID": object["objectID"] as String,
"objectID": object["objectID"] as! String,
"body": object
])
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Network.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Manager {
return URLRequest
}

var mutableURLRequest: NSMutableURLRequest! = URLRequest.mutableCopy() as NSMutableURLRequest
var mutableURLRequest: NSMutableURLRequest! = URLRequest.mutableCopy() as! NSMutableURLRequest
var error: NSError? = nil

if let data = NSJSONSerialization.dataWithJSONObject(parameters!, options: .allZeros, error: &error) {
Expand Down
2 changes: 1 addition & 1 deletion Source/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public class Query : Printable {
var error: NSError?
let data = NSJSONSerialization.dataWithJSONObject(facetFilters, options: .PrettyPrinted, error: &error)
if error == nil {
let json: String = NSString(data: data!, encoding: NSUTF8StringEncoding)!
let json: String = NSString(data: data!, encoding: NSUTF8StringEncoding)! as String
url.append(Query.encodeForQuery(json, withKey: "facetFilters"))
} else {
NSException(name: "InvalidArgument", reason: "Invalid facetFilters (should be an array of string)", userInfo: nil).raise()
Expand Down
Loading

0 comments on commit 1a38e7d

Please sign in to comment.