소스 검색

Fixed all errors/warnings happening for swift-DEVELOPMENT-SNAPSHOT-2016-05-31-a-osx

Damian Kołakowski 10 년 전
부모
커밋
5bf31af941

+ 6 - 8
Sources/Swifter/File.swift

@@ -35,8 +35,7 @@ public class File {
     }
     
     public static func openFileForMode(_ path: String, _ mode: String) throws -> File {
-        let file = fopen(path.withCString({ $0 }), mode.withCString({ $0 }))
-        guard file != nil else {
+        guard let file = fopen(path.withCString({ $0 }), mode.withCString({ $0 })) else {
             throw FileError.OpenFailed(descriptionOfLastError())
         }
         return File(file)
@@ -51,8 +50,7 @@ public class File {
     }
     
     public static func currentWorkingDirectory() throws -> String {
-        let path = getcwd(nil, 0)
-        if path == nil {
+        guard let path = getcwd(nil, 0) else {
             throw FileError.GetCurrentWorkingDirectoryFailed(descriptionOfLastError())
         }
         return String(cString: path)
@@ -109,19 +107,19 @@ public class File {
 
 extension File {
     
-    public static func withNewFileOpenedForWriting<Result>(path: String, _ f: File throws -> Result) throws -> Result {
+    public static func withNewFileOpenedForWriting<Result>(path: String, _ f: (File) throws -> Result) throws -> Result {
         return try withFileOpenedForMode(path, mode: "wb", f)
     }
     
-    public static func withFileOpenedForReading<Result>(path: String, _ f: File throws -> Result) throws -> Result {
+    public static func withFileOpenedForReading<Result>(path: String, _ f: (File) throws -> Result) throws -> Result {
         return try withFileOpenedForMode(path, mode: "rb", f)
     }
     
-    public static func withFileOpenedForWritingAndReading<Result>(path: String, _ f: File throws -> Result) throws -> Result {
+    public static func withFileOpenedForWritingAndReading<Result>(path: String, _ f: (File) throws -> Result) throws -> Result {
         return try withFileOpenedForMode(path, mode: "r+b", f)
     }
     
-    public static func withFileOpenedForMode<Result>(_ path: String, mode: String, _ f: File throws -> Result) throws -> Result {
+    public static func withFileOpenedForMode<Result>(_ path: String, mode: String, _ f: (File) throws -> Result) throws -> Result {
         let file = try File.openFileForMode(path, mode)
         defer {
             file.close()

+ 1 - 1
Sources/Swifter/HttpHandlers+Files.swift

@@ -9,7 +9,7 @@ import Foundation
 
 extension HttpHandlers {
     
-    public class func shareFilesFromDirectory(_ directoryPath: String) -> (HttpRequest -> HttpResponse) {
+    public class func shareFilesFromDirectory(_ directoryPath: String) -> ((HttpRequest) -> HttpResponse) {
         return { r in
             guard let fileRelativePath = r.params.first else {
                 return .NotFound

+ 2 - 2
Sources/Swifter/HttpHandlers+WebSockets.swift

@@ -11,7 +11,7 @@ extension HttpHandlers {
     
     public class func websocket(
           _ text: ((WebSocketSession, String) -> Void)?,
-        _ binary: ((WebSocketSession, [UInt8]) -> Void)?) -> (HttpRequest -> HttpResponse) {
+        _ binary: ((WebSocketSession, [UInt8]) -> Void)?) -> ((HttpRequest) -> HttpResponse) {
         return { r in
             guard r.hasTokenForHeader("upgrade", token: "websocket") else {
                 return .BadRequest(.Text("Invalid value of 'Upgrade' header: \(r.headers["upgrade"])"))
@@ -22,7 +22,7 @@ extension HttpHandlers {
             guard let secWebSocketKey = r.headers["sec-websocket-key"] else {
                 return .BadRequest(.Text("Invalid value of 'Sec-Websocket-Key' header: \(r.headers["sec-websocket-key"])"))
             }
-            let protocolSessionClosure: (Socket -> Void) = { socket in
+            let protocolSessionClosure: ((Socket) -> Void) = { socket in
                 let session = WebSocketSession(socket)
                 while let frame = try? session.readFrame() {
                     switch frame.opcode {

+ 5 - 5
Sources/Swifter/HttpResponse.swift

@@ -25,7 +25,7 @@ public enum HttpResponseBody {
     case Data([UInt8])
     case Custom(Any, (Any) throws -> String)
     
-    func content() -> (Int, (HttpResponseBodyWriter throws -> Void)?) {
+    func content() -> (Int, ((HttpResponseBodyWriter) throws -> Void)?) {
         do {
             switch self {
             case .Json(let object):
@@ -77,12 +77,12 @@ public enum HttpResponseBody {
 
 public enum HttpResponse {
     
-    case SwitchProtocols([String: String], Socket -> Void)
+    case SwitchProtocols([String: String], (Socket) -> Void)
     case OK(HttpResponseBody), Created, Accepted
     case MovedPermanently(String)
     case BadRequest(HttpResponseBody?), Unauthorized, Forbidden, NotFound
     case InternalServerError
-    case RAW(Int, String, [String:String]?, (HttpResponseBodyWriter -> Void)? )
+    case RAW(Int, String, [String:String]?, ((HttpResponseBodyWriter) -> Void)? )
     
     func statusCode() -> Int {
         switch self {
@@ -144,7 +144,7 @@ public enum HttpResponse {
         return headers
     }
     
-    func content() -> (length: Int, write: (HttpResponseBodyWriter throws -> Void)?) {
+    func content() -> (length: Int, write: ((HttpResponseBodyWriter) throws -> Void)?) {
         switch self {
         case .OK(let body)             : return body.content()
         case .BadRequest(let body)     : return body?.content() ?? (-1, nil)
@@ -153,7 +153,7 @@ public enum HttpResponse {
         }
     }
     
-    func socketSession() -> (Socket -> Void)?  {
+    func socketSession() -> ((Socket) -> Void)?  {
         switch self {
         case SwitchProtocols(_, let handler) : return handler
         default: return nil

+ 4 - 4
Sources/Swifter/HttpRouter.swift

@@ -11,7 +11,7 @@ public class HttpRouter {
     
     private class Node {
         var nodes = [String: Node]()
-        var handler: (HttpRequest -> HttpResponse)? = nil
+        var handler: ((HttpRequest) -> HttpResponse)? = nil
     }
     
     private var rootNode = Node()
@@ -37,7 +37,7 @@ public class HttpRouter {
         return result
     }
     
-    public func register(_ method: String?, path: String, handler: (HttpRequest -> HttpResponse)?) {
+    public func register(_ method: String?, path: String, handler: ((HttpRequest) -> HttpResponse)?) {
         var pathSegments = stripQuery(path).split("/")
         if let method = method {
             pathSegments.insert(method, at: 0)
@@ -48,7 +48,7 @@ public class HttpRouter {
         inflate(&rootNode, generator: &pathSegmentsGenerator).handler = handler
     }
     
-    public func route(_ method: String?, path: String) -> ([String: String], HttpRequest -> HttpResponse)? {
+    public func route(_ method: String?, path: String) -> ([String: String], (HttpRequest) -> HttpResponse)? {
         if let method = method {
             let pathSegments = (method + "/" + stripQuery(path)).split("/")
             var pathSegmentsGenerator = pathSegments.makeIterator()
@@ -78,7 +78,7 @@ public class HttpRouter {
         return node
     }
     
-    private func findHandler(_ node: inout Node, params: inout [String: String], generator: inout IndexingIterator<[String]>) -> (HttpRequest -> HttpResponse)? {
+    private func findHandler(_ node: inout Node, params: inout [String: String], generator: inout IndexingIterator<[String]>) -> ((HttpRequest) -> HttpResponse)? {
         guard let pathToken = generator.next() else {
             return node.handler
         }

+ 10 - 10
Sources/Swifter/HttpServer.swift

@@ -24,31 +24,31 @@ public class HttpServer: HttpServerIO {
     
     public var DELETE, UPDATE, HEAD, POST, GET, PUT : MethodRoute
     
-    public func get(_ path: String, _ handler: (HttpRequest -> HttpResponse)) {
+    public func get(_ path: String, _ handler: ((HttpRequest) -> HttpResponse)) {
         router.register("GET", path: path, handler: handler)
     }
     
-    public func post(_ path: String, _ handler: (HttpRequest -> HttpResponse)) {
+    public func post(_ path: String, _ handler: ((HttpRequest) -> HttpResponse)) {
         router.register("POST", path: path, handler: handler)
     }
     
-    public func put(_ path: String, _ handler: (HttpRequest -> HttpResponse)) {
+    public func put(_ path: String, _ handler: ((HttpRequest) -> HttpResponse)) {
         router.register("PUT", path: path, handler: handler)
     }
     
-    public func head(_ path: String, _ handler: (HttpRequest -> HttpResponse)) {
+    public func head(_ path: String, _ handler: ((HttpRequest) -> HttpResponse)) {
         router.register("HEAD", path: path, handler: handler)
     }
     
-    public func delete(_ path: String, _ handler: (HttpRequest -> HttpResponse)) {
+    public func delete(_ path: String, _ handler: ((HttpRequest) -> HttpResponse)) {
         router.register("DELETE", path: path, handler: handler)
     }
     
-    public func update(_ path: String, _ handler: (HttpRequest -> HttpResponse)) {
+    public func update(_ path: String, _ handler: ((HttpRequest) -> HttpResponse)) {
         router.register("UPDATE", path: path, handler: handler)
     }
 
-    public subscript(path: String) -> (HttpRequest -> HttpResponse)? {
+    public subscript(path: String) -> ((HttpRequest) -> HttpResponse)? {
         set {
             router.register(nil, path: path, handler: newValue)
         }
@@ -59,9 +59,9 @@ public class HttpServer: HttpServerIO {
         return router.routes();
     }
     
-    public var notFoundHandler: (HttpRequest -> HttpResponse)?
+    public var notFoundHandler: ((HttpRequest) -> HttpResponse)?
 
-    override public func dispatch(_ method: String, path: String) -> ([String:String], HttpRequest -> HttpResponse) {
+    override public func dispatch(_ method: String, path: String) -> ([String:String], (HttpRequest) -> HttpResponse) {
         if let result = router.route(method, path: path) {
             return result
         }
@@ -74,7 +74,7 @@ public class HttpServer: HttpServerIO {
     public struct MethodRoute {
         public let method: String
         public let router: HttpRouter
-        public subscript(path: String) -> (HttpRequest -> HttpResponse)? {
+        public subscript(path: String) -> ((HttpRequest) -> HttpResponse)? {
             set {
                 router.register(method, path: path, handler: newValue)
             }

+ 2 - 2
Sources/Swifter/HttpServerIO.swift

@@ -13,7 +13,7 @@ public class HttpServerIO {
     private var clientSockets: Set<Socket> = []
     private let clientSocketsLock = NSLock()
     
-    public typealias MiddlewareCallback = HttpRequest -> HttpResponse?
+    public typealias MiddlewareCallback = (HttpRequest) -> HttpResponse?
     
     public var middleware = [MiddlewareCallback]()
     
@@ -47,7 +47,7 @@ public class HttpServerIO {
         }
     }
     
-    public func dispatch(_ method: String, path: String) -> ([String: String], HttpRequest -> HttpResponse) {
+    public func dispatch(_ method: String, path: String) -> ([String: String], (HttpRequest) -> HttpResponse) {
         return ([:], { _ in HttpResponse.NotFound })
     }
     

+ 1 - 1
Sources/Swifter/Process.swift

@@ -11,7 +11,7 @@ public class Process {
     
     public static var PID: Int { return Int(getpid()) }
     
-    public typealias SignalCallback = Int32 -> Void
+    public typealias SignalCallback = (Int32) -> Void
     
     private static var signalsWatchers = [SignalCallback]()
     private static var signalsObserved = false

+ 1 - 20
Sources/Swifter/Reflection.swift

@@ -25,18 +25,6 @@ public class DatabaseReflection: DatabaseReflectionProtocol {
 
 public extension DatabaseReflectionProtocol {
     
-    public func schemeWithValuesMethod1() -> (String, [String: Any?]) {
-        let reflections = _reflect(self)
-        
-        var fields = [String: Any?]()
-        for index in stride(from: 0, to: reflections.count, by: 1) {
-            let reflection = reflections[index]
-            fields[reflection.0] = reflection.1.value
-        }
-        
-        return (reflections.summary, fields)
-    }
-    
     public func schemeWithValuesMethod2() -> (String, [String: Any?]) {
         let mirror = Mirror(reflecting: self)
         
@@ -50,7 +38,6 @@ public extension DatabaseReflectionProtocol {
     
     public func schemeWithValuesAsString() -> (String, [(String, String?)]) {
         let (name, fields) = schemeWithValuesMethod2()
-        let (_, _) = schemeWithValuesMethod1()
         var map = [(String, String?)]()
         for (key, value) in fields {
             // TODO - Replace this by extending all supported types by a protocol.
@@ -72,12 +59,6 @@ public extension DatabaseReflectionProtocol {
         return (name, map)
     }
     
-    public static func classInstanceWithSchemeMethod1() -> (Self, String, [String: Any?]) {
-        let instance = Self()
-        let (name, fields) = instance.schemeWithValuesMethod1()
-        return (instance, name, fields)
-    }
-    
     public static func classInstanceWithSchemeMethod2() -> (Self, String, [String: Any?]) {
         let instance = Self()
         let (name, fields) = instance.schemeWithValuesMethod2()
@@ -85,7 +66,7 @@ public extension DatabaseReflectionProtocol {
     }
     
     static func find(id: UInt64) -> Self? {
-        let (instance, _, _) = classInstanceWithSchemeMethod1()
+        let (instance, _, _) = classInstanceWithSchemeMethod2()
         // TODO - make a query to DB
         return instance
     }

+ 7 - 9
Sources/Swifter/SQLite.swift

@@ -38,7 +38,7 @@ public class SQLite {
         try exec(sql, nil)
     }
     
-    public func exec(_ sql: String, _ params: [String?]? = nil, _ step: ([String: String?] -> Void)? = nil) throws {
+    public func exec(_ sql: String, _ params: [String?]? = nil, _ step: (([String: String?]) -> Void)? = nil) throws {
         var statementPointer: OpaquePointer? = nil
         let prepareResult = sql.withCString { sqlite3_prepare_v2(databaseConnection, $0, Int32(sql.utf8.count), &statementPointer, nil) }
         guard prepareResult == SQLITE_OK else {
@@ -61,11 +61,10 @@ public class SQLite {
                 var content = [String: String?]()
                 for i in 0..<sqlite3_column_count(statement) {
                     let name = String(cString: UnsafePointer<CChar>(sqlite3_column_name(statement, i)))
-                    let pointer = sqlite3_column_text(statement, i)
-                    if pointer == nil {
-                        content[name] = nil
-                    } else {
+                    if let pointer = sqlite3_column_text(statement, i) {
                         content[name] = String(cString: UnsafePointer<CChar>(pointer))
+                    } else {
+                        content[name] = nil
                     }
                 }
                 step?(content)
@@ -102,11 +101,10 @@ public class SQLite {
                 var content = [String: String]()
                 for i in 0..<sqlite3_column_count(statement) {
                     let name = String(cString: UnsafePointer<CChar>(sqlite3_column_name(statement, i)))
-                    let pointer = sqlite3_column_text(statement, i)
-                    if pointer == nil {
-                        content[name] = nil
-                    } else {
+                    if let pointer = sqlite3_column_text(statement, i) {
                         content[name] = String(cString: UnsafePointer<CChar>(pointer))
+                    } else {
+                        content[name] = nil
                     }
                 }
                 return content

+ 2 - 2
XCode/Swifter.xcodeproj/project.pbxproj

@@ -1092,7 +1092,7 @@
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				COPY_PHASE_STRIP = NO;
 				CURRENT_PROJECT_VERSION = 1.1.3;
-				EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
+				EMBEDDED_CONTENT_CONTAINS_SWIFT = NO;
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
 				ENABLE_TESTABILITY = YES;
 				GCC_C_LANGUAGE_STANDARD = gnu99;
@@ -1142,7 +1142,7 @@
 				"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
 				COPY_PHASE_STRIP = YES;
 				CURRENT_PROJECT_VERSION = 1.1.3;
-				EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
+				EMBEDDED_CONTENT_CONTAINS_SWIFT = NO;
 				ENABLE_NS_ASSERTIONS = NO;
 				ENABLE_STRICT_OBJC_MSGSEND = YES;
 				GCC_C_LANGUAGE_STANDARD = gnu99;

+ 1 - 1
XCode/SwifterTestsCommon/SwifterTestsReflection.swift

@@ -21,7 +21,7 @@ class SwifterTestsReflection: XCTestCase {
         let blogPostInstance = BlogPost()
         blogPostInstance.author = "Me"
 
-        let (_, fields) = blogPostInstance.schemeWithValuesMethod1()
+        let (_, fields) = blogPostInstance.schemeWithValuesMethod2()
         XCTAssertEqual((fields["author"] as? String)?.utf8.count, 2)
     }
 }