diff --git a/BridgingHeader.h b/BridgingHeader.h new file mode 100644 index 0000000..7374330 --- /dev/null +++ b/BridgingHeader.h @@ -0,0 +1,25 @@ +// GCDWebServer Core +#import "GCDWebServer.h" +#import "GCDWebServerConnection.h" +#import "GCDWebServerFunctions.h" +#import "GCDWebServerHTTPStatusCodes.h" +#import "GCDWebServerResponse.h" +#import "GCDWebServerRequest.h" + +// GCDWebServer Requests +#import "GCDWebServerDataRequest.h" +#import "GCDWebServerFileRequest.h" +#import "GCDWebServerMultiPartFormRequest.h" +#import "GCDWebServerURLEncodedFormRequest.h" + +// GCDWebServer Responses +#import "GCDWebServerDataResponse.h" +#import "GCDWebServerErrorResponse.h" +#import "GCDWebServerFileResponse.h" +#import "GCDWebServerStreamedResponse.h" + +// GCDWebUploader +#import "GCDWebUploader.h" + +// GCDWebDAVServer +#import "GCDWebDAVServer.h" diff --git a/GCDWebServer.xcodeproj/project.pbxproj b/GCDWebServer.xcodeproj/project.pbxproj index 8ea6079..0c9faa4 100644 --- a/GCDWebServer.xcodeproj/project.pbxproj +++ b/GCDWebServer.xcodeproj/project.pbxproj @@ -185,9 +185,8 @@ E2DDD1EF1BE69BC5002CE867 /* libxml2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = E2DDD1BB1BE69551002CE867 /* libxml2.tbd */; }; E2DDD1F01BE69BC5002CE867 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = E2DDD1B91BE69545002CE867 /* libz.tbd */; }; E2DDD1F11BE69BE9002CE867 /* GCDWebUploader.bundle in Resources */ = {isa = PBXBuildFile; fileRef = E2BE850718E77ECA0061360B /* GCDWebUploader.bundle */; }; - E2DDD1FA1BE69EE5002CE867 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E2DDD1F91BE69EE5002CE867 /* main.m */; }; - E2DDD1FD1BE69EE5002CE867 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E2DDD1FC1BE69EE5002CE867 /* AppDelegate.m */; }; - E2DDD2001BE69EE5002CE867 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E2DDD1FF1BE69EE5002CE867 /* ViewController.m */; }; + E2DDD1FD1BE69EE5002CE867 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2DDD1FC1BE69EE5002CE867 /* AppDelegate.swift */; }; + E2DDD2001BE69EE5002CE867 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2DDD1FF1BE69EE5002CE867 /* ViewController.swift */; }; E2DDD2031BE69EE5002CE867 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E2DDD2011BE69EE5002CE867 /* Main.storyboard */; }; E2DDD2051BE69EE5002CE867 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E2DDD2041BE69EE5002CE867 /* Assets.xcassets */; }; E2DDD2081BE69EE5002CE867 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E2DDD2061BE69EE5002CE867 /* LaunchScreen.storyboard */; }; @@ -207,7 +206,6 @@ E2DDD21C1BE69F17002CE867 /* GCDWebServerStreamedResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = E28BAE3318F99C810095C089 /* GCDWebServerStreamedResponse.m */; }; E2DDD21D1BE69F25002CE867 /* GCDWebDAVServer.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A0E80918F3432600C580B1 /* GCDWebDAVServer.m */; }; E2DDD21E1BE69F25002CE867 /* GCDWebUploader.m in Sources */ = {isa = PBXBuildFile; fileRef = E2BE850918E77ECA0061360B /* GCDWebUploader.m */; }; - E2DDD21F1BE6A061002CE867 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CEE28D691AE1ABAA00F4023C /* UIKit.framework */; }; E2DDD2201BE6A067002CE867 /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E221129C1690B7BA0048D2B2 /* MobileCoreServices.framework */; }; E2DDD2211BE6A06E002CE867 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E22112981690B7AA0048D2B2 /* CFNetwork.framework */; }; E2DDD2251BE6A0AE002CE867 /* libxml2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = E2DDD2241BE6A0AE002CE867 /* libxml2.tbd */; }; @@ -300,6 +298,7 @@ E221129C1690B7BA0048D2B2 /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/System/Library/Frameworks/MobileCoreServices.framework; sourceTree = DEVELOPER_DIR; }; E24039251BA09207000B7089 /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; E24039311BA092B7000B7089 /* Tests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Tests.m; sourceTree = ""; }; + E24A3BE021E2795700C58878 /* BridgingHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BridgingHeader.h; sourceTree = SOURCE_ROOT; }; E28BAE1618F99C810095C089 /* GCDWebServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServer.h; sourceTree = ""; }; E28BAE1718F99C810095C089 /* GCDWebServer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GCDWebServer.m; sourceTree = ""; }; E28BAE1818F99C810095C089 /* GCDWebServerConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GCDWebServerConnection.h; sourceTree = ""; }; @@ -350,11 +349,8 @@ E2DDD1D51BE698A8002CE867 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; E2DDD1D71BE698A8002CE867 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; E2DDD1F61BE69EE4002CE867 /* GCDWebServer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GCDWebServer.app; sourceTree = BUILT_PRODUCTS_DIR; }; - E2DDD1F91BE69EE5002CE867 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; - E2DDD1FB1BE69EE5002CE867 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; - E2DDD1FC1BE69EE5002CE867 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; - E2DDD1FE1BE69EE5002CE867 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; - E2DDD1FF1BE69EE5002CE867 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + E2DDD1FC1BE69EE5002CE867 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + E2DDD1FF1BE69EE5002CE867 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; E2DDD2021BE69EE5002CE867 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; E2DDD2041BE69EE5002CE867 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; E2DDD2071BE69EE5002CE867 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; @@ -439,7 +435,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - E2DDD21F1BE6A061002CE867 /* UIKit.framework in Frameworks */, E2DDD2201BE6A067002CE867 /* MobileCoreServices.framework in Frameworks */, E2DDD2211BE6A06E002CE867 /* CFNetwork.framework in Frameworks */, E2DDD2281BE6A0D8002CE867 /* libxml2.tbd in Frameworks */, @@ -453,6 +448,7 @@ 08FB7794FE84155DC02AAC07 /* LittleCMS */ = { isa = PBXGroup; children = ( + E24A3BE021E2795700C58878 /* BridgingHeader.h */, E28BAE1418F99C810095C089 /* GCDWebServer */, E2A0E80718F3432600C580B1 /* GCDWebDAVServer */, E2BE850618E77ECA0061360B /* GCDWebUploader */, @@ -635,15 +631,12 @@ E2DDD1F71BE69EE5002CE867 /* iOS */ = { isa = PBXGroup; children = ( - E2DDD1FB1BE69EE5002CE867 /* AppDelegate.h */, - E2DDD1FC1BE69EE5002CE867 /* AppDelegate.m */, - E2DDD1FE1BE69EE5002CE867 /* ViewController.h */, - E2DDD1FF1BE69EE5002CE867 /* ViewController.m */, + E2DDD1FC1BE69EE5002CE867 /* AppDelegate.swift */, + E2DDD1FF1BE69EE5002CE867 /* ViewController.swift */, E2DDD2011BE69EE5002CE867 /* Main.storyboard */, E2DDD2041BE69EE5002CE867 /* Assets.xcassets */, E2DDD2061BE69EE5002CE867 /* LaunchScreen.storyboard */, E2DDD2091BE69EE5002CE867 /* Info.plist */, - E2DDD1F91BE69EE5002CE867 /* main.m */, ); path = iOS; sourceTree = ""; @@ -1113,9 +1106,8 @@ E2DDD21C1BE69F17002CE867 /* GCDWebServerStreamedResponse.m in Sources */, E2DDD21D1BE69F25002CE867 /* GCDWebDAVServer.m in Sources */, E2DDD21E1BE69F25002CE867 /* GCDWebUploader.m in Sources */, - E2DDD2001BE69EE5002CE867 /* ViewController.m in Sources */, - E2DDD1FD1BE69EE5002CE867 /* AppDelegate.m in Sources */, - E2DDD1FA1BE69EE5002CE867 /* main.m in Sources */, + E2DDD2001BE69EE5002CE867 /* ViewController.swift in Sources */, + E2DDD1FD1BE69EE5002CE867 /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1218,6 +1210,10 @@ HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2"; ONLY_ACTIVE_ARCH = YES; PRODUCT_BUNDLE_IDENTIFIER = "net.pol-online.GCDWebServers"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OBJC_BRIDGING_HEADER = BridgingHeader.h; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.2; WARNING_CFLAGS = ( "-Wall", "-Weverything", @@ -1254,6 +1250,10 @@ GCC_TREAT_WARNINGS_AS_ERRORS = YES; HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2"; PRODUCT_BUNDLE_IDENTIFIER = "net.pol-online.GCDWebServers"; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OBJC_BRIDGING_HEADER = BridgingHeader.h; + SWIFT_TREAT_WARNINGS_AS_ERRORS = YES; + SWIFT_VERSION = 4.2; WARNING_CFLAGS = "-Wall"; }; name = Release; @@ -1430,6 +1430,7 @@ ENABLE_BITCODE = YES; INFOPLIST_FILE = iOS/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = GCDWebServer; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -1442,6 +1443,7 @@ ENABLE_BITCODE = YES; INFOPLIST_FILE = iOS/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = GCDWebServer; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/format-source.sh b/format-source.sh index 3c566d5..26920bd 100755 --- a/format-source.sh +++ b/format-source.sh @@ -1,4 +1,4 @@ -#!/bin/sh -ex +#!/bin/sh -exuo pipefail # brew install clang-format @@ -8,6 +8,15 @@ if [[ "$CLANG_FORMAT_VERSION" != "7.0.0" ]]; then exit 1 fi +if [[ ! -f "build/swiftformat" ]]; then + mkdir -p "build" + curl -sfL -o "build/SwiftFormat.zip" "https://github.com/nicklockwood/SwiftFormat/archive/0.37.2.zip" + unzip "build/SwiftFormat.zip" "SwiftFormat-0.37.2/CommandLineTool/swiftformat" -d "build" + mv "build/SwiftFormat-0.37.2/CommandLineTool/swiftformat" "build/swiftformat" +fi + +clang-format -style=file -i *.h + pushd "GCDWebServer/Core" clang-format -style=file -i *.h *.m popd @@ -30,11 +39,10 @@ popd pushd "Mac" clang-format -style=file -i *.m popd -pushd "iOS" -clang-format -style=file -i *.h *.m -popd pushd "tvOS" clang-format -style=file -i *.h *.m popd +build/swiftformat --indent 2 "iOS" + echo "OK" diff --git a/iOS/AppDelegate.h b/iOS/AppDelegate.h deleted file mode 100644 index 8b0876f..0000000 --- a/iOS/AppDelegate.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright (c) 2012-2015, Pierre-Olivier Latour - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * The name of Pierre-Olivier Latour may not be used to endorse - or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import - -@interface AppDelegate : UIResponder -@property(strong, nonatomic) UIWindow* window; -@end diff --git a/iOS/AppDelegate.m b/iOS/AppDelegate.m deleted file mode 100644 index bfd0518..0000000 --- a/iOS/AppDelegate.m +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright (c) 2012-2015, Pierre-Olivier Latour - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * The name of Pierre-Olivier Latour may not be used to endorse - or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import "AppDelegate.h" - -@implementation AppDelegate - -- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { - return YES; -} - -@end diff --git a/iOS/ViewController.h b/iOS/AppDelegate.swift similarity index 92% rename from iOS/ViewController.h rename to iOS/AppDelegate.swift index 5400bd5..ce76fa7 100644 --- a/iOS/ViewController.h +++ b/iOS/AppDelegate.swift @@ -1,7 +1,7 @@ /* Copyright (c) 2012-2015, Pierre-Olivier Latour All rights reserved. - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright @@ -12,7 +12,7 @@ * The name of Pierre-Olivier Latour may not be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -25,7 +25,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#import +import UIKit -@interface ViewController : UIViewController -@end +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + var window: UIWindow? +} diff --git a/iOS/Assets.xcassets/AppIcon.appiconset/Contents.json b/iOS/Assets.xcassets/AppIcon.appiconset/Contents.json index 1d060ed..d8db8d6 100644 --- a/iOS/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/iOS/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -84,6 +84,11 @@ "idiom" : "ipad", "size" : "83.5x83.5", "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : { diff --git a/iOS/Base.lproj/LaunchScreen.storyboard b/iOS/Base.lproj/LaunchScreen.storyboard index 8158318..4641a00 100644 --- a/iOS/Base.lproj/LaunchScreen.storyboard +++ b/iOS/Base.lproj/LaunchScreen.storyboard @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -10,14 +14,13 @@ - - + + - + - - + diff --git a/iOS/Base.lproj/Main.storyboard b/iOS/Base.lproj/Main.storyboard index ad3b119..5da1578 100644 --- a/iOS/Base.lproj/Main.storyboard +++ b/iOS/Base.lproj/Main.storyboard @@ -1,41 +1,49 @@ - - + + + + + - + + - + - - + + - + - - + - - + + + - + + diff --git a/iOS/ViewController.m b/iOS/ViewController.m deleted file mode 100644 index fbeae6b..0000000 --- a/iOS/ViewController.m +++ /dev/null @@ -1,77 +0,0 @@ -/* - Copyright (c) 2012-2015, Pierre-Olivier Latour - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * The name of Pierre-Olivier Latour may not be used to endorse - or promote products derived from this software without specific - prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - DISCLAIMED. IN NO EVENT SHALL PIERRE-OLIVIER LATOUR BE LIABLE FOR ANY - DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#import "ViewController.h" -#import "GCDWebUploader.h" - -@interface ViewController () -@property(weak, nonatomic) IBOutlet UILabel* label; -@end - -@implementation ViewController { -@private - GCDWebUploader* _webServer; -} - -- (void)viewWillAppear:(BOOL)animated { - [super viewWillAppear:animated]; - - NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; - _webServer = [[GCDWebUploader alloc] initWithUploadDirectory:documentsPath]; - _webServer.delegate = self; - _webServer.allowHiddenItems = YES; - if ([_webServer start]) { - _label.text = [NSString stringWithFormat:NSLocalizedString(@"GCDWebServer running locally on port %i", nil), (int)_webServer.port]; - } else { - _label.text = NSLocalizedString(@"GCDWebServer not running!", nil); - } -} - -- (void)viewDidDisappear:(BOOL)animated { - [super viewDidDisappear:animated]; - - [_webServer stop]; - _webServer = nil; -} - -- (void)webUploader:(GCDWebUploader*)uploader didUploadFileAtPath:(NSString*)path { - NSLog(@"[UPLOAD] %@", path); -} - -- (void)webUploader:(GCDWebUploader*)uploader didMoveItemFromPath:(NSString*)fromPath toPath:(NSString*)toPath { - NSLog(@"[MOVE] %@ -> %@", fromPath, toPath); -} - -- (void)webUploader:(GCDWebUploader*)uploader didDeleteItemAtPath:(NSString*)path { - NSLog(@"[DELETE] %@", path); -} - -- (void)webUploader:(GCDWebUploader*)uploader didCreateDirectoryAtPath:(NSString*)path { - NSLog(@"[CREATE] %@", path); -} - -@end diff --git a/iOS/main.m b/iOS/ViewController.swift similarity index 51% rename from iOS/main.m rename to iOS/ViewController.swift index bd96dd5..21b4c06 100644 --- a/iOS/main.m +++ b/iOS/ViewController.swift @@ -1,7 +1,7 @@ /* Copyright (c) 2012-2015, Pierre-Olivier Latour All rights reserved. - + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright @@ -12,7 +12,7 @@ * The name of Pierre-Olivier Latour may not be used to endorse or promote products derived from this software without specific prior written permission. - + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -25,10 +25,52 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#import "AppDelegate.h" +import UIKit -int main(int argc, char* argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); +class ViewController: UIViewController { + @IBOutlet var label: UILabel? + var webServer: GCDWebUploader! + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + + let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first! + webServer = GCDWebUploader(uploadDirectory: documentsPath) + webServer.delegate = self + webServer.allowHiddenItems = true + if webServer.start() { + label?.text = "GCDWebServer running locally on port \(webServer.port)" + } else { + label?.text = "GCDWebServer not running!" + } + } + + override func viewDidDisappear(_ animated: Bool) { + super.viewDidDisappear(animated) + + webServer.stop() + webServer = nil + } +} + +extension ViewController: GCDWebUploaderDelegate { + func webUploader(_: GCDWebUploader, didUploadFileAtPath path: String) { + print("[UPLOAD] \(path)") + } + + func webUploader(_: GCDWebUploader, didDownloadFileAtPath path: String) { + print("[DOWNLOAD] \(path)") + } + + func webUploader(_: GCDWebUploader, didMoveItemFromPath fromPath: String, toPath: String) { + print("[MOVE] \(fromPath) -> \(toPath)") + } + + func webUploader(_: GCDWebUploader, didCreateDirectoryAtPath path: String) { + print("[CREATE] \(path)") + } + + func webUploader(_: GCDWebUploader, didDeleteItemAtPath path: String) { + print("[DELETE] \(path)") } }