├── .gitignore ├── AutoMCServer.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── AutoMCServer.xccheckout └── xcuserdata │ └── tristenmiller.xcuserdatad │ └── xcschemes │ ├── AutoMCServer.xcscheme │ └── xcschememanagement.plist ├── AutoMCServer ├── AppDelegate.swift ├── Base.lproj │ └── Main.storyboard ├── CompletedViewController.swift ├── Crafting Table.png ├── CreationViewController.swift ├── Data.swift ├── Images.xcassets │ └── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── Crafting-Table-icon-1-1.png │ │ ├── Crafting-Table-icon-1.png │ │ ├── Crafting-Table-icon-2-1.png │ │ ├── Crafting-Table-icon-2.png │ │ ├── Crafting-Table-icon-3 copy-1.png │ │ ├── Crafting-Table-icon-3 copy-2.png │ │ ├── Crafting-Table-icon-3 copy.png │ │ ├── Crafting-Table-icon-3-1.png │ │ ├── Crafting-Table-icon-3.png │ │ └── Crafting-Table-icon-4.png ├── Info.plist ├── MasterViewController.swift ├── OptionsViewController.swift ├── ServerOptions.swift ├── ServerProperties.swift ├── SwiftJSON.swift ├── TaskQueue.swift ├── donate_paypal.png └── server.properties ├── README.md └── SwiftHTTP-master ├── .gitignore ├── HTTPRequestSerializer.swift ├── HTTPResponseSerializer.swift ├── HTTPTask.swift ├── HTTPUpload.swift ├── Info.plist ├── LICENSE ├── README.md ├── SwiftHTTP.h ├── SwiftHTTP.podspec ├── SwiftHTTP.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ ├── SwiftHTTP.xcscheme │ └── SwiftHTTPOSX.xcscheme └── Tests ├── Info.plist └── SwiftHTTPTests.swift /.gitignore: -------------------------------------------------------------------------------- 1 | DerivedData 2 | */DerivedData 3 | AutoMCServerTests 4 | .DS_Store 5 | xcuserdata/ -------------------------------------------------------------------------------- /AutoMCServer.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 540181D51AA7E15200236F1B /* SwiftHTTP.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 540181D21AA7E12800236F1B /* SwiftHTTP.framework */; }; 11 | 5414CD8E1A92C4B100703B93 /* ServerProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5414CD8D1A92C4B100703B93 /* ServerProperties.swift */; }; 12 | 542296881A91AA24001EB0CB /* server.properties in Resources */ = {isa = PBXBuildFile; fileRef = 542296871A91AA24001EB0CB /* server.properties */; }; 13 | 543C4A341A8C0E5500C66E17 /* CreationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 543C4A331A8C0E5500C66E17 /* CreationViewController.swift */; }; 14 | 54424E111A901AD200F3E7FE /* TaskQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54424E101A901AD200F3E7FE /* TaskQueue.swift */; }; 15 | 5459A48A1A9154040036C1DE /* Crafting Table.png in Resources */ = {isa = PBXBuildFile; fileRef = 5459A4891A9154040036C1DE /* Crafting Table.png */; }; 16 | 5459A48C1A915BA60036C1DE /* donate_paypal.png in Resources */ = {isa = PBXBuildFile; fileRef = 5459A48B1A915BA60036C1DE /* donate_paypal.png */; }; 17 | 5459A48E1A9161D00036C1DE /* CompletedViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5459A48D1A9161D00036C1DE /* CompletedViewController.swift */; }; 18 | 5479A09E1A8AD863003514DB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5479A09D1A8AD863003514DB /* AppDelegate.swift */; }; 19 | 5479A0A01A8AD863003514DB /* OptionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5479A09F1A8AD863003514DB /* OptionsViewController.swift */; }; 20 | 5479A0A21A8AD863003514DB /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5479A0A11A8AD863003514DB /* Images.xcassets */; }; 21 | 5479A0A51A8AD863003514DB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5479A0A31A8AD863003514DB /* Main.storyboard */; }; 22 | 548FDDF41A9199EC0012D63B /* SwiftJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 548FDDF31A9199EC0012D63B /* SwiftJSON.swift */; }; 23 | 54A9B3A41A8C123E00859805 /* MasterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54A9B3A21A8C123E00859805 /* MasterViewController.swift */; }; 24 | 54A9B3A71A8C1E7B00859805 /* ServerOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54A9B3A61A8C1E7B00859805 /* ServerOptions.swift */; }; 25 | 54A9B3A91A8C2FDF00859805 /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54A9B3A81A8C2FDF00859805 /* Data.swift */; }; 26 | 54FE50E11AA84166007B67A8 /* SwiftHTTP.framework in Copy Files (1 item) */ = {isa = PBXBuildFile; fileRef = 540181D21AA7E12800236F1B /* SwiftHTTP.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 27 | /* End PBXBuildFile section */ 28 | 29 | /* Begin PBXContainerItemProxy section */ 30 | 540181CD1AA7E12800236F1B /* PBXContainerItemProxy */ = { 31 | isa = PBXContainerItemProxy; 32 | containerPortal = 540181C61AA7E12800236F1B /* SwiftHTTP.xcodeproj */; 33 | proxyType = 2; 34 | remoteGlobalIDString = 6BFD901619C8D8B500DD99B6; 35 | remoteInfo = SwiftHTTP; 36 | }; 37 | 540181CF1AA7E12800236F1B /* PBXContainerItemProxy */ = { 38 | isa = PBXContainerItemProxy; 39 | containerPortal = 540181C61AA7E12800236F1B /* SwiftHTTP.xcodeproj */; 40 | proxyType = 2; 41 | remoteGlobalIDString = 6BFD902119C8D8B500DD99B6; 42 | remoteInfo = SwiftHTTPTests; 43 | }; 44 | 540181D11AA7E12800236F1B /* PBXContainerItemProxy */ = { 45 | isa = PBXContainerItemProxy; 46 | containerPortal = 540181C61AA7E12800236F1B /* SwiftHTTP.xcodeproj */; 47 | proxyType = 2; 48 | remoteGlobalIDString = D958025919E6EEEB003C8218; 49 | remoteInfo = SwiftHTTPOSX; 50 | }; 51 | 540181D31AA7E12800236F1B /* PBXContainerItemProxy */ = { 52 | isa = PBXContainerItemProxy; 53 | containerPortal = 540181C61AA7E12800236F1B /* SwiftHTTP.xcodeproj */; 54 | proxyType = 2; 55 | remoteGlobalIDString = D958026319E6EEEB003C8218; 56 | remoteInfo = SwiftHTTPOSXTests; 57 | }; 58 | /* End PBXContainerItemProxy section */ 59 | 60 | /* Begin PBXCopyFilesBuildPhase section */ 61 | 540181D61AA7E19F00236F1B /* Copy Files (1 item) */ = { 62 | isa = PBXCopyFilesBuildPhase; 63 | buildActionMask = 2147483647; 64 | dstPath = ""; 65 | dstSubfolderSpec = 10; 66 | files = ( 67 | 54FE50E11AA84166007B67A8 /* SwiftHTTP.framework in Copy Files (1 item) */, 68 | ); 69 | name = "Copy Files (1 item)"; 70 | runOnlyForDeploymentPostprocessing = 0; 71 | }; 72 | /* End PBXCopyFilesBuildPhase section */ 73 | 74 | /* Begin PBXFileReference section */ 75 | 540181C61AA7E12800236F1B /* SwiftHTTP.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SwiftHTTP.xcodeproj; path = "SwiftHTTP-master/SwiftHTTP.xcodeproj"; sourceTree = ""; }; 76 | 5414CD8D1A92C4B100703B93 /* ServerProperties.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServerProperties.swift; sourceTree = ""; }; 77 | 542296871A91AA24001EB0CB /* server.properties */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = server.properties; sourceTree = ""; }; 78 | 543C4A331A8C0E5500C66E17 /* CreationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CreationViewController.swift; sourceTree = ""; }; 79 | 54424E101A901AD200F3E7FE /* TaskQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TaskQueue.swift; sourceTree = ""; }; 80 | 5459A4891A9154040036C1DE /* Crafting Table.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Crafting Table.png"; sourceTree = ""; }; 81 | 5459A48B1A915BA60036C1DE /* donate_paypal.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = donate_paypal.png; sourceTree = ""; }; 82 | 5459A48D1A9161D00036C1DE /* CompletedViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CompletedViewController.swift; sourceTree = ""; }; 83 | 5479A0981A8AD863003514DB /* AutoMCServer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AutoMCServer.app; sourceTree = BUILT_PRODUCTS_DIR; }; 84 | 5479A09C1A8AD863003514DB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 85 | 5479A09D1A8AD863003514DB /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 86 | 5479A09F1A8AD863003514DB /* OptionsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionsViewController.swift; sourceTree = ""; }; 87 | 5479A0A11A8AD863003514DB /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 88 | 5479A0A41A8AD863003514DB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 89 | 548FDDF31A9199EC0012D63B /* SwiftJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftJSON.swift; sourceTree = ""; }; 90 | 54A9B3A21A8C123E00859805 /* MasterViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MasterViewController.swift; sourceTree = ""; }; 91 | 54A9B3A61A8C1E7B00859805 /* ServerOptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ServerOptions.swift; sourceTree = ""; }; 92 | 54A9B3A81A8C2FDF00859805 /* Data.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Data.swift; sourceTree = ""; }; 93 | /* End PBXFileReference section */ 94 | 95 | /* Begin PBXFrameworksBuildPhase section */ 96 | 5479A0951A8AD863003514DB /* Frameworks */ = { 97 | isa = PBXFrameworksBuildPhase; 98 | buildActionMask = 2147483647; 99 | files = ( 100 | 540181D51AA7E15200236F1B /* SwiftHTTP.framework in Frameworks */, 101 | ); 102 | runOnlyForDeploymentPostprocessing = 0; 103 | }; 104 | /* End PBXFrameworksBuildPhase section */ 105 | 106 | /* Begin PBXGroup section */ 107 | 540181C71AA7E12800236F1B /* Products */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | 540181CE1AA7E12800236F1B /* SwiftHTTP.framework */, 111 | 540181D01AA7E12800236F1B /* SwiftHTTPTests.xctest */, 112 | 540181D21AA7E12800236F1B /* SwiftHTTP.framework */, 113 | 540181D41AA7E12800236F1B /* SwiftHTTPOSXTests.xctest */, 114 | ); 115 | name = Products; 116 | sourceTree = ""; 117 | }; 118 | 5479A08F1A8AD863003514DB = { 119 | isa = PBXGroup; 120 | children = ( 121 | 540181C61AA7E12800236F1B /* SwiftHTTP.xcodeproj */, 122 | 5479A09A1A8AD863003514DB /* AutoMCServer */, 123 | 5479A0991A8AD863003514DB /* Products */, 124 | ); 125 | sourceTree = ""; 126 | }; 127 | 5479A0991A8AD863003514DB /* Products */ = { 128 | isa = PBXGroup; 129 | children = ( 130 | 5479A0981A8AD863003514DB /* AutoMCServer.app */, 131 | ); 132 | name = Products; 133 | sourceTree = ""; 134 | }; 135 | 5479A09A1A8AD863003514DB /* AutoMCServer */ = { 136 | isa = PBXGroup; 137 | children = ( 138 | 5479A09D1A8AD863003514DB /* AppDelegate.swift */, 139 | 54A9B3A21A8C123E00859805 /* MasterViewController.swift */, 140 | 5479A09F1A8AD863003514DB /* OptionsViewController.swift */, 141 | 543C4A331A8C0E5500C66E17 /* CreationViewController.swift */, 142 | 5459A48D1A9161D00036C1DE /* CompletedViewController.swift */, 143 | 54424E101A901AD200F3E7FE /* TaskQueue.swift */, 144 | 548FDDF31A9199EC0012D63B /* SwiftJSON.swift */, 145 | 54A9B3A61A8C1E7B00859805 /* ServerOptions.swift */, 146 | 5414CD8D1A92C4B100703B93 /* ServerProperties.swift */, 147 | 54A9B3A81A8C2FDF00859805 /* Data.swift */, 148 | 5479A0A11A8AD863003514DB /* Images.xcassets */, 149 | 5459A4891A9154040036C1DE /* Crafting Table.png */, 150 | 5459A48B1A915BA60036C1DE /* donate_paypal.png */, 151 | 542296871A91AA24001EB0CB /* server.properties */, 152 | 5479A0A31A8AD863003514DB /* Main.storyboard */, 153 | 5479A09B1A8AD863003514DB /* Supporting Files */, 154 | ); 155 | path = AutoMCServer; 156 | sourceTree = ""; 157 | }; 158 | 5479A09B1A8AD863003514DB /* Supporting Files */ = { 159 | isa = PBXGroup; 160 | children = ( 161 | 5479A09C1A8AD863003514DB /* Info.plist */, 162 | ); 163 | name = "Supporting Files"; 164 | sourceTree = ""; 165 | }; 166 | /* End PBXGroup section */ 167 | 168 | /* Begin PBXNativeTarget section */ 169 | 5479A0971A8AD863003514DB /* AutoMCServer */ = { 170 | isa = PBXNativeTarget; 171 | buildConfigurationList = 5479A0B41A8AD863003514DB /* Build configuration list for PBXNativeTarget "AutoMCServer" */; 172 | buildPhases = ( 173 | 5479A0941A8AD863003514DB /* Sources */, 174 | 5479A0951A8AD863003514DB /* Frameworks */, 175 | 5479A0961A8AD863003514DB /* Resources */, 176 | 540181D61AA7E19F00236F1B /* Copy Files (1 item) */, 177 | ); 178 | buildRules = ( 179 | ); 180 | dependencies = ( 181 | ); 182 | name = AutoMCServer; 183 | productName = AutoMCServer; 184 | productReference = 5479A0981A8AD863003514DB /* AutoMCServer.app */; 185 | productType = "com.apple.product-type.application"; 186 | }; 187 | /* End PBXNativeTarget section */ 188 | 189 | /* Begin PBXProject section */ 190 | 5479A0901A8AD863003514DB /* Project object */ = { 191 | isa = PBXProject; 192 | attributes = { 193 | LastUpgradeCheck = 0610; 194 | ORGANIZATIONNAME = "Tristen Miller"; 195 | TargetAttributes = { 196 | 5479A0971A8AD863003514DB = { 197 | CreatedOnToolsVersion = 6.1.1; 198 | }; 199 | }; 200 | }; 201 | buildConfigurationList = 5479A0931A8AD863003514DB /* Build configuration list for PBXProject "AutoMCServer" */; 202 | compatibilityVersion = "Xcode 3.2"; 203 | developmentRegion = English; 204 | hasScannedForEncodings = 0; 205 | knownRegions = ( 206 | en, 207 | Base, 208 | ); 209 | mainGroup = 5479A08F1A8AD863003514DB; 210 | productRefGroup = 5479A0991A8AD863003514DB /* Products */; 211 | projectDirPath = ""; 212 | projectReferences = ( 213 | { 214 | ProductGroup = 540181C71AA7E12800236F1B /* Products */; 215 | ProjectRef = 540181C61AA7E12800236F1B /* SwiftHTTP.xcodeproj */; 216 | }, 217 | ); 218 | projectRoot = ""; 219 | targets = ( 220 | 5479A0971A8AD863003514DB /* AutoMCServer */, 221 | ); 222 | }; 223 | /* End PBXProject section */ 224 | 225 | /* Begin PBXReferenceProxy section */ 226 | 540181CE1AA7E12800236F1B /* SwiftHTTP.framework */ = { 227 | isa = PBXReferenceProxy; 228 | fileType = wrapper.framework; 229 | path = SwiftHTTP.framework; 230 | remoteRef = 540181CD1AA7E12800236F1B /* PBXContainerItemProxy */; 231 | sourceTree = BUILT_PRODUCTS_DIR; 232 | }; 233 | 540181D01AA7E12800236F1B /* SwiftHTTPTests.xctest */ = { 234 | isa = PBXReferenceProxy; 235 | fileType = wrapper.cfbundle; 236 | path = SwiftHTTPTests.xctest; 237 | remoteRef = 540181CF1AA7E12800236F1B /* PBXContainerItemProxy */; 238 | sourceTree = BUILT_PRODUCTS_DIR; 239 | }; 240 | 540181D21AA7E12800236F1B /* SwiftHTTP.framework */ = { 241 | isa = PBXReferenceProxy; 242 | fileType = wrapper.framework; 243 | path = SwiftHTTP.framework; 244 | remoteRef = 540181D11AA7E12800236F1B /* PBXContainerItemProxy */; 245 | sourceTree = BUILT_PRODUCTS_DIR; 246 | }; 247 | 540181D41AA7E12800236F1B /* SwiftHTTPOSXTests.xctest */ = { 248 | isa = PBXReferenceProxy; 249 | fileType = wrapper.cfbundle; 250 | path = SwiftHTTPOSXTests.xctest; 251 | remoteRef = 540181D31AA7E12800236F1B /* PBXContainerItemProxy */; 252 | sourceTree = BUILT_PRODUCTS_DIR; 253 | }; 254 | /* End PBXReferenceProxy section */ 255 | 256 | /* Begin PBXResourcesBuildPhase section */ 257 | 5479A0961A8AD863003514DB /* Resources */ = { 258 | isa = PBXResourcesBuildPhase; 259 | buildActionMask = 2147483647; 260 | files = ( 261 | 5479A0A21A8AD863003514DB /* Images.xcassets in Resources */, 262 | 5459A48C1A915BA60036C1DE /* donate_paypal.png in Resources */, 263 | 5479A0A51A8AD863003514DB /* Main.storyboard in Resources */, 264 | 542296881A91AA24001EB0CB /* server.properties in Resources */, 265 | 5459A48A1A9154040036C1DE /* Crafting Table.png in Resources */, 266 | ); 267 | runOnlyForDeploymentPostprocessing = 0; 268 | }; 269 | /* End PBXResourcesBuildPhase section */ 270 | 271 | /* Begin PBXSourcesBuildPhase section */ 272 | 5479A0941A8AD863003514DB /* Sources */ = { 273 | isa = PBXSourcesBuildPhase; 274 | buildActionMask = 2147483647; 275 | files = ( 276 | 54A9B3A41A8C123E00859805 /* MasterViewController.swift in Sources */, 277 | 54A9B3A91A8C2FDF00859805 /* Data.swift in Sources */, 278 | 543C4A341A8C0E5500C66E17 /* CreationViewController.swift in Sources */, 279 | 54424E111A901AD200F3E7FE /* TaskQueue.swift in Sources */, 280 | 548FDDF41A9199EC0012D63B /* SwiftJSON.swift in Sources */, 281 | 5479A0A01A8AD863003514DB /* OptionsViewController.swift in Sources */, 282 | 5479A09E1A8AD863003514DB /* AppDelegate.swift in Sources */, 283 | 5459A48E1A9161D00036C1DE /* CompletedViewController.swift in Sources */, 284 | 54A9B3A71A8C1E7B00859805 /* ServerOptions.swift in Sources */, 285 | 5414CD8E1A92C4B100703B93 /* ServerProperties.swift in Sources */, 286 | ); 287 | runOnlyForDeploymentPostprocessing = 0; 288 | }; 289 | /* End PBXSourcesBuildPhase section */ 290 | 291 | /* Begin PBXVariantGroup section */ 292 | 5479A0A31A8AD863003514DB /* Main.storyboard */ = { 293 | isa = PBXVariantGroup; 294 | children = ( 295 | 5479A0A41A8AD863003514DB /* Base */, 296 | ); 297 | name = Main.storyboard; 298 | sourceTree = ""; 299 | }; 300 | /* End PBXVariantGroup section */ 301 | 302 | /* Begin XCBuildConfiguration section */ 303 | 5479A0B31A8AD863003514DB /* Release */ = { 304 | isa = XCBuildConfiguration; 305 | buildSettings = { 306 | ALWAYS_SEARCH_USER_PATHS = NO; 307 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 308 | CLANG_CXX_LIBRARY = "libc++"; 309 | CLANG_ENABLE_MODULES = YES; 310 | CLANG_ENABLE_OBJC_ARC = YES; 311 | CLANG_WARN_BOOL_CONVERSION = YES; 312 | CLANG_WARN_CONSTANT_CONVERSION = YES; 313 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 314 | CLANG_WARN_EMPTY_BODY = YES; 315 | CLANG_WARN_ENUM_CONVERSION = YES; 316 | CLANG_WARN_INT_CONVERSION = YES; 317 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 318 | CLANG_WARN_UNREACHABLE_CODE = YES; 319 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 320 | CODE_SIGN_IDENTITY = "-"; 321 | COPY_PHASE_STRIP = YES; 322 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 323 | ENABLE_NS_ASSERTIONS = NO; 324 | ENABLE_STRICT_OBJC_MSGSEND = YES; 325 | FRAMEWORK_SEARCH_PATHS = "$(inherited)"; 326 | GCC_C_LANGUAGE_STANDARD = gnu99; 327 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 328 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 329 | GCC_WARN_UNDECLARED_SELECTOR = YES; 330 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 331 | GCC_WARN_UNUSED_FUNCTION = YES; 332 | GCC_WARN_UNUSED_VARIABLE = YES; 333 | MACOSX_DEPLOYMENT_TARGET = 10.10; 334 | MTL_ENABLE_DEBUG_INFO = NO; 335 | OTHER_LDFLAGS = "$(inherited)"; 336 | SDKROOT = macosx; 337 | SWIFT_INCLUDE_PATHS = "$(inherited)"; 338 | }; 339 | name = Release; 340 | }; 341 | 5479A0B61A8AD863003514DB /* Release */ = { 342 | isa = XCBuildConfiguration; 343 | buildSettings = { 344 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 345 | COMBINE_HIDPI_IMAGES = YES; 346 | INFOPLIST_FILE = AutoMCServer/Info.plist; 347 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 348 | PRODUCT_NAME = "$(TARGET_NAME)"; 349 | }; 350 | name = Release; 351 | }; 352 | /* End XCBuildConfiguration section */ 353 | 354 | /* Begin XCConfigurationList section */ 355 | 5479A0931A8AD863003514DB /* Build configuration list for PBXProject "AutoMCServer" */ = { 356 | isa = XCConfigurationList; 357 | buildConfigurations = ( 358 | 5479A0B31A8AD863003514DB /* Release */, 359 | ); 360 | defaultConfigurationIsVisible = 0; 361 | defaultConfigurationName = Release; 362 | }; 363 | 5479A0B41A8AD863003514DB /* Build configuration list for PBXNativeTarget "AutoMCServer" */ = { 364 | isa = XCConfigurationList; 365 | buildConfigurations = ( 366 | 5479A0B61A8AD863003514DB /* Release */, 367 | ); 368 | defaultConfigurationIsVisible = 0; 369 | defaultConfigurationName = Release; 370 | }; 371 | /* End XCConfigurationList section */ 372 | }; 373 | rootObject = 5479A0901A8AD863003514DB /* Project object */; 374 | } 375 | -------------------------------------------------------------------------------- /AutoMCServer.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AutoMCServer.xcodeproj/project.xcworkspace/xcshareddata/AutoMCServer.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | F980147B-7285-4892-B891-7EEA8BC84F0A 9 | IDESourceControlProjectName 10 | AutoMCServer 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | F3030AFDE129246BFF83AA1841B89254D63AE1A2 14 | https://github.com/hawkfalcon/AutoMCServer.git 15 | 16 | IDESourceControlProjectPath 17 | AutoMCServer.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | F3030AFDE129246BFF83AA1841B89254D63AE1A2 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/hawkfalcon/AutoMCServer.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | F3030AFDE129246BFF83AA1841B89254D63AE1A2 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | F3030AFDE129246BFF83AA1841B89254D63AE1A2 36 | IDESourceControlWCCName 37 | AutoMCServer 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /AutoMCServer.xcodeproj/xcuserdata/tristenmiller.xcuserdatad/xcschemes/AutoMCServer.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 94 | 100 | 101 | 102 | 103 | 105 | 106 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /AutoMCServer.xcodeproj/xcuserdata/tristenmiller.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | AutoMCServer.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 5479A0971A8AD863003514DB 16 | 17 | primary 18 | 19 | 20 | 5479A0A91A8AD863003514DB 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /AutoMCServer/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | 3 | @NSApplicationMain 4 | class AppDelegate: NSObject, NSApplicationDelegate { 5 | 6 | func applicationDidFinishLaunching(aNotification: NSNotification) { 7 | } 8 | 9 | func applicationWillTerminate(aNotification: NSNotification) { 10 | 11 | } 12 | 13 | func applicationShouldTerminateAfterLastWindowClosed(sender: NSApplication) -> Bool { 14 | return true 15 | } 16 | 17 | @IBAction func help(sender: AnyObject) { 18 | var help = NSURL(string: "https://hawkfalcon.com") 19 | NSWorkspace.sharedWorkspace().openURL(help!) 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /AutoMCServer/CompletedViewController.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | 3 | class CompletedViewController: NSViewController { 4 | var options: ServerOptions! 5 | @IBOutlet var ip: NSTextField! 6 | 7 | override func viewDidLoad() { 8 | super.viewDidLoad() 9 | options = Data.options 10 | getIP() 11 | } 12 | 13 | func getIP() { 14 | let url = NSURL(string: "http://icanhazip.com") 15 | 16 | let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in 17 | let ip = NSString(data: data, encoding: NSUTF8StringEncoding)! 18 | self.ip.stringValue = ip 19 | let paste = NSPasteboard.generalPasteboard() 20 | paste.clearContents() 21 | paste.setString(ip, forType: NSPasteboardTypeString) 22 | } 23 | task.resume() 24 | } 25 | @IBAction func quitapp(sender: AnyObject) { 26 | NSApplication.sharedApplication().stop(self) 27 | } 28 | 29 | @IBAction func portforward(sender: AnyObject) { 30 | let help = NSURL(string: "http://portforward.com/english/applications/port_forwarding/Minecraft_Server/") 31 | NSWorkspace.sharedWorkspace().openURL(help!) 32 | } 33 | 34 | @IBAction func editprop(sender: AnyObject) { 35 | let help = options.path.stringByAppendingPathComponent("minecraft/server.properties") 36 | NSWorkspace.sharedWorkspace().openFile(help) 37 | } 38 | 39 | @IBAction func openfolder(sender: AnyObject) { 40 | let help = options.path.stringByAppendingPathComponent("minecraft/") 41 | NSWorkspace.sharedWorkspace().openFile(help) 42 | } 43 | @IBAction func donatepls(sender: AnyObject) { 44 | let help = NSURL(string: "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=MVENJVD6Y6EXJ&lc=US&item_name=hawkfalcon&item_number=hawkfalcon¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHosted") 45 | NSWorkspace.sharedWorkspace().openURL(help!) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /AutoMCServer/Crafting Table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hawkfalcon/AutoMCServer/cf30912ccbd85293c3b81043de1e4c353b489d11/AutoMCServer/Crafting Table.png -------------------------------------------------------------------------------- /AutoMCServer/CreationViewController.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | import SwiftHTTP 3 | 4 | class CreationViewController: NSViewController { 5 | 6 | var notificationCenter = NSNotificationCenter.defaultCenter() 7 | 8 | var fileManager = NSFileManager.defaultManager() 9 | 10 | var total = 0.0 11 | 12 | var options:ServerOptions! 13 | var properties:ServerProperties! 14 | var path:NSString! 15 | let spigot = "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar" 16 | let latestjson = NSURL(string: "https://s3.amazonaws.com/Minecraft.Download/versions/versions.json") 17 | 18 | @IBOutlet var progresstext: NSTextField! 19 | @IBOutlet var subtext: NSTextField! 20 | @IBOutlet var percent: NSTextField! 21 | @IBOutlet var progress: NSProgressIndicator! 22 | 23 | @IBOutlet var ram: NSTextField! 24 | @IBOutlet var servertype: NSTextField! 25 | @IBOutlet var username: NSTextField! 26 | @IBOutlet var output: NSTextView! 27 | @IBOutlet var spin: NSProgressIndicator! 28 | 29 | override func viewDidLoad() { 30 | super.viewDidLoad() 31 | options = Data.options 32 | properties = Data.properties 33 | path = options.path.stringByAppendingPathComponent("minecraft") 34 | notificationCenter.addObserver(self, selector: "receivedOut:", name: NSFileHandleDataAvailableNotification, object: nil) 35 | setupGUI() 36 | } 37 | 38 | func setupGUI() { 39 | username.stringValue = "OP: \(options.username)" 40 | ram.stringValue = "RAM: \(options.ram)\(options.bytesize)" 41 | servertype.stringValue = "Creating \(options.servertype.rawValue) Server" 42 | spin.startAnimation(1) 43 | } 44 | 45 | override func viewDidAppear() { 46 | startCreation() 47 | } 48 | 49 | func startCreation() { 50 | if (!self.fileManager.fileExistsAtPath(self.path)) { 51 | self.updateGui(0.0, label: "Creating folder") 52 | updateSub(" ") 53 | self.fileManager.createDirectoryAtPath(self.path, withIntermediateDirectories: false, attributes: nil, error: nil) 54 | } 55 | if (options.servertype == ServerType.Vanilla) { 56 | queueVanilla() 57 | } else { 58 | queueBuildTools() 59 | } 60 | } 61 | 62 | func queueBuildTools() { 63 | let queue = TaskQueue() 64 | queue.tasks +=! { 65 | self.output.append("Starting download of BuildTools...") 66 | self.updateGui(0.00, label: "Starting download of BuildTools...") 67 | } 68 | 69 | queue.tasks +=~ { result, next in 70 | let fileUrl = NSURL(fileURLWithPath: self.path + "/BuildTools.jar") 71 | self.downloadFile(self.spigot, toPath: fileUrl!) {(_) in 72 | next(nil) 73 | } 74 | } 75 | 76 | queue.tasks +=! { 77 | self.output.append("Downloaded BuildTools.jar") 78 | self.updateGui(1.0, label: "Downloaded BuildTools") 79 | self.output.append("Running BuildTools...") 80 | } 81 | 82 | queue.tasks +=! { result, next in 83 | let task = NSTask() 84 | task.launchPath = "/usr/bin/java" 85 | task.currentDirectoryPath = self.path 86 | task.arguments = ["-jar", "BuildTools.jar"] 87 | 88 | let pipe = NSPipe() 89 | task.standardOutput = pipe 90 | let data = pipe.fileHandleForReading 91 | data.waitForDataInBackgroundAndNotify() 92 | task.launch() 93 | task.terminationHandler = {task -> Void in 94 | next(nil) 95 | } 96 | } 97 | 98 | queue.tasks +=! { 99 | self.cleanFolder() 100 | } 101 | 102 | queue.run { 103 | self.finishCreation() 104 | } 105 | } 106 | 107 | func queueVanilla() { 108 | let queue = TaskQueue() 109 | queue.tasks +=! { 110 | self.output.append("Starting download of minecraft_server.jar...") 111 | self.updateGui(0.25, label: "Starting download of minecraft_server.jar...") 112 | } 113 | 114 | queue.tasks +=~ { result, next in 115 | self.updateGui(0.5, label: "Getting latest minecraft version...") 116 | let dataFromNetworking = NSData(contentsOfURL: self.latestjson!) 117 | let json = JSON(data: dataFromNetworking!) 118 | let version = json["latest"]["release"] 119 | let vanilla = "https://s3.amazonaws.com/Minecraft.Download/versions/\(version)/minecraft_server.\(version).jar" 120 | let fileUrl = NSURL(fileURLWithPath: self.path + "/minecraft_server.jar") 121 | self.updateGui(0.0, label: "Downloading Minecraft Jar...") 122 | self.downloadFile(vanilla, toPath: fileUrl!) {(_) in 123 | next(nil) 124 | } 125 | } 126 | 127 | queue.tasks +=! { 128 | self.output.append("Downloaded minecraft_server.jar") 129 | self.updateGui(0.0, label: "Downloaded minecraft_server.jar") 130 | } 131 | 132 | queue.run { 133 | self.finishCreation() 134 | } 135 | } 136 | 137 | func receivedOut(notif : NSNotification) { 138 | let fh:NSFileHandle = notif.object as NSFileHandle 139 | let data = fh.availableData 140 | if data.length > 0 { 141 | let dstring = NSString(data: data, encoding: NSUTF8StringEncoding)! 142 | self.parseOutput(dstring) 143 | fh.waitForDataInBackgroundAndNotify() 144 | } 145 | } 146 | 147 | var perc = 0.00 148 | func parseOutput(line: String) { 149 | perc += 1/5800 150 | output.append(line) 151 | self.updateGui(perc, label: nil) 152 | let trimmed = line.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()) 153 | let check = ["Starting clone": "Downloading files", "Maven does not exist":"Downloading Maven", "Pulling updates":"Getting updates","https://s3.amazonaws.com/Minecraft.Download/":"Downloading Minecraft Jar", "Final mapped jar":"Preparing Minecraft Jar","Remapping final jar":"Modifying Minecraft Jar","Decompiling class net/minecraft/server/WorldType":"Decompiling", "Applying CraftBukkit Patches":"Creating CraftBukkit","Compiling Bukkit":"Compiling Bukkit","Compiling CraftBukkit":"Compiling CraftBukkit","Applying patches to Spigot-API":"Applying Spigot changes","Building Spigot-API":"Building Spigot-API","Building Spigot ":"Building Spigot","Success! Everything compiled successfully.":"Success! Everything compiled successfully."] 154 | for (find, print) in check { 155 | if (trimmed.rangeOfString(find) != nil) { 156 | perc += 0.014 157 | updateGui(perc, label: "\(print)...") 158 | updateSub(" ") 159 | } 160 | } 161 | let subs = ["Starting clone of":" ","Extracted: work/decompile-":"/","Decompiling class":"/", "Applying:":"Applying: ","Patching with":" ", "Running":".","BUILD SUCCESS":" ", "Building jar":"/", "Starting download":"/"] 162 | for (needle, split) in subs { 163 | setSubFor(trimmed, needle: needle, split: split) 164 | } 165 | } 166 | 167 | func setSubFor(line: String, needle: String, split: String) { 168 | if (line.rangeOfString(needle) != nil) { 169 | updateSub(line.componentsSeparatedByString(split).last!) 170 | } 171 | } 172 | 173 | func downloadFile(fromUrl: NSString, toPath: NSURL, done: () -> ()) { 174 | var request = HTTPTask() 175 | let server = options.servertype.rawValue 176 | let downloadTask = request.download(fromUrl, parameters: nil, progress: {(complete: Double) in 177 | self.updateGuiFast(complete) 178 | }, success: {(response: HTTPResponse) in 179 | if response.responseObject != nil { 180 | //we MUST copy the file from its temp location to a permanent location. 181 | if let url = response.responseObject as? NSURL { 182 | if let path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first as? String { 183 | if let fileName = response.suggestedFilename { 184 | if let newPath = NSURL(fileURLWithPath: "\(path)/\(fileName)") { 185 | let fileManager = NSFileManager.defaultManager() 186 | fileManager.removeItemAtURL(toPath, error: nil) 187 | fileManager.moveItemAtURL(url, toURL: toPath, error:nil) 188 | done() 189 | } 190 | } 191 | } 192 | } 193 | } 194 | }, failure: {(error: NSError, response: HTTPResponse?) in 195 | println("failure") 196 | }) 197 | } 198 | 199 | func updateGui(amount: Double, label: String?) { 200 | let amountp = Int(amount * 100) 201 | self.percent.stringValue = "\(amountp)%" 202 | self.progress.doubleValue = amount 203 | if label != nil { 204 | self.progresstext.stringValue = label! 205 | } 206 | } 207 | 208 | func updateSub(sub: String) { 209 | self.subtext.stringValue = sub.truncate(60) 210 | } 211 | 212 | func updateGuiFast(amount: Double) { 213 | self.percent.stringValue = "\(Int(amount*100))%" 214 | self.progress.doubleValue = amount 215 | } 216 | 217 | func cleanFolder() { 218 | var removeList = ["CraftBukkit", "Bukkit", "Spigot", "BuildData", "BuildTools.jar", "work", "BuildTools.log.txt"] 219 | removeList.append(getFullName("apache-maven")) 220 | for remove in removeList { 221 | removeFromFolder(remove) 222 | output.append("Cleaning \(remove)...") 223 | } 224 | output.append("DONE CREATING SERVER JAR") 225 | } 226 | 227 | func finishCreation() { 228 | createFiles() 229 | self.performSegueWithIdentifier("final", sender: self) 230 | } 231 | 232 | func createFiles() { 233 | self.updateGui(0.8, label: "Creating files") 234 | var serverjar = getFullName("spigot") 235 | if options.servertype == ServerType.Bukkit { 236 | serverjar = getFullName("craftbukkit") 237 | } else if options.servertype == ServerType.Vanilla { 238 | serverjar = getFullName("minecraft_server") 239 | } 240 | var size = options.bytesize 241 | let sh = "#!/bin/sh\n\ncd \"$( dirname \"$0\" )\"\njava -Xms\(options.ram)\(size) -Xmx\(options.ram)\(size) -jar \(serverjar) nogui -o true" 242 | let start = path.stringByAppendingPathComponent("start.sh") 243 | createFile(start, contents: sh) 244 | createFile(path.stringByAppendingPathComponent("eula.txt"), contents: "eula=true") 245 | createFile(path.stringByAppendingPathComponent("ops.txt"), contents: options.username) 246 | self.updateGui(0.9, label: "Creating properties") 247 | createProperties() 248 | self.updateGui(1.0, label: "Launching server") 249 | let attributes = [NSFilePosixPermissions : NSNumber(short: 0x755.shortValue)] 250 | fileManager.setAttributes(attributes, ofItemAtPath: start, error: nil) 251 | NSWorkspace.sharedWorkspace().openFile(start, withApplication: "terminal") 252 | } 253 | 254 | func createProperties() { 255 | let prop = NSBundle.mainBundle().pathForResource("server", ofType: "properties") 256 | var content = String(contentsOfFile:prop!, encoding: NSUTF8StringEncoding, error: nil) 257 | content = content?.replace("mobs", withString: properties.mobs.toString()) 258 | content = content?.replace("nether", withString: properties.nether.toString()) 259 | content = content?.replace("leveltype", withString: properties.leveltype.rawValue) 260 | content = content?.replace("whitelist", withString: properties.whitelist.toString()) 261 | content = content?.replace("pvp", withString: properties.pvp.toString()) 262 | content = content?.replace("difficulty", withString: String(properties.difficulty.rawValue)) 263 | content = content?.replace("gamemode", withString: String(properties.gamemode.rawValue)) 264 | content = content?.replace("maxplayers", withString: String(properties.maxplayers)) 265 | content = content?.replace("motd", withString: properties.motd) 266 | createFile(path.stringByAppendingPathComponent("server.properties"), contents: content!) 267 | } 268 | 269 | func createFile(fpath: String, contents: String) { 270 | fileManager.createFileAtPath(fpath, contents: contents.dataUsingEncoding(NSUTF8StringEncoding), attributes: nil) 271 | } 272 | 273 | func removeFromFolder(file: String) { 274 | let toRemove = path.stringByAppendingPathComponent(file) 275 | if fileManager.fileExistsAtPath(toRemove) { 276 | fileManager.removeItemAtPath(toRemove, error: nil) 277 | } 278 | } 279 | 280 | func getFullName(partial: String) -> String { 281 | var longestCompletion = "" 282 | var match = path.stringByAppendingPathComponent(partial).completePathIntoString(&longestCompletion, caseSensitive: false) 283 | return longestCompletion.lastPathComponent 284 | } 285 | } 286 | 287 | extension String { 288 | func truncate(length: Int) -> String { 289 | if countElements(self) > length { 290 | return self.substringToIndex(advance(self.startIndex, length)) 291 | } else { 292 | return self 293 | } 294 | } 295 | } 296 | 297 | extension NSTextView { 298 | func append(string: String) { 299 | dispatch_async(dispatch_get_main_queue(), { 300 | self.textStorage?.appendAttributedString(NSAttributedString(string: "\(string) \n")) 301 | self.scrollToEndOfDocument(nil) 302 | }) 303 | } 304 | } 305 | 306 | extension String { 307 | func replace(target: String, withString: String) -> String { 308 | return self.stringByReplacingOccurrencesOfString("{\(target)}", withString: withString, options: NSStringCompareOptions.LiteralSearch, range: nil) 309 | } 310 | } 311 | 312 | extension Bool { 313 | func toString() -> String { 314 | return self.boolValue ? "true" : "false" 315 | } 316 | } -------------------------------------------------------------------------------- /AutoMCServer/Data.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Data.swift 3 | // AutoMCServer 4 | // 5 | // Created by Tristen Miller on 2/11/15. 6 | // Copyright (c) 2015 Tristen Miller. All rights reserved. 7 | // 8 | 9 | class Data { 10 | private struct OptionsStruct { static var serveroptions: ServerOptions! } 11 | private struct PropertiesStruct { static var properties: ServerProperties! } 12 | 13 | class var options: ServerOptions { 14 | get { return OptionsStruct.serveroptions } 15 | set { OptionsStruct.serveroptions = newValue } 16 | } 17 | 18 | class var properties: ServerProperties { 19 | get { return PropertiesStruct.properties } 20 | set { PropertiesStruct.properties = newValue } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /AutoMCServer/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "Crafting-Table-icon-2-1.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "Crafting-Table-icon-1.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "Crafting-Table-icon-1-1.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "Crafting-Table-icon-4.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "Crafting-Table-icon-2.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "Crafting-Table-icon-3 copy.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "Crafting-Table-icon-3 copy-1.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "Crafting-Table-icon-3.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "Crafting-Table-icon-3-1.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "Crafting-Table-icon-3 copy-2.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-1-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hawkfalcon/AutoMCServer/cf30912ccbd85293c3b81043de1e4c353b489d11/AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-1-1.png -------------------------------------------------------------------------------- /AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hawkfalcon/AutoMCServer/cf30912ccbd85293c3b81043de1e4c353b489d11/AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-1.png -------------------------------------------------------------------------------- /AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hawkfalcon/AutoMCServer/cf30912ccbd85293c3b81043de1e4c353b489d11/AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-2-1.png -------------------------------------------------------------------------------- /AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hawkfalcon/AutoMCServer/cf30912ccbd85293c3b81043de1e4c353b489d11/AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-2.png -------------------------------------------------------------------------------- /AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-3 copy-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hawkfalcon/AutoMCServer/cf30912ccbd85293c3b81043de1e4c353b489d11/AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-3 copy-1.png -------------------------------------------------------------------------------- /AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-3 copy-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hawkfalcon/AutoMCServer/cf30912ccbd85293c3b81043de1e4c353b489d11/AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-3 copy-2.png -------------------------------------------------------------------------------- /AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-3 copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hawkfalcon/AutoMCServer/cf30912ccbd85293c3b81043de1e4c353b489d11/AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-3 copy.png -------------------------------------------------------------------------------- /AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hawkfalcon/AutoMCServer/cf30912ccbd85293c3b81043de1e4c353b489d11/AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-3-1.png -------------------------------------------------------------------------------- /AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hawkfalcon/AutoMCServer/cf30912ccbd85293c3b81043de1e4c353b489d11/AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-3.png -------------------------------------------------------------------------------- /AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hawkfalcon/AutoMCServer/cf30912ccbd85293c3b81043de1e4c353b489d11/AutoMCServer/Images.xcassets/AppIcon.appiconset/Crafting-Table-icon-4.png -------------------------------------------------------------------------------- /AutoMCServer/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.hawkfalcon.$(PRODUCT_NAME:rfc1034identifier) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 0.1 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | $(MACOSX_DEPLOYMENT_TARGET) 27 | NSHumanReadableCopyright 28 | Copyright © 2015 Tristen Miller. All rights reserved. 29 | NSMainStoryboardFile 30 | Main 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /AutoMCServer/MasterViewController.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | 3 | class DismissSegue: NSStoryboardSegue { 4 | 5 | var nextViewControllerIdentifier:String? 6 | 7 | override func perform() { 8 | let src = self.sourceController as NSViewController 9 | let windowController = src.view.window!.windowController() as TopLevelWindowController 10 | 11 | src.view.removeFromSuperview() 12 | src.removeFromParentViewController() 13 | 14 | if let identifier = nextViewControllerIdentifier { 15 | windowController.setNewViewController(identifier) 16 | } 17 | } 18 | } 19 | 20 | class TopLevelWindowController: NSWindowController { 21 | 22 | /// This is the view and controller under which the various app subviews will be loaded. 23 | /// Connects themselves automatically - see MainContentViewController.viewDidAppear() 24 | var containerView: NSView! 25 | var containerViewController: ContainerViewController! { 26 | didSet { 27 | // setNewViewController depends on containerViewController being set. 28 | setNewViewController("OptionsView") 29 | } 30 | } 31 | 32 | // MARK: Setting a new view controller 33 | 34 | func setNewViewController(identifier: String) { 35 | // Create and set up the new view controller and view. 36 | let viewController = storyboard!.instantiateControllerWithIdentifier(identifier) as NSViewController 37 | let view = viewController.view 38 | view.translatesAutoresizingMaskIntoConstraints = false 39 | containerView.addSubview(viewController.view) 40 | containerViewController.addChildViewController(viewController) 41 | containerView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[view]|", options: nil, metrics: nil, views: ["view": view])) 42 | containerView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[view]|", options: nil, metrics: nil, views: ["view": view])) 43 | } 44 | } 45 | 46 | // This class just immediately connects itself to the top level window controller 47 | class ContainerViewController: NSViewController { 48 | 49 | @IBOutlet var containerView: NSView! 50 | 51 | override func viewDidAppear() { 52 | super.viewDidAppear() 53 | if let window = view.window { 54 | if let topLevelWindowController = window.windowController() as? TopLevelWindowController { 55 | topLevelWindowController.containerView = containerView 56 | topLevelWindowController.containerViewController = self 57 | } 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /AutoMCServer/OptionsViewController.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | 3 | class OptionsViewController: NSViewController { 4 | 5 | var folder: NSURL = NSURL(fileURLWithPath: NSHomeDirectory().stringByAppendingPathComponent("Desktop"))! 6 | 7 | @IBOutlet var servertype: NSSegmentedControl! 8 | @IBOutlet var ram: NSTextField! 9 | @IBOutlet var bytes: NSPopUpButton! 10 | @IBOutlet var username: NSTextField! 11 | @IBOutlet var choosefolder: NSPopUpButton! 12 | 13 | @IBOutlet var worldtype: NSPopUpButton! 14 | @IBOutlet var gamemode: NSPopUpButton! 15 | @IBOutlet var difficulty: NSPopUpButton! 16 | @IBOutlet var maxplayers: NSTextField! 17 | @IBOutlet var motd: NSTextField! 18 | @IBOutlet var nether: NSButton! 19 | @IBOutlet var mobs: NSButton! 20 | @IBOutlet var whitelist: NSButton! 21 | @IBOutlet var pvp: NSButton! 22 | 23 | override func viewDidLoad() { 24 | super.viewDidLoad() 25 | choosefolder.itemAtIndex(0)?.image = NSWorkspace.sharedWorkspace().iconForFile(folder.path!) 26 | } 27 | 28 | override func prepareForSegue(segue: NSStoryboardSegue, sender: AnyObject?) { 29 | if let segue = segue as? DismissSegue { 30 | segue.nextViewControllerIdentifier = "CreationView" 31 | } 32 | var ramv = ram.integerValue 33 | var bytesize = "M" 34 | if bytes.titleOfSelectedItem == "Megabytes" { 35 | ramv = ramv == 0 ? 1024 : ramv 36 | } else { 37 | bytesize = "G" 38 | ramv = ramv == 0 ? 2 : ramv 39 | } 40 | var maxplayer = maxplayers.integerValue 41 | maxplayer = maxplayer == 0 ? 20 : maxplayer 42 | var motds = motd.stringValue 43 | motds = motds == "" ? "A Minecraft Server" : motds 44 | 45 | let options = ServerOptions(path: folder.path!, servertype: getServerType(), ram: ramv, bytesize: bytesize, username: username.stringValue) 46 | Data.options = options 47 | let properties:ServerProperties = ServerProperties(nether: nether.isPressedIn(), leveltype: LevelType(rawValue: worldtype.titleOfSelectedItem!)!, mobs: mobs.isPressedIn(), whitelist: whitelist.isPressedIn(), pvp: pvp.isPressedIn(), difficulty: Difficulty(rawValue: difficulty.indexOfSelectedItem)!, gamemode: GameMode(rawValue: gamemode.indexOfSelectedItem)!, maxplayers: maxplayer, motd: motds) 48 | Data.properties = properties 49 | } 50 | 51 | @IBAction func choosefolder(sender: AnyObject) { 52 | var openPanel = NSOpenPanel() 53 | openPanel.allowsMultipleSelection = false 54 | openPanel.canChooseDirectories = true 55 | openPanel.canCreateDirectories = true 56 | openPanel.canChooseFiles = false 57 | openPanel.beginWithCompletionHandler { (result) -> Void in 58 | if result == NSFileHandlingPanelOKButton { 59 | self.folder = openPanel.URLs[0] as NSURL 60 | self.choosefolder.itemAtIndex(0)?.title = self.folder.lastPathComponent! 61 | self.choosefolder.itemAtIndex(0)?.image = NSWorkspace.sharedWorkspace().iconForFile(self.folder.path!) 62 | self.choosefolder.selectItemAtIndex(0) 63 | } 64 | } 65 | } 66 | 67 | @IBAction func changebytes(sender: AnyObject) { 68 | if bytes.titleOfSelectedItem == "Megabytes" { 69 | ram.placeholderString = "1024" 70 | } else { 71 | ram.placeholderString = "2" 72 | } 73 | } 74 | 75 | func getServerType() -> ServerType { 76 | return ServerType(rawValue: servertype.labelForSegment(servertype.selectedSegment)!)! 77 | } 78 | } 79 | extension NSButton { 80 | func isPressedIn() -> Bool { 81 | return self.state == 1 ? true : false 82 | } 83 | } -------------------------------------------------------------------------------- /AutoMCServer/ServerOptions.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | 3 | enum ServerType: String { 4 | case Spigot = "Spigot" 5 | case Bukkit = "Bukkit" 6 | case Vanilla = "Vanilla" 7 | } 8 | 9 | class ServerOptions { 10 | var path: NSString 11 | var servertype: ServerType = .Spigot 12 | var ram = 2048 13 | var bytesize: String 14 | var username = "Notch" 15 | 16 | init(path: NSString, servertype: ServerType, ram: Int, bytesize: String, username: String) { 17 | self.path = path 18 | self.servertype = servertype 19 | self.ram = ram 20 | self.bytesize = bytesize 21 | self.username = username 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /AutoMCServer/ServerProperties.swift: -------------------------------------------------------------------------------- 1 | import Cocoa 2 | 3 | enum GameMode: Int { 4 | case Survival = 0 5 | case Creative = 1 6 | case Adventure = 2 7 | } 8 | 9 | enum Difficulty: Int { 10 | case Peaceful = 0 11 | case Easy = 1 12 | case Normal = 2 13 | case Hard = 3 14 | } 15 | 16 | enum LevelType: String { 17 | case DEFAULT = "DEFAULT" 18 | case FLAT = "FLAT" 19 | case LARGEBIOMES = "LARGEBIOMES" 20 | case AMPLIFIED = "AMPLIFIED" 21 | } 22 | 23 | class ServerProperties { 24 | var nether: Bool 25 | var leveltype: LevelType 26 | var mobs: Bool 27 | var whitelist: Bool 28 | var pvp: Bool 29 | var difficulty: Difficulty 30 | var gamemode: GameMode 31 | var maxplayers: Int 32 | var motd: String 33 | 34 | init(nether:Bool, leveltype:LevelType, mobs:Bool, whitelist:Bool, pvp:Bool, difficulty:Difficulty, gamemode:GameMode, maxplayers:Int, motd:String) { 35 | self.nether = nether 36 | self.leveltype = leveltype 37 | self.mobs = mobs 38 | self.whitelist = whitelist 39 | self.pvp = pvp 40 | self.difficulty = difficulty 41 | self.gamemode = gamemode 42 | self.maxplayers = maxplayers 43 | self.motd = motd 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /AutoMCServer/SwiftJSON.swift: -------------------------------------------------------------------------------- 1 | // SwiftyJSON.swift 2 | // 3 | // Copyright (c) 2014 Ruoyu Fu, Pinglin Tang 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | import Foundation 24 | 25 | // MARK: - Error 26 | 27 | ///Error domain 28 | public let ErrorDomain: String! = "SwiftyJSONErrorDomain" 29 | 30 | ///Error code 31 | public let ErrorUnsupportedType: Int! = 999 32 | public let ErrorIndexOutOfBounds: Int! = 900 33 | public let ErrorWrongType: Int! = 901 34 | public let ErrorNotExist: Int! = 500 35 | 36 | // MARK: - JSON Type 37 | 38 | /** 39 | JSON's type definitions. 40 | 41 | See http://tools.ietf.org/html/rfc7231#section-4.3 42 | */ 43 | public enum Type :Int{ 44 | 45 | case Number 46 | case String 47 | case Bool 48 | case Array 49 | case Dictionary 50 | case Null 51 | case Unknown 52 | } 53 | 54 | // MARK: - JSON Base 55 | 56 | public struct JSON { 57 | 58 | /** 59 | Creates a JSON using the data. 60 | 61 | :param: data The NSData used to convert to json.Top level object in data is an NSArray or NSDictionary 62 | :param: opt The JSON serialization reading options. `.AllowFragments` by default. 63 | :param: error error The NSErrorPointer used to return the error. `nil` by default. 64 | 65 | :returns: The created JSON 66 | */ 67 | public init(data:NSData, options opt: NSJSONReadingOptions = .AllowFragments, error: NSErrorPointer = nil) { 68 | if let object: AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: opt, error: error) { 69 | self.init(object) 70 | } else { 71 | self.init(NSNull()) 72 | } 73 | } 74 | 75 | /** 76 | Creates a JSON using the object. 77 | 78 | :param: object The object must have the following properties: All objects are NSString/String, NSNumber/Int/Float/Double/Bool, NSArray/Array, NSDictionary/Dictionary, or NSNull; All dictionary keys are NSStrings/String; NSNumbers are not NaN or infinity. 79 | 80 | :returns: The created JSON 81 | */ 82 | public init(_ object: AnyObject) { 83 | self.object = object 84 | } 85 | 86 | /// Private object 87 | private var _object: AnyObject = NSNull() 88 | /// Private type 89 | private var _type: Type = .Null 90 | /// prviate error 91 | private var _error: NSError? 92 | 93 | /// Object in JSON 94 | public var object: AnyObject { 95 | get { 96 | return _object 97 | } 98 | set { 99 | _object = newValue 100 | switch newValue { 101 | case let number as NSNumber: 102 | if number.isBool { 103 | _type = .Bool 104 | } else { 105 | _type = .Number 106 | } 107 | case let string as NSString: 108 | _type = .String 109 | case let null as NSNull: 110 | _type = .Null 111 | case let array as [AnyObject]: 112 | _type = .Array 113 | case let dictionary as [String : AnyObject]: 114 | _type = .Dictionary 115 | default: 116 | _type = .Unknown 117 | _object = NSNull() 118 | _error = NSError(domain: ErrorDomain, code: ErrorUnsupportedType, userInfo: [NSLocalizedDescriptionKey: "It is a unsupported type"]) 119 | } 120 | } 121 | } 122 | 123 | /// json type 124 | public var type: Type { get { return _type } } 125 | 126 | /// Error in JSON 127 | public var error: NSError? { get { return self._error } } 128 | 129 | /// The static null json 130 | public static var nullJSON: JSON { get { return JSON(NSNull()) } } 131 | 132 | } 133 | 134 | // MARK: - SequenceType 135 | extension JSON: SequenceType{ 136 | 137 | /// If `type` is `.Array` or `.Dictionary`, return `array.empty` or `dictonary.empty` otherwise return `false`. 138 | public var isEmpty: Bool { 139 | get { 140 | switch self.type { 141 | case .Array: 142 | return (self.object as [AnyObject]).isEmpty 143 | case .Dictionary: 144 | return (self.object as [String : AnyObject]).isEmpty 145 | default: 146 | return false 147 | } 148 | } 149 | } 150 | 151 | /// If `type` is `.Array` or `.Dictionary`, return `array.count` or `dictonary.count` otherwise return `0`. 152 | public var count: Int { 153 | get { 154 | switch self.type { 155 | case .Array: 156 | return self.arrayValue.count 157 | case .Dictionary: 158 | return self.dictionaryValue.count 159 | default: 160 | return 0 161 | } 162 | } 163 | } 164 | 165 | /** 166 | If `type` is `.Array` or `.Dictionary`, return a generator over the elements like `Array` or `Dictionary`, otherwise return a generator over empty. 167 | 168 | :returns: Return a *generator* over the elements of this *sequence*. 169 | */ 170 | public func generate() -> GeneratorOf <(String, JSON)> { 171 | switch self.type { 172 | case .Array: 173 | let array_ = object as [AnyObject] 174 | var generate_ = array_.generate() 175 | var index_: Int = 0 176 | return GeneratorOf<(String, JSON)> { 177 | if let element_: AnyObject = generate_.next() { 178 | return ("\(index_++)", JSON(element_)) 179 | } else { 180 | return nil 181 | } 182 | } 183 | case .Dictionary: 184 | let dictionary_ = object as [String : AnyObject] 185 | var generate_ = dictionary_.generate() 186 | return GeneratorOf<(String, JSON)> { 187 | if let (key_: String, value_: AnyObject) = generate_.next() { 188 | return (key_, JSON(value_)) 189 | } else { 190 | return nil 191 | } 192 | } 193 | default: 194 | return GeneratorOf<(String, JSON)> { 195 | return nil 196 | } 197 | } 198 | } 199 | } 200 | 201 | // MARK: - Subscript 202 | 203 | /** 204 | * To mark both String and Int can be used in subscript. 205 | */ 206 | public protocol SubscriptType {} 207 | 208 | extension Int: SubscriptType {} 209 | 210 | extension String: SubscriptType {} 211 | 212 | extension JSON { 213 | 214 | /// If `type` is `.Array`, return json which's object is `array[index]`, otherwise return null json with error. 215 | private subscript(#index: Int) -> JSON { 216 | get { 217 | 218 | if self.type != .Array { 219 | var errorResult_ = JSON.nullJSON 220 | errorResult_._error = self._error ?? NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] failure, It is not an array"]) 221 | return errorResult_ 222 | } 223 | 224 | let array_ = self.object as [AnyObject] 225 | 226 | if index >= 0 && index < array_.count { 227 | return JSON(array_[index]) 228 | } 229 | 230 | var errorResult_ = JSON.nullJSON 231 | errorResult_._error = NSError(domain: ErrorDomain, code:ErrorIndexOutOfBounds , userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] is out of bounds"]) 232 | return errorResult_ 233 | } 234 | set { 235 | if self.type == .Array { 236 | var array_ = self.object as [AnyObject] 237 | if array_.count > index { 238 | array_[index] = newValue.object 239 | self.object = array_ 240 | } 241 | } 242 | } 243 | } 244 | 245 | /// If `type` is `.Dictionary`, return json which's object is `dictionary[key]` , otherwise return null json with error. 246 | private subscript(#key: String) -> JSON { 247 | get { 248 | var returnJSON = JSON.nullJSON 249 | if self.type == .Dictionary { 250 | if let object_: AnyObject = self.object[key] { 251 | returnJSON = JSON(object_) 252 | } else { 253 | returnJSON._error = NSError(domain: ErrorDomain, code: ErrorNotExist, userInfo: [NSLocalizedDescriptionKey: "Dictionary[\"\(key)\"] does not exist"]) 254 | } 255 | } else { 256 | returnJSON._error = self._error ?? NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Dictionary[\"\(key)\"] failure, It is not an dictionary"]) 257 | } 258 | return returnJSON 259 | } 260 | set { 261 | if self.type == .Dictionary { 262 | var dictionary_ = self.object as [String : AnyObject] 263 | dictionary_[key] = newValue.object 264 | self.object = dictionary_ 265 | } 266 | } 267 | } 268 | 269 | /// If `sub` is `Int`, return `subscript(index:)`; If `sub` is `String`, return `subscript(key:)`. 270 | private subscript(#sub: SubscriptType) -> JSON { 271 | get { 272 | if sub is String { 273 | return self[key:sub as String] 274 | } else { 275 | return self[index:sub as Int] 276 | } 277 | } 278 | set { 279 | if sub is String { 280 | self[key:sub as String] = newValue 281 | } else { 282 | self[index:sub as Int] = newValue 283 | } 284 | } 285 | } 286 | 287 | /** 288 | Find a json in the complex data structuresby using the Int/String's array. 289 | 290 | :param: path The target json's path. Example: 291 | 292 | let json = JSON[data] 293 | let path = [9,"list","person","name"] 294 | let name = json[path] 295 | 296 | The same as: let name = json[9]["list"]["person"]["name"] 297 | 298 | :returns: Return a json found by the path or a null json with error 299 | */ 300 | public subscript(path: [SubscriptType]) -> JSON { 301 | get { 302 | if path.count == 0 { 303 | return JSON.nullJSON 304 | } 305 | 306 | var next = self 307 | for sub in path { 308 | next = next[sub:sub] 309 | } 310 | return next 311 | } 312 | set { 313 | 314 | switch path.count { 315 | case 0: return 316 | case 1: self[sub:path[0]] = newValue 317 | default: 318 | var last = newValue 319 | var newPath = path 320 | newPath.removeLast() 321 | for sub in path.reverse() { 322 | var previousLast = self[newPath] 323 | previousLast[sub:sub] = last 324 | last = previousLast 325 | if newPath.count <= 1 { 326 | break 327 | } 328 | newPath.removeLast() 329 | } 330 | self[sub:newPath[0]] = last 331 | } 332 | } 333 | } 334 | 335 | /** 336 | Find a json in the complex data structuresby using the Int/String's array. 337 | 338 | :param: path The target json's path. Example: 339 | 340 | let name = json[9,"list","person","name"] 341 | 342 | The same as: let name = json[9]["list"]["person"]["name"] 343 | 344 | :returns: Return a json found by the path or a null json with error 345 | */ 346 | public subscript(path: SubscriptType...) -> JSON { 347 | get { 348 | return self[path] 349 | } 350 | set { 351 | self[path] = newValue 352 | } 353 | } 354 | } 355 | 356 | // MARK: - LiteralConvertible 357 | 358 | extension JSON: StringLiteralConvertible { 359 | 360 | public init(stringLiteral value: StringLiteralType) { 361 | self.init(value) 362 | } 363 | 364 | public init(extendedGraphemeClusterLiteral value: StringLiteralType) { 365 | self.init(value) 366 | } 367 | 368 | public init(unicodeScalarLiteral value: StringLiteralType) { 369 | self.init(value) 370 | } 371 | } 372 | 373 | extension JSON: IntegerLiteralConvertible { 374 | 375 | public init(integerLiteral value: IntegerLiteralType) { 376 | self.init(value) 377 | } 378 | } 379 | 380 | extension JSON: BooleanLiteralConvertible { 381 | 382 | public init(booleanLiteral value: BooleanLiteralType) { 383 | self.init(value) 384 | } 385 | } 386 | 387 | extension JSON: FloatLiteralConvertible { 388 | 389 | public init(floatLiteral value: FloatLiteralType) { 390 | self.init(value) 391 | } 392 | } 393 | 394 | extension JSON: DictionaryLiteralConvertible { 395 | 396 | public init(dictionaryLiteral elements: (String, AnyObject)...) { 397 | var dictionary_ = [String : AnyObject]() 398 | for (key_, value) in elements { 399 | dictionary_[key_] = value 400 | } 401 | self.init(dictionary_) 402 | } 403 | } 404 | 405 | extension JSON: ArrayLiteralConvertible { 406 | 407 | public init(arrayLiteral elements: AnyObject...) { 408 | self.init(elements) 409 | } 410 | } 411 | 412 | extension JSON: NilLiteralConvertible { 413 | 414 | public init(nilLiteral: ()) { 415 | self.init(NSNull()) 416 | } 417 | } 418 | 419 | // MARK: - Raw 420 | 421 | extension JSON: RawRepresentable { 422 | 423 | public init?(rawValue: AnyObject) { 424 | if JSON(rawValue).type == .Unknown { 425 | return nil 426 | } else { 427 | self.init(rawValue) 428 | } 429 | } 430 | 431 | public var rawValue: AnyObject { 432 | return self.object 433 | } 434 | 435 | public func rawData(options opt: NSJSONWritingOptions = NSJSONWritingOptions(0), error: NSErrorPointer = nil) -> NSData? { 436 | return NSJSONSerialization.dataWithJSONObject(self.object, options: opt, error:error) 437 | } 438 | 439 | public func rawString(encoding: UInt = NSUTF8StringEncoding, options opt: NSJSONWritingOptions = .PrettyPrinted) -> String? { 440 | switch self.type { 441 | case .Array, .Dictionary: 442 | if let data = self.rawData(options: opt) { 443 | return NSString(data: data, encoding: encoding) 444 | } else { 445 | return nil 446 | } 447 | case .String: 448 | return (self.object as String) 449 | case .Number: 450 | return (self.object as NSNumber).stringValue 451 | case .Bool: 452 | return (self.object as Bool).description 453 | case .Null: 454 | return "null" 455 | default: 456 | return nil 457 | } 458 | } 459 | } 460 | 461 | // MARK: - Printable, DebugPrintable 462 | 463 | extension JSON: Printable, DebugPrintable { 464 | 465 | public var description: String { 466 | if let string = self.rawString(options:.PrettyPrinted) { 467 | return string 468 | } else { 469 | return "unknown" 470 | } 471 | } 472 | 473 | public var debugDescription: String { 474 | return description 475 | } 476 | } 477 | 478 | // MARK: - Array 479 | 480 | extension JSON { 481 | 482 | //Optional [JSON] 483 | public var array: [JSON]? { 484 | get { 485 | if self.type == .Array { 486 | return map(self.object as [AnyObject]){ JSON($0) } 487 | } else { 488 | return nil 489 | } 490 | } 491 | } 492 | 493 | //Non-optional [JSON] 494 | public var arrayValue: [JSON] { 495 | get { 496 | return self.array ?? [] 497 | } 498 | } 499 | 500 | //Optional [AnyObject] 501 | public var arrayObject: [AnyObject]? { 502 | get { 503 | switch self.type { 504 | case .Array: 505 | return self.object as? [AnyObject] 506 | default: 507 | return nil 508 | } 509 | } 510 | set { 511 | if newValue != nil { 512 | self.object = NSMutableArray(array: newValue!, copyItems: true) 513 | } else { 514 | self.object = NSNull() 515 | } 516 | } 517 | } 518 | } 519 | 520 | // MARK: - Dictionary 521 | 522 | extension JSON { 523 | 524 | private func _map(source: [Key: Value], transform: Value -> NewValue) -> [Key: NewValue] { 525 | var result = [Key: NewValue](minimumCapacity:source.count) 526 | for (key,value) in source { 527 | result[key] = transform(value) 528 | } 529 | return result 530 | } 531 | 532 | //Optional [String : JSON] 533 | public var dictionary: [String : JSON]? { 534 | get { 535 | if self.type == .Dictionary { 536 | return _map(self.object as [String : AnyObject]){ JSON($0) } 537 | } else { 538 | return nil 539 | } 540 | } 541 | } 542 | 543 | //Non-optional [String : JSON] 544 | public var dictionaryValue: [String : JSON] { 545 | get { 546 | return self.dictionary ?? [:] 547 | } 548 | } 549 | 550 | //Optional [String : AnyObject] 551 | public var dictionaryObject: [String : AnyObject]? { 552 | get { 553 | switch self.type { 554 | case .Dictionary: 555 | return self.object as? [String : AnyObject] 556 | default: 557 | return nil 558 | } 559 | } 560 | set { 561 | if newValue != nil { 562 | self.object = NSMutableDictionary(dictionary: newValue!, copyItems: true) 563 | } else { 564 | self.object = NSNull() 565 | } 566 | } 567 | } 568 | } 569 | 570 | // MARK: - Bool 571 | 572 | extension JSON: BooleanType { 573 | 574 | //Optional bool 575 | public var bool: Bool? { 576 | get { 577 | switch self.type { 578 | case .Bool: 579 | return self.object.boolValue 580 | default: 581 | return nil 582 | } 583 | } 584 | set { 585 | if newValue != nil { 586 | self.object = NSNumber(bool: newValue!) 587 | } else { 588 | self.object = NSNull() 589 | } 590 | } 591 | } 592 | 593 | //Non-optional bool 594 | public var boolValue: Bool { 595 | get { 596 | switch self.type { 597 | case .Bool, .Number, .String: 598 | return self.object.boolValue 599 | default: 600 | return false 601 | } 602 | } 603 | set { 604 | self.object = NSNumber(bool: newValue) 605 | } 606 | } 607 | } 608 | 609 | // MARK: - String 610 | 611 | extension JSON { 612 | 613 | //Optional string 614 | public var string: String? { 615 | get { 616 | switch self.type { 617 | case .String: 618 | return self.object as? String 619 | default: 620 | return nil 621 | } 622 | } 623 | set { 624 | if newValue != nil { 625 | self.object = NSString(string:newValue!) 626 | } else { 627 | self.object = NSNull() 628 | } 629 | } 630 | } 631 | 632 | //Non-optional string 633 | public var stringValue: String { 634 | get { 635 | switch self.type { 636 | case .String: 637 | return self.object as String 638 | case .Number: 639 | return self.object.stringValue 640 | case .Bool: 641 | return (self.object as Bool).description 642 | default: 643 | return "" 644 | } 645 | } 646 | set { 647 | self.object = NSString(string:newValue) 648 | } 649 | } 650 | } 651 | 652 | // MARK: - Number 653 | extension JSON { 654 | 655 | //Optional number 656 | public var number: NSNumber? { 657 | get { 658 | switch self.type { 659 | case .Number, .Bool: 660 | return self.object as? NSNumber 661 | default: 662 | return nil 663 | } 664 | } 665 | set { 666 | self.object = newValue?.copy() ?? NSNull() 667 | } 668 | } 669 | 670 | //Non-optional number 671 | public var numberValue: NSNumber { 672 | get { 673 | switch self.type { 674 | case .String: 675 | let scanner = NSScanner(string: self.object as String) 676 | if scanner.scanDouble(nil){ 677 | if (scanner.atEnd) { 678 | return NSNumber(double:(self.object as NSString).doubleValue) 679 | } 680 | } 681 | return NSNumber(double: 0.0) 682 | case .Number, .Bool: 683 | return self.object as NSNumber 684 | default: 685 | return NSNumber(double: 0.0) 686 | } 687 | } 688 | set { 689 | self.object = newValue.copy() 690 | } 691 | } 692 | } 693 | 694 | //MARK: - Null 695 | extension JSON { 696 | 697 | public var null: NSNull? { 698 | get { 699 | switch self.type { 700 | case .Null: 701 | return NSNull() 702 | default: 703 | return nil 704 | } 705 | } 706 | set { 707 | self.object = NSNull() 708 | } 709 | } 710 | } 711 | 712 | //MARK: - URL 713 | extension JSON { 714 | 715 | //Optional URL 716 | public var URL: NSURL? { 717 | get { 718 | switch self.type { 719 | case .String: 720 | if let encodedString_ = self.object.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) { 721 | return NSURL(string: encodedString_) 722 | } else { 723 | return nil 724 | } 725 | default: 726 | return nil 727 | } 728 | } 729 | set { 730 | self.object = newValue?.absoluteString ?? NSNull() 731 | } 732 | } 733 | } 734 | 735 | // MARK: - Int, Double, Float, Int8, Int16, Int32, Int64 736 | 737 | extension JSON { 738 | 739 | public var double: Double? { 740 | get { 741 | return self.number?.doubleValue 742 | } 743 | set { 744 | if newValue != nil { 745 | self.object = NSNumber(double: newValue!) 746 | } else { 747 | self.object = NSNull() 748 | } 749 | } 750 | } 751 | 752 | public var doubleValue: Double { 753 | get { 754 | return self.numberValue.doubleValue 755 | } 756 | set { 757 | self.object = NSNumber(double: newValue) 758 | } 759 | } 760 | 761 | public var float: Float? { 762 | get { 763 | return self.number?.floatValue 764 | } 765 | set { 766 | if newValue != nil { 767 | self.object = NSNumber(float: newValue!) 768 | } else { 769 | self.object = NSNull() 770 | } 771 | } 772 | } 773 | 774 | public var floatValue: Float { 775 | get { 776 | return self.numberValue.floatValue 777 | } 778 | set { 779 | self.object = NSNumber(float: newValue) 780 | } 781 | } 782 | 783 | public var int: Int? { 784 | get { 785 | return self.number?.longValue 786 | } 787 | set { 788 | if newValue != nil { 789 | self.object = NSNumber(integer: newValue!) 790 | } else { 791 | self.object = NSNull() 792 | } 793 | } 794 | } 795 | 796 | public var intValue: Int { 797 | get { 798 | return self.numberValue.integerValue 799 | } 800 | set { 801 | self.object = NSNumber(integer: newValue) 802 | } 803 | } 804 | 805 | public var uInt: UInt? { 806 | get { 807 | return self.number?.unsignedLongValue 808 | } 809 | set { 810 | if newValue != nil { 811 | self.object = NSNumber(unsignedLong: newValue!) 812 | } else { 813 | self.object = NSNull() 814 | } 815 | } 816 | } 817 | 818 | public var uIntValue: UInt { 819 | get { 820 | return self.numberValue.unsignedLongValue 821 | } 822 | set { 823 | self.object = NSNumber(unsignedLong: newValue) 824 | } 825 | } 826 | 827 | public var int8: Int8? { 828 | get { 829 | return self.number?.charValue 830 | } 831 | set { 832 | if newValue != nil { 833 | self.object = NSNumber(char: newValue!) 834 | } else { 835 | self.object = NSNull() 836 | } 837 | } 838 | } 839 | 840 | public var int8Value: Int8 { 841 | get { 842 | return self.numberValue.charValue 843 | } 844 | set { 845 | self.object = NSNumber(char: newValue) 846 | } 847 | } 848 | 849 | public var uInt8: UInt8? { 850 | get { 851 | return self.number?.unsignedCharValue 852 | } 853 | set { 854 | if newValue != nil { 855 | self.object = NSNumber(unsignedChar: newValue!) 856 | } else { 857 | self.object = NSNull() 858 | } 859 | } 860 | } 861 | 862 | public var uInt8Value: UInt8 { 863 | get { 864 | return self.numberValue.unsignedCharValue 865 | } 866 | set { 867 | self.object = NSNumber(unsignedChar: newValue) 868 | } 869 | } 870 | 871 | public var int16: Int16? { 872 | get { 873 | return self.number?.shortValue 874 | } 875 | set { 876 | if newValue != nil { 877 | self.object = NSNumber(short: newValue!) 878 | } else { 879 | self.object = NSNull() 880 | } 881 | } 882 | } 883 | 884 | public var int16Value: Int16 { 885 | get { 886 | return self.numberValue.shortValue 887 | } 888 | set { 889 | self.object = NSNumber(short: newValue) 890 | } 891 | } 892 | 893 | public var uInt16: UInt16? { 894 | get { 895 | return self.number?.unsignedShortValue 896 | } 897 | set { 898 | if newValue != nil { 899 | self.object = NSNumber(unsignedShort: newValue!) 900 | } else { 901 | self.object = NSNull() 902 | } 903 | } 904 | } 905 | 906 | public var uInt16Value: UInt16 { 907 | get { 908 | return self.numberValue.unsignedShortValue 909 | } 910 | set { 911 | self.object = NSNumber(unsignedShort: newValue) 912 | } 913 | } 914 | 915 | public var int32: Int32? { 916 | get { 917 | return self.number?.intValue 918 | } 919 | set { 920 | if newValue != nil { 921 | self.object = NSNumber(int: newValue!) 922 | } else { 923 | self.object = NSNull() 924 | } 925 | } 926 | } 927 | 928 | public var int32Value: Int32 { 929 | get { 930 | return self.numberValue.intValue 931 | } 932 | set { 933 | self.object = NSNumber(int: newValue) 934 | } 935 | } 936 | 937 | public var uInt32: UInt32? { 938 | get { 939 | return self.number?.unsignedIntValue 940 | } 941 | set { 942 | if newValue != nil { 943 | self.object = NSNumber(unsignedInt: newValue!) 944 | } else { 945 | self.object = NSNull() 946 | } 947 | } 948 | } 949 | 950 | public var uInt32Value: UInt32 { 951 | get { 952 | return self.numberValue.unsignedIntValue 953 | } 954 | set { 955 | self.object = NSNumber(unsignedInt: newValue) 956 | } 957 | } 958 | 959 | public var int64: Int64? { 960 | get { 961 | return self.number?.longLongValue 962 | } 963 | set { 964 | if newValue != nil { 965 | self.object = NSNumber(longLong: newValue!) 966 | } else { 967 | self.object = NSNull() 968 | } 969 | } 970 | } 971 | 972 | public var int64Value: Int64 { 973 | get { 974 | return self.numberValue.longLongValue 975 | } 976 | set { 977 | self.object = NSNumber(longLong: newValue) 978 | } 979 | } 980 | 981 | public var uInt64: UInt64? { 982 | get { 983 | return self.number?.unsignedLongLongValue 984 | } 985 | set { 986 | if newValue != nil { 987 | self.object = NSNumber(unsignedLongLong: newValue!) 988 | } else { 989 | self.object = NSNull() 990 | } 991 | } 992 | } 993 | 994 | public var uInt64Value: UInt64 { 995 | get { 996 | return self.numberValue.unsignedLongLongValue 997 | } 998 | set { 999 | self.object = NSNumber(unsignedLongLong: newValue) 1000 | } 1001 | } 1002 | } 1003 | 1004 | //MARK: - Comparable 1005 | extension JSON: Comparable {} 1006 | 1007 | public func ==(lhs: JSON, rhs: JSON) -> Bool { 1008 | 1009 | switch (lhs.type, rhs.type) { 1010 | case (.Number, .Number): 1011 | return (lhs.object as NSNumber) == (rhs.object as NSNumber) 1012 | case (.String, .String): 1013 | return (lhs.object as String) == (rhs.object as String) 1014 | case (.Bool, .Bool): 1015 | return (lhs.object as Bool) == (rhs.object as Bool) 1016 | case (.Array, .Array): 1017 | return (lhs.object as NSArray) == (rhs.object as NSArray) 1018 | case (.Dictionary, .Dictionary): 1019 | return (lhs.object as NSDictionary) == (rhs.object as NSDictionary) 1020 | case (.Null, .Null): 1021 | return true 1022 | default: 1023 | return false 1024 | } 1025 | } 1026 | 1027 | public func <=(lhs: JSON, rhs: JSON) -> Bool { 1028 | 1029 | switch (lhs.type, rhs.type) { 1030 | case (.Number, .Number): 1031 | return (lhs.object as NSNumber) <= (rhs.object as NSNumber) 1032 | case (.String, .String): 1033 | return (lhs.object as String) <= (rhs.object as String) 1034 | case (.Bool, .Bool): 1035 | return (lhs.object as Bool) == (rhs.object as Bool) 1036 | case (.Array, .Array): 1037 | return (lhs.object as NSArray) == (rhs.object as NSArray) 1038 | case (.Dictionary, .Dictionary): 1039 | return (lhs.object as NSDictionary) == (rhs.object as NSDictionary) 1040 | case (.Null, .Null): 1041 | return true 1042 | default: 1043 | return false 1044 | } 1045 | } 1046 | 1047 | public func >=(lhs: JSON, rhs: JSON) -> Bool { 1048 | 1049 | switch (lhs.type, rhs.type) { 1050 | case (.Number, .Number): 1051 | return (lhs.object as NSNumber) >= (rhs.object as NSNumber) 1052 | case (.String, .String): 1053 | return (lhs.object as String) >= (rhs.object as String) 1054 | case (.Bool, .Bool): 1055 | return (lhs.object as Bool) == (rhs.object as Bool) 1056 | case (.Array, .Array): 1057 | return (lhs.object as NSArray) == (rhs.object as NSArray) 1058 | case (.Dictionary, .Dictionary): 1059 | return (lhs.object as NSDictionary) == (rhs.object as NSDictionary) 1060 | case (.Null, .Null): 1061 | return true 1062 | default: 1063 | return false 1064 | } 1065 | } 1066 | 1067 | public func >(lhs: JSON, rhs: JSON) -> Bool { 1068 | 1069 | switch (lhs.type, rhs.type) { 1070 | case (.Number, .Number): 1071 | return (lhs.object as NSNumber) > (rhs.object as NSNumber) 1072 | case (.String, .String): 1073 | return (lhs.object as String) > (rhs.object as String) 1074 | default: 1075 | return false 1076 | } 1077 | } 1078 | 1079 | public func <(lhs: JSON, rhs: JSON) -> Bool { 1080 | 1081 | switch (lhs.type, rhs.type) { 1082 | case (.Number, .Number): 1083 | return (lhs.object as NSNumber) < (rhs.object as NSNumber) 1084 | case (.String, .String): 1085 | return (lhs.object as String) < (rhs.object as String) 1086 | default: 1087 | return false 1088 | } 1089 | } 1090 | 1091 | private let trueNumber = NSNumber(bool: true) 1092 | private let falseNumber = NSNumber(bool: false) 1093 | private let trueObjCType = String.fromCString(trueNumber.objCType) 1094 | private let falseObjCType = String.fromCString(falseNumber.objCType) 1095 | 1096 | // MARK: - NSNumber: Comparable 1097 | 1098 | extension NSNumber: Comparable { 1099 | var isBool:Bool { 1100 | get { 1101 | let objCType = String.fromCString(self.objCType) 1102 | if (self.compare(trueNumber) == NSComparisonResult.OrderedSame && objCType == trueObjCType) || (self.compare(falseNumber) == NSComparisonResult.OrderedSame && objCType == falseObjCType){ 1103 | return true 1104 | } else { 1105 | return false 1106 | } 1107 | } 1108 | } 1109 | } 1110 | 1111 | public func ==(lhs: NSNumber, rhs: NSNumber) -> Bool { 1112 | switch (lhs.isBool, rhs.isBool) { 1113 | case (false, true): 1114 | return false 1115 | case (true, false): 1116 | return false 1117 | default: 1118 | return lhs.compare(rhs) == NSComparisonResult.OrderedSame 1119 | } 1120 | } 1121 | 1122 | public func !=(lhs: NSNumber, rhs: NSNumber) -> Bool { 1123 | return !(lhs == rhs) 1124 | } 1125 | 1126 | public func <(lhs: NSNumber, rhs: NSNumber) -> Bool { 1127 | 1128 | switch (lhs.isBool, rhs.isBool) { 1129 | case (false, true): 1130 | return false 1131 | case (true, false): 1132 | return false 1133 | default: 1134 | return lhs.compare(rhs) == NSComparisonResult.OrderedAscending 1135 | } 1136 | } 1137 | 1138 | public func >(lhs: NSNumber, rhs: NSNumber) -> Bool { 1139 | 1140 | switch (lhs.isBool, rhs.isBool) { 1141 | case (false, true): 1142 | return false 1143 | case (true, false): 1144 | return false 1145 | default: 1146 | return lhs.compare(rhs) == NSComparisonResult.OrderedDescending 1147 | } 1148 | } 1149 | 1150 | public func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { 1151 | 1152 | switch (lhs.isBool, rhs.isBool) { 1153 | case (false, true): 1154 | return false 1155 | case (true, false): 1156 | return false 1157 | default: 1158 | return lhs.compare(rhs) != NSComparisonResult.OrderedDescending 1159 | } 1160 | } 1161 | 1162 | public func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { 1163 | 1164 | switch (lhs.isBool, rhs.isBool) { 1165 | case (false, true): 1166 | return false 1167 | case (true, false): 1168 | return false 1169 | default: 1170 | return lhs.compare(rhs) != NSComparisonResult.OrderedAscending 1171 | } 1172 | } 1173 | 1174 | //MARK:- Unavailable 1175 | 1176 | @availability(*, unavailable, renamed="JSON") 1177 | public typealias JSONValue = JSON 1178 | 1179 | extension JSON { 1180 | 1181 | @availability(*, unavailable, message="use 'init(_ object:AnyObject)' instead") 1182 | public init(object: AnyObject) { 1183 | self = JSON(object) 1184 | } 1185 | 1186 | @availability(*, unavailable, renamed="dictionaryObject") 1187 | public var dictionaryObjects: [String : AnyObject]? { 1188 | get { return self.dictionaryObject } 1189 | } 1190 | 1191 | @availability(*, unavailable, renamed="arrayObject") 1192 | public var arrayObjects: [AnyObject]? { 1193 | get { return self.arrayObject } 1194 | } 1195 | 1196 | @availability(*, unavailable, renamed="int8") 1197 | public var char: Int8? { 1198 | get { 1199 | return self.number?.charValue 1200 | } 1201 | } 1202 | 1203 | @availability(*, unavailable, renamed="int8Value") 1204 | public var charValue: Int8 { 1205 | get { 1206 | return self.numberValue.charValue 1207 | } 1208 | } 1209 | 1210 | @availability(*, unavailable, renamed="uInt8") 1211 | public var unsignedChar: UInt8? { 1212 | get{ 1213 | return self.number?.unsignedCharValue 1214 | } 1215 | } 1216 | 1217 | @availability(*, unavailable, renamed="uInt8Value") 1218 | public var unsignedCharValue: UInt8 { 1219 | get{ 1220 | return self.numberValue.unsignedCharValue 1221 | } 1222 | } 1223 | 1224 | @availability(*, unavailable, renamed="int16") 1225 | public var short: Int16? { 1226 | get{ 1227 | return self.number?.shortValue 1228 | } 1229 | } 1230 | 1231 | @availability(*, unavailable, renamed="int16Value") 1232 | public var shortValue: Int16 { 1233 | get{ 1234 | return self.numberValue.shortValue 1235 | } 1236 | } 1237 | 1238 | @availability(*, unavailable, renamed="uInt16") 1239 | public var unsignedShort: UInt16? { 1240 | get{ 1241 | return self.number?.unsignedShortValue 1242 | } 1243 | } 1244 | 1245 | @availability(*, unavailable, renamed="uInt16Value") 1246 | public var unsignedShortValue: UInt16 { 1247 | get{ 1248 | return self.numberValue.unsignedShortValue 1249 | } 1250 | } 1251 | 1252 | @availability(*, unavailable, renamed="int") 1253 | public var long: Int? { 1254 | get{ 1255 | return self.number?.longValue 1256 | } 1257 | } 1258 | 1259 | @availability(*, unavailable, renamed="intValue") 1260 | public var longValue: Int { 1261 | get{ 1262 | return self.numberValue.longValue 1263 | } 1264 | } 1265 | 1266 | @availability(*, unavailable, renamed="uInt") 1267 | public var unsignedLong: UInt? { 1268 | get{ 1269 | return self.number?.unsignedLongValue 1270 | } 1271 | } 1272 | 1273 | @availability(*, unavailable, renamed="uIntValue") 1274 | public var unsignedLongValue: UInt { 1275 | get{ 1276 | return self.numberValue.unsignedLongValue 1277 | } 1278 | } 1279 | 1280 | @availability(*, unavailable, renamed="int64") 1281 | public var longLong: Int64? { 1282 | get{ 1283 | return self.number?.longLongValue 1284 | } 1285 | } 1286 | 1287 | @availability(*, unavailable, renamed="int64Value") 1288 | public var longLongValue: Int64 { 1289 | get{ 1290 | return self.numberValue.longLongValue 1291 | } 1292 | } 1293 | 1294 | @availability(*, unavailable, renamed="uInt64") 1295 | public var unsignedLongLong: UInt64? { 1296 | get{ 1297 | return self.number?.unsignedLongLongValue 1298 | } 1299 | } 1300 | 1301 | @availability(*, unavailable, renamed="uInt64Value") 1302 | public var unsignedLongLongValue: UInt64 { 1303 | get{ 1304 | return self.numberValue.unsignedLongLongValue 1305 | } 1306 | } 1307 | 1308 | @availability(*, unavailable, renamed="int") 1309 | public var integer: Int? { 1310 | get { 1311 | return self.number?.integerValue 1312 | } 1313 | } 1314 | 1315 | @availability(*, unavailable, renamed="intValue") 1316 | public var integerValue: Int { 1317 | get { 1318 | return self.numberValue.integerValue 1319 | } 1320 | } 1321 | 1322 | @availability(*, unavailable, renamed="uInt") 1323 | public var unsignedInteger: Int? { 1324 | get { 1325 | return self.number?.unsignedIntegerValue 1326 | } 1327 | } 1328 | 1329 | @availability(*, unavailable, renamed="uIntValue") 1330 | public var unsignedIntegerValue: Int { 1331 | get { 1332 | return self.numberValue.unsignedIntegerValue 1333 | } 1334 | } 1335 | } -------------------------------------------------------------------------------- /AutoMCServer/TaskQueue.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TaskQueue.swift ver. 0.9.1 3 | // 4 | // Copyright (c) 2014 Marin Todorov, Underplot ltd. 5 | // This code is distributed under the terms and conditions of the MIT license. 6 | // 7 | // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 | // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 9 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | // 11 | // This class is inspired by Sequencer (objc) https://github.com/berzniz/Sequencer 12 | // but aims to implement 1) flow control, 2) swift code, 3) control of GDC queues, 4) concurrency 13 | 14 | import Foundation 15 | 16 | // MARK: TaskQueue class 17 | 18 | class TaskQueue: Printable { 19 | 20 | // 21 | // types used by the TaskQueue 22 | // 23 | typealias ClosureNoResultNext = () -> Void 24 | typealias ClosureWithResult = (AnyObject?) -> Void 25 | typealias ClosureWithResultNext = (AnyObject? , AnyObject? -> Void) -> Void 26 | 27 | // 28 | // tasks and completions storage 29 | // 30 | var tasks: [ClosureWithResultNext] = [] 31 | lazy var completions: [ClosureNoResultNext] = [] 32 | 33 | // 34 | // concurrency 35 | // 36 | private(set) var numberOfActiveTasks: Int = 0 37 | var maximumNumberOfActiveTasks: Int = 1 { 38 | willSet { 39 | assert(maximumNumberOfActiveTasks>0, "Setting less than 1 task at a time not allowed") 40 | } 41 | } 42 | 43 | private var currentTask: ClosureWithResultNext? = nil 44 | private(set) var lastResult: AnyObject! = nil 45 | 46 | // 47 | // queue state 48 | // 49 | private(set) var running = false 50 | 51 | var paused: Bool = false { 52 | didSet { 53 | running = !paused 54 | } 55 | } 56 | 57 | private var cancelled = false 58 | func cancel() { 59 | cancelled = true 60 | } 61 | 62 | private var hasCompletions = false 63 | 64 | // 65 | // start or resume the queue 66 | // 67 | func run(completion: ClosureNoResultNext? = nil) { 68 | if completion != nil { 69 | hasCompletions = true 70 | completions += [completion!] 71 | } 72 | 73 | if (paused) { 74 | paused = false 75 | _runNextTask() 76 | return 77 | } 78 | 79 | if running { 80 | return 81 | } 82 | 83 | running = true 84 | _runNextTask() 85 | } 86 | 87 | private func _runNextTask(result: AnyObject? = nil) { 88 | if (cancelled) { 89 | tasks.removeAll(keepCapacity: false) 90 | completions.removeAll(keepCapacity: false) 91 | } 92 | 93 | if (numberOfActiveTasks >= maximumNumberOfActiveTasks) { 94 | return 95 | } 96 | 97 | lastResult = result 98 | 99 | if paused { 100 | return 101 | } 102 | 103 | var task: ClosureWithResultNext? = nil 104 | 105 | //fetch one task synchronized 106 | objc_sync_enter(self) 107 | if self.tasks.count > 0 { 108 | task = self.tasks.removeAtIndex(0) 109 | self.numberOfActiveTasks++ 110 | } 111 | objc_sync_exit(self) 112 | 113 | if task == nil { 114 | if self.numberOfActiveTasks == 0 { 115 | self._complete() 116 | } 117 | return 118 | } 119 | 120 | currentTask = task 121 | 122 | let executeTask = { 123 | task!(self.maximumNumberOfActiveTasks>1 ? nil: result) { (nextResult: AnyObject?) in 124 | self.numberOfActiveTasks-- 125 | self._runNextTask(result: nextResult) 126 | } 127 | } 128 | 129 | if maximumNumberOfActiveTasks>1 { 130 | //parallel queue 131 | _delay(seconds: 0.001) { 132 | self._runNextTask(result: nil) 133 | } 134 | _delay(seconds: 0, executeTask) 135 | } else { 136 | //serial queue 137 | executeTask() 138 | } 139 | } 140 | 141 | private func _complete() { 142 | paused = false 143 | running = false 144 | 145 | if hasCompletions { 146 | //synchronized remove completions 147 | objc_sync_enter(self) 148 | while completions.count > 0 { 149 | (completions.removeAtIndex(0) as ClosureNoResultNext)() 150 | } 151 | objc_sync_exit(self) 152 | } 153 | } 154 | 155 | // 156 | // skip the next task 157 | // 158 | func skip() { 159 | if tasks.count>0 { 160 | _ = tasks.removeAtIndex(0) //better way? 161 | } 162 | } 163 | 164 | // 165 | // remove all remaining tasks 166 | // 167 | func removeAll() { 168 | tasks.removeAll(keepCapacity: false) 169 | } 170 | 171 | // 172 | // count of the tasks left to execute 173 | // 174 | var count: Int { 175 | return tasks.count 176 | } 177 | 178 | // 179 | // re-run the current task 180 | // 181 | func retry(delay: Double = 0) { 182 | assert(maximumNumberOfActiveTasks==1, "You can call retry() only on serial queues") 183 | 184 | tasks.insert(currentTask!, atIndex: 0) 185 | currentTask = nil 186 | 187 | self._delay(seconds: delay) { 188 | self.numberOfActiveTasks-- 189 | self._runNextTask(result: self.lastResult) 190 | } 191 | } 192 | 193 | // 194 | // Provide description when printed 195 | // 196 | var description: String { 197 | let state = running ? "runing " : (paused ? "paused ": "stopped") 198 | let type = maximumNumberOfActiveTasks==1 ? "serial": "parallel" 199 | 200 | return "[TaskQueue] type=\(type) state=\(state) \(tasks.count) tasks" 201 | } 202 | 203 | deinit { 204 | //println("queue deinit") 205 | } 206 | 207 | private func _delay(#seconds:Double, completion:()->()) { 208 | let popTime = dispatch_time(DISPATCH_TIME_NOW, Int64( Double(NSEC_PER_SEC) * seconds )) 209 | 210 | dispatch_after(popTime, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0)) { 211 | completion() 212 | } 213 | } 214 | 215 | } 216 | 217 | // 218 | // Operator overlaoding helps to make adding tasks to the queue 219 | // more readable and easy to understand. You just keep adding closures 220 | // to the tasks array and the operators adjust your task to the desired 221 | // ClosureWithResultNext type. 222 | // 223 | 224 | infix operator +=~ {} 225 | infix operator +=! {} 226 | 227 | // MARK: Add tasks on the current queue 228 | 229 | // 230 | // Add a task closure with result and next params 231 | // 232 | func += (inout tasks: [TaskQueue.ClosureWithResultNext], task: TaskQueue.ClosureWithResultNext) { 233 | tasks += [task] 234 | } 235 | 236 | // 237 | // Add a task closure that doesn't take result/next params 238 | // 239 | func += (inout tasks: [TaskQueue.ClosureWithResultNext], task: TaskQueue.ClosureNoResultNext) { 240 | tasks += [{ 241 | _, next in 242 | task() 243 | next(nil) 244 | }] 245 | } 246 | 247 | // MARK: Add tasks on a background queueu 248 | 249 | // 250 | // Add a task closure that doesn't take result/next params 251 | // The task gets executed on a low prio queueu 252 | // 253 | func +=~ (inout tasks: [TaskQueue.ClosureWithResultNext], task: TaskQueue.ClosureNoResultNext) { 254 | tasks += [{ 255 | _, next in 256 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), { 257 | task() 258 | next(nil) 259 | }) 260 | }] 261 | } 262 | 263 | // 264 | // The task gets executed on a low prio queueu 265 | // 266 | func +=~ (inout tasks: [TaskQueue.ClosureWithResultNext], task: TaskQueue.ClosureWithResultNext) { 267 | tasks += [{result, next in 268 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), { 269 | task(result, next) 270 | }) 271 | }] 272 | } 273 | 274 | // MARK: Add tasks on the main queue 275 | 276 | // 277 | // Add a task closure that doesn't take result/next params 278 | // The task gets executed on the main queue - update UI, etc. 279 | // 280 | func +=! (inout tasks: [TaskQueue.ClosureWithResultNext], task: TaskQueue.ClosureNoResultNext) { 281 | tasks += [{ 282 | _, next in 283 | dispatch_async(dispatch_get_main_queue(), { 284 | task() 285 | next(nil) 286 | }) 287 | }] 288 | } 289 | 290 | // 291 | // The task gets executed on the main queue - update UI, etc. 292 | // 293 | func +=! (inout tasks: [TaskQueue.ClosureWithResultNext], task: TaskQueue.ClosureWithResultNext) { 294 | tasks += [{ 295 | result, next in 296 | dispatch_async(dispatch_get_main_queue(), { 297 | task(result, next) 298 | }) 299 | }] 300 | } 301 | 302 | // MARK: Adding sub-queues 303 | 304 | // 305 | // Add a queue to the task list 306 | // 307 | func += (inout tasks: [TaskQueue.ClosureWithResultNext], queue: TaskQueue) { 308 | tasks += [{ 309 | _, next in 310 | queue.run { 311 | next(queue.lastResult) 312 | } 313 | }] 314 | } 315 | -------------------------------------------------------------------------------- /AutoMCServer/donate_paypal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hawkfalcon/AutoMCServer/cf30912ccbd85293c3b81043de1e4c353b489d11/AutoMCServer/donate_paypal.png -------------------------------------------------------------------------------- /AutoMCServer/server.properties: -------------------------------------------------------------------------------- 1 | generator-settings= 2 | op-permission-level=4 3 | resource-pack-hash= 4 | allow-nether={nether} 5 | level-name=world 6 | enable-query=false 7 | allow-flight=false 8 | announce-player-achievements=true 9 | server-port=25565 10 | max-world-size=29999984 11 | level-type={leveltype} 12 | enable-rcon=false 13 | force-gamemode=false 14 | level-seed= 15 | server-ip= 16 | network-compression-threshold=256 17 | max-build-height=256 18 | spawn-npcs={mobs} 19 | white-list={whitelist} 20 | spawn-animals={mobs} 21 | hardcore=false 22 | snooper-enabled=true 23 | online-mode=true 24 | resource-pack= 25 | pvp={pvp} 26 | difficulty={difficulty} 27 | enable-command-block=false 28 | gamemode={gamemode} 29 | player-idle-timeout=0 30 | max-players={maxplayers} 31 | max-tick-time=60000 32 | spawn-monsters={mobs} 33 | generate-structures=true 34 | view-distance=10 35 | motd={motd} 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AutoMCServer 2 | AutoBukkitServer, in Swift, for Spigot/Bukkit/Vanilla 3 | 4 | Images 5 | ------ 6 | 7 | #####Basic Configuration + Properties 8 | !["Basic Configuration"](http://i.imgur.com/WoY77Cv.png) 9 | !["Server Properties"](http://i.imgur.com/C4tWukt.png) 10 | #####Server Creation 11 | !["Simple GUI"](http://i.imgur.com/ccfivA4.png) 12 | !["Built in Console"](http://i.imgur.com/W9lTi6R.png) 13 | !["Helpful Links"](http://i.imgur.com/Vw6DZMv.png) 14 | -------------------------------------------------------------------------------- /SwiftHTTP-master/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by http://www.gitignore.io 2 | 3 | ### OSX ### 4 | .DS_Store 5 | .AppleDouble 6 | .LSOverride 7 | 8 | # Icon must end with two \r 9 | Icon 10 | 11 | 12 | # Thumbnails 13 | ._* 14 | 15 | # Files that might appear on external disk 16 | .Spotlight-V100 17 | .Trashes 18 | 19 | # Directories potentially created on remote AFP share 20 | .AppleDB 21 | .AppleDesktop 22 | Network Trash Folder 23 | Temporary Items 24 | .apdisk 25 | 26 | 27 | ### Swift ### 28 | # Xcode 29 | # 30 | build/ 31 | *.pbxuser 32 | !default.pbxuser 33 | *.mode1v3 34 | !default.mode1v3 35 | *.mode2v3 36 | !default.mode2v3 37 | *.perspectivev3 38 | !default.perspectivev3 39 | xcuserdata 40 | *.xccheckout 41 | *.moved-aside 42 | DerivedData 43 | *.hmap 44 | *.ipa 45 | *.xcuserstate 46 | 47 | # CocoaPods 48 | # 49 | # We recommend against adding the Pods directory to your .gitignore. However 50 | # you should judge for yourself, the pros and cons are mentioned at: 51 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 52 | # 53 | # Pods/ -------------------------------------------------------------------------------- /SwiftHTTP-master/HTTPRequestSerializer.swift: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // HTTPRequestSerializer.swift 4 | // 5 | // Created by Dalton Cherry on 6/3/14. 6 | // Copyright (c) 2014 Vluxe. All rights reserved. 7 | // 8 | ////////////////////////////////////////////////////////////////////////////////////////////////// 9 | 10 | import Foundation 11 | 12 | 13 | extension String { 14 | /** 15 | A simple extension to the String object to encode it for web request. 16 | 17 | :returns: Encoded version of of string it was called as. 18 | */ 19 | var escaped: String { 20 | return CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,self,"[].",":/?&=;+!@#$()',*",CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)) 21 | } 22 | } 23 | 24 | /// Default Serializer for serializing an object to an HTTP request. This applies to form serialization, parameter encoding, etc. 25 | public class HTTPRequestSerializer: NSObject { 26 | let contentTypeKey = "Content-Type" 27 | 28 | /// headers for the request. 29 | public var headers = Dictionary() 30 | /// encoding for the request. 31 | public var stringEncoding: UInt = NSUTF8StringEncoding 32 | /// Send request if using cellular network or not. Defaults to true. 33 | public var allowsCellularAccess = true 34 | /// If the request should handle cookies of not. Defaults to true. 35 | public var HTTPShouldHandleCookies = true 36 | /// If the request should use piplining or not. Defaults to false. 37 | public var HTTPShouldUsePipelining = false 38 | /// How long the timeout interval is. Defaults to 60 seconds. 39 | public var timeoutInterval: NSTimeInterval = 60 40 | /// Set the request cache policy. Defaults to UseProtocolCachePolicy. 41 | public var cachePolicy: NSURLRequestCachePolicy = NSURLRequestCachePolicy.UseProtocolCachePolicy 42 | /// Set the network service. Defaults to NetworkServiceTypeDefault. 43 | public var networkServiceType = NSURLRequestNetworkServiceType.NetworkServiceTypeDefault 44 | 45 | /// Initializes a new HTTPRequestSerializer Object. 46 | public override init() { 47 | super.init() 48 | } 49 | 50 | /** 51 | Creates a new NSMutableURLRequest object with configured options. 52 | 53 | :param: url The url you would like to make a request to. 54 | :param: method The HTTP method/verb for the request. 55 | 56 | :returns: A new NSMutableURLRequest with said options. 57 | */ 58 | func newRequest(url: NSURL, method: HTTPMethod) -> NSMutableURLRequest { 59 | var request = NSMutableURLRequest(URL: url, cachePolicy: cachePolicy, timeoutInterval: timeoutInterval) 60 | request.HTTPMethod = method.rawValue 61 | request.cachePolicy = self.cachePolicy 62 | request.timeoutInterval = self.timeoutInterval 63 | request.allowsCellularAccess = self.allowsCellularAccess 64 | request.HTTPShouldHandleCookies = self.HTTPShouldHandleCookies 65 | request.HTTPShouldUsePipelining = self.HTTPShouldUsePipelining 66 | request.networkServiceType = self.networkServiceType 67 | for (key,val) in self.headers { 68 | request.addValue(val, forHTTPHeaderField: key) 69 | } 70 | return request 71 | } 72 | 73 | /** 74 | Creates a new NSMutableURLRequest object with configured options. 75 | 76 | :param: url The url you would like to make a request to. 77 | :param: method The HTTP method/verb for the request. 78 | :param: parameters The parameters are HTTP parameters you would like to send. 79 | 80 | :returns: A new NSMutableURLRequest with said options or an error. 81 | */ 82 | func createRequest(url: NSURL, method: HTTPMethod, parameters: Dictionary?) -> (request: NSURLRequest, error: NSError?) { 83 | 84 | var request = newRequest(url, method: method) 85 | var isMulti = false 86 | //do a check for upload objects to see if we are multi form 87 | if let params = parameters { 88 | isMulti = isMultiForm(params) 89 | } 90 | if isMulti { 91 | if(method != .POST && method != .PUT) { 92 | request.HTTPMethod = HTTPMethod.POST.rawValue // you probably wanted a post 93 | } 94 | var boundary = "Boundary+\(arc4random())\(arc4random())" 95 | if parameters != nil { 96 | request.HTTPBody = dataFromParameters(parameters!,boundary: boundary) 97 | } 98 | if request.valueForHTTPHeaderField(contentTypeKey) == nil { 99 | request.setValue("multipart/form-data; boundary=\(boundary)", 100 | forHTTPHeaderField:contentTypeKey) 101 | } 102 | return (request,nil) 103 | } 104 | var queryString = "" 105 | if parameters != nil { 106 | queryString = self.stringFromParameters(parameters!) 107 | } 108 | if isURIParam(method) { 109 | var para = (request.URL!.query != nil) ? "&" : "?" 110 | var newUrl = "\(request.URL!.absoluteString!)" 111 | if countElements(queryString) > 0 { 112 | newUrl += "\(para)\(queryString)" 113 | } 114 | request.URL = NSURL(string: newUrl) 115 | } else { 116 | var charset = CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(self.stringEncoding)); 117 | if request.valueForHTTPHeaderField(contentTypeKey) == nil { 118 | request.setValue("application/x-www-form-urlencoded; charset=\(charset)", 119 | forHTTPHeaderField:contentTypeKey) 120 | } 121 | request.HTTPBody = queryString.dataUsingEncoding(self.stringEncoding) 122 | } 123 | return (request,nil) 124 | } 125 | 126 | ///check for multi form objects 127 | func isMultiForm(params: Dictionary) -> Bool { 128 | for (name,object: AnyObject) in params { 129 | if object is HTTPUpload { 130 | return true 131 | } else if let subParams = object as? Dictionary { 132 | if isMultiForm(subParams) { 133 | return true 134 | } 135 | } 136 | } 137 | return false 138 | } 139 | ///convert the parameter dict to its HTTP string representation 140 | func stringFromParameters(parameters: Dictionary) -> String { 141 | return join("&", map(serializeObject(parameters, key: nil), {(pair) in 142 | return pair.stringValue() 143 | })) 144 | } 145 | 146 | ///check if enum is a HTTPMethod that requires the params in the URL 147 | func isURIParam(method: HTTPMethod) -> Bool { 148 | if(method == .GET || method == .HEAD || method == .DELETE) { 149 | return true 150 | } 151 | return false 152 | } 153 | 154 | ///the method to serialized all the objects 155 | func serializeObject(object: AnyObject,key: String?) -> Array { 156 | var collect = Array() 157 | if let array = object as? Array { 158 | for nestedValue : AnyObject in array { 159 | collect.extend(self.serializeObject(nestedValue,key: "\(key!)[]")) 160 | } 161 | } else if let dict = object as? Dictionary { 162 | for (nestedKey, nestedObject: AnyObject) in dict { 163 | var newKey = key != nil ? "\(key!)[\(nestedKey)]" : nestedKey 164 | collect.extend(self.serializeObject(nestedObject,key: newKey)) 165 | } 166 | } else { 167 | collect.append(HTTPPair(value: object, key: key)) 168 | } 169 | return collect 170 | } 171 | 172 | //create a multi form data object of the parameters 173 | func dataFromParameters(parameters: Dictionary,boundary: String) -> NSData { 174 | var mutData = NSMutableData() 175 | var multiCRLF = "\r\n" 176 | var boundSplit = "\(multiCRLF)--\(boundary)\(multiCRLF)".dataUsingEncoding(self.stringEncoding)! 177 | var lastBound = "\(multiCRLF)--\(boundary)--\(multiCRLF)".dataUsingEncoding(self.stringEncoding)! 178 | mutData.appendData("--\(boundary)\(multiCRLF)".dataUsingEncoding(self.stringEncoding)!) 179 | 180 | let pairs = serializeObject(parameters, key: nil) 181 | let count = pairs.count-1 182 | var i = 0 183 | for pair in pairs { 184 | var append = true 185 | if let upload = pair.getUpload() { 186 | if let data = upload.data { 187 | mutData.appendData(multiFormHeader(pair.key, fileName: upload.fileName, 188 | type: upload.mimeType, multiCRLF: multiCRLF).dataUsingEncoding(self.stringEncoding)!) 189 | mutData.appendData(data) 190 | } else { 191 | append = false 192 | } 193 | } else { 194 | let str = "\(self.multiFormHeader(pair.key, fileName: nil, type: nil, multiCRLF: multiCRLF))\(pair.getValue())" 195 | mutData.appendData(str.dataUsingEncoding(self.stringEncoding)!) 196 | } 197 | if append { 198 | if i == count { 199 | mutData.appendData(lastBound) 200 | } else { 201 | mutData.appendData(boundSplit) 202 | } 203 | } 204 | i++ 205 | } 206 | return mutData 207 | } 208 | 209 | ///helper method to create the multi form headers 210 | func multiFormHeader(name: String, fileName: String?, type: String?, multiCRLF: String) -> String { 211 | var str = "Content-Disposition: form-data; name=\"\(name.escaped)\"" 212 | if fileName != nil { 213 | str += "; filename=\"\(fileName!)\"" 214 | } 215 | str += multiCRLF 216 | if type != nil { 217 | str += "Content-Type: \(type!)\(multiCRLF)" 218 | } 219 | str += multiCRLF 220 | return str 221 | } 222 | 223 | /// Creates key/pair of the parameters. 224 | class HTTPPair: NSObject { 225 | var value: AnyObject 226 | var key: String! 227 | 228 | init(value: AnyObject, key: String?) { 229 | self.value = value 230 | self.key = key 231 | } 232 | 233 | func getUpload() -> HTTPUpload? { 234 | return self.value as? HTTPUpload 235 | } 236 | 237 | func getValue() -> String { 238 | var val = "" 239 | if let str = self.value as? String { 240 | val = str 241 | } else if self.value.description != nil { 242 | val = self.value.description 243 | } 244 | return val 245 | } 246 | 247 | func stringValue() -> String { 248 | var val = getValue() 249 | if self.key == nil { 250 | return val.escaped 251 | } 252 | return "\(self.key.escaped)=\(val.escaped)" 253 | } 254 | 255 | } 256 | 257 | } 258 | 259 | /// JSON Serializer for serializing an object to an HTTP request. Same as HTTPRequestSerializer, expect instead of HTTP form encoding it does JSON. 260 | public class JSONRequestSerializer: HTTPRequestSerializer { 261 | 262 | /** 263 | Creates a new NSMutableURLRequest object with configured options. 264 | 265 | :param: url The url you would like to make a request to. 266 | :param: method The HTTP method/verb for the request. 267 | :param: parameters The parameters are HTTP parameters you would like to send. 268 | 269 | :returns: A new NSMutableURLRequest with said options or an error. 270 | */ 271 | public override func createRequest(url: NSURL, method: HTTPMethod, parameters: Dictionary?) -> (request: NSURLRequest, error: NSError?) { 272 | if self.isURIParam(method) { 273 | return super.createRequest(url, method: method, parameters: parameters) 274 | } 275 | var request = newRequest(url, method: method) 276 | var error: NSError? 277 | if parameters != nil { 278 | var charset = CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)); 279 | request.setValue("application/json; charset=\(charset)", forHTTPHeaderField: self.contentTypeKey) 280 | request.HTTPBody = NSJSONSerialization.dataWithJSONObject(parameters!, options: NSJSONWritingOptions(), error:&error) 281 | } 282 | return (request, error) 283 | } 284 | 285 | } 286 | -------------------------------------------------------------------------------- /SwiftHTTP-master/HTTPResponseSerializer.swift: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // HTTPResponseSerializer.swift 4 | // 5 | // Created by Dalton Cherry on 6/16/14. 6 | // Copyright (c) 2014 Vluxe. All rights reserved. 7 | // 8 | ////////////////////////////////////////////////////////////////////////////////////////////////// 9 | 10 | import Foundation 11 | 12 | /// This protocol provides a way to implement a custom serializer. 13 | public protocol HTTPResponseSerializer { 14 | /// This can be used if you want to have your data parsed/serialized into something instead of just a NSData blob. 15 | func responseObjectFromResponse(response: NSURLResponse, data: NSData) -> (object: AnyObject?, error: NSError?) 16 | } 17 | 18 | /// Serialize the data into a JSON object. 19 | public struct JSONResponseSerializer : HTTPResponseSerializer { 20 | /// Initializes a new JSONResponseSerializer Object. 21 | public init(){} 22 | 23 | /** 24 | Creates a HTTPOperation that can be scheduled on a NSOperationQueue. Called by convenience HTTP verb methods below. 25 | 26 | :param: response The NSURLResponse. 27 | :param: data The response data to be parsed into JSON. 28 | 29 | :returns: Returns a object from JSON data and an NSError if an error occured while parsing the data. 30 | */ 31 | public func responseObjectFromResponse(response: NSURLResponse, data: NSData) -> (object: AnyObject?, error: NSError?) { 32 | var error: NSError? 33 | let response: AnyObject? = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(), error: &error) 34 | return (response,error) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /SwiftHTTP-master/HTTPTask.swift: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // HTTPTask.swift 4 | // 5 | // Created by Dalton Cherry on 6/3/14. 6 | // Copyright (c) 2014 Vluxe. All rights reserved. 7 | // 8 | ////////////////////////////////////////////////////////////////////////////////////////////////// 9 | 10 | import Foundation 11 | 12 | /// HTTP Verbs. 13 | /// 14 | /// - GET: For GET requests. 15 | /// - POST: For POST requests. 16 | /// - PUT: For PUT requests. 17 | /// - HEAD: For HEAD requests. 18 | /// - DELETE: For DELETE requests. 19 | public enum HTTPMethod: String { 20 | case GET = "GET" 21 | case POST = "POST" 22 | case PUT = "PUT" 23 | case HEAD = "HEAD" 24 | case DELETE = "DELETE" 25 | } 26 | 27 | /// Object representation of a HTTP Response. 28 | public class HTTPResponse { 29 | /// The header values in HTTP response. 30 | public var headers: Dictionary? 31 | /// The mime type of the HTTP response. 32 | public var mimeType: String? 33 | /// The suggested filename for a downloaded file. 34 | public var suggestedFilename: String? 35 | /// The body or response data of the HTTP Response. 36 | public var responseObject: AnyObject? 37 | /// The status code of the HTTP Response. 38 | public var statusCode: Int? 39 | ///Returns the response as a string 40 | public func text() -> String? { 41 | if let d = self.responseObject as? NSData { 42 | return NSString(data: d, encoding: NSUTF8StringEncoding) 43 | } 44 | return nil 45 | } 46 | /// The URL of the HTTP Response. 47 | public var URL: NSURL? 48 | } 49 | 50 | /// Holds the blocks of the background task. 51 | class BackgroundBlocks { 52 | // these 2 only get used for background download/upload since they have to be delegate methods 53 | var success:((HTTPResponse) -> Void)? 54 | var failure:((NSError, HTTPResponse?) -> Void)? 55 | var progress:((Double) -> Void)? 56 | 57 | /** 58 | Initializes a new Background Block 59 | 60 | :param: success The block that is run on a sucessful HTTP Request. 61 | :param: failure The block that is run on a failed HTTP Request. 62 | :param: progress The block that is run on the progress of a HTTP Upload or Download. 63 | */ 64 | init(_ success: ((HTTPResponse) -> Void)?, _ failure: ((NSError, HTTPResponse?) -> Void)?,_ progress: ((Double) -> Void)?) { 65 | self.failure = failure 66 | self.success = success 67 | self.progress = progress 68 | } 69 | } 70 | 71 | /// Subclass of NSOperation for handling and scheduling HTTPTask on a NSOperationQueue. 72 | public class HTTPOperation : NSOperation { 73 | private var task: NSURLSessionDataTask! 74 | private var stopped = false 75 | private var running = false 76 | 77 | /// Controls if the task is finished or not. 78 | public var done = false 79 | 80 | //MARK: Subclassed NSOperation Methods 81 | 82 | /// Returns if the task is asynchronous or not. This should always be false. 83 | override public var asynchronous: Bool { 84 | return false 85 | } 86 | 87 | /// Returns if the task has been cancelled or not. 88 | override public var cancelled: Bool { 89 | return stopped 90 | } 91 | 92 | /// Returns if the task is current running. 93 | override public var executing: Bool { 94 | return running 95 | } 96 | 97 | /// Returns if the task is finished. 98 | override public var finished: Bool { 99 | return done 100 | } 101 | 102 | /// Returns if the task is ready to be run or not. 103 | override public var ready: Bool { 104 | return !running 105 | } 106 | 107 | /// Starts the task. 108 | override public func start() { 109 | super.start() 110 | stopped = false 111 | running = true 112 | done = false 113 | task.resume() 114 | } 115 | 116 | /// Cancels the running task. 117 | override public func cancel() { 118 | super.cancel() 119 | running = false 120 | stopped = true 121 | done = true 122 | task.cancel() 123 | } 124 | 125 | /// Sets the task to finished. 126 | public func finish() { 127 | self.willChangeValueForKey("isExecuting") 128 | self.willChangeValueForKey("isFinished") 129 | 130 | running = false 131 | done = true 132 | 133 | self.didChangeValueForKey("isExecuting") 134 | self.didChangeValueForKey("isFinished") 135 | } 136 | } 137 | 138 | /// Configures NSURLSession Request for HTTPOperation. Also provides convenience methods for easily running HTTP Request. 139 | public class HTTPTask : NSObject, NSURLSessionDelegate, NSURLSessionTaskDelegate { 140 | var backgroundTaskMap = Dictionary() 141 | //var sess: NSURLSession? 142 | 143 | public var baseURL: String? 144 | public var requestSerializer = HTTPRequestSerializer() 145 | public var responseSerializer: HTTPResponseSerializer? 146 | //This gets called on auth challenges. If nil, default handling is use. 147 | //Returning nil from this method will cause the request to be rejected and cancelled 148 | public var auth:((NSURLAuthenticationChallenge) -> NSURLCredential?)? 149 | 150 | //MARK: Public Methods 151 | 152 | /// A newly minted HTTPTask for your enjoyment. 153 | public override init() { 154 | super.init() 155 | } 156 | 157 | /** 158 | Creates a HTTPOperation that can be scheduled on a NSOperationQueue. Called by convenience HTTP verb methods below. 159 | 160 | :param: url The url you would like to make a request to. 161 | :param: method The HTTP method/verb for the request. 162 | :param: parameters The parameters are HTTP parameters you would like to send. 163 | :param: success The block that is run on a sucessful HTTP Request. 164 | :param: failure The block that is run on a failed HTTP Request. 165 | 166 | :returns: A freshly constructed HTTPOperation to add to your NSOperationQueue. 167 | */ 168 | public func create(url: String, method: HTTPMethod, parameters: Dictionary!, success:((HTTPResponse) -> Void)!, failure:((NSError, HTTPResponse?) -> Void)!) -> HTTPOperation? { 169 | 170 | let serialReq = createRequest(url, method: method, parameters: parameters) 171 | if serialReq.error != nil { 172 | if failure != nil { 173 | failure(serialReq.error!, nil) 174 | } 175 | return nil 176 | } 177 | let opt = HTTPOperation() 178 | let config = NSURLSessionConfiguration.defaultSessionConfiguration() 179 | let session = NSURLSession(configuration: config, delegate: self, delegateQueue: nil) 180 | let task = session.dataTaskWithRequest(serialReq.request, 181 | completionHandler: {(data: NSData!, response: NSURLResponse!, error: NSError!) -> Void in 182 | opt.finish() 183 | if error != nil { 184 | if failure != nil { 185 | failure(error, nil) 186 | } 187 | return 188 | } 189 | if data != nil { 190 | var responseObject: AnyObject = data 191 | if self.responseSerializer != nil { 192 | let resObj = self.responseSerializer!.responseObjectFromResponse(response, data: data) 193 | if resObj.error != nil { 194 | if failure != nil { 195 | failure(resObj.error!, nil) 196 | } 197 | return 198 | } 199 | if resObj.object != nil { 200 | responseObject = resObj.object! 201 | } 202 | } 203 | var extraResponse = HTTPResponse() 204 | if let hresponse = response as? NSHTTPURLResponse { 205 | extraResponse.headers = hresponse.allHeaderFields as? Dictionary 206 | extraResponse.mimeType = hresponse.MIMEType 207 | extraResponse.suggestedFilename = hresponse.suggestedFilename 208 | extraResponse.statusCode = hresponse.statusCode 209 | extraResponse.URL = hresponse.URL 210 | } 211 | extraResponse.responseObject = responseObject 212 | if extraResponse.statusCode > 299 { 213 | if failure != nil { 214 | failure(self.createError(extraResponse.statusCode!), extraResponse) 215 | } 216 | } else if success != nil { 217 | success(extraResponse) 218 | } 219 | } else if failure != nil { 220 | failure(error, nil) 221 | } 222 | }) 223 | opt.task = task 224 | return opt 225 | } 226 | 227 | /** 228 | Creates a HTTPOperation as a HTTP GET request and starts it for you. 229 | 230 | :param: url The url you would like to make a request to. 231 | :param: parameters The parameters are HTTP parameters you would like to send. 232 | :param: success The block that is run on a sucessful HTTP Request. 233 | :param: failure The block that is run on a failed HTTP Request. 234 | */ 235 | public func GET(url: String, parameters: Dictionary?, success:((HTTPResponse) -> Void)!, failure:((NSError, HTTPResponse?) -> Void)!) { 236 | var opt = self.create(url, method:.GET, parameters: parameters,success,failure) 237 | if opt != nil { 238 | opt!.start() 239 | } 240 | } 241 | 242 | /** 243 | Creates a HTTPOperation as a HTTP POST request and starts it for you. 244 | 245 | :param: url The url you would like to make a request to. 246 | :param: parameters The parameters are HTTP parameters you would like to send. 247 | :param: success The block that is run on a sucessful HTTP Request. 248 | :param: failure The block that is run on a failed HTTP Request. 249 | */ 250 | public func POST(url: String, parameters: Dictionary?, success:((HTTPResponse) -> Void)!, failure:((NSError, HTTPResponse?) -> Void)!) { 251 | var opt = self.create(url, method:.POST, parameters: parameters,success,failure) 252 | if opt != nil { 253 | opt!.start() 254 | } 255 | } 256 | 257 | /** 258 | Creates a HTTPOperation as a HTTP PUT request and starts it for you. 259 | 260 | :param: url The url you would like to make a request to. 261 | :param: parameters The parameters are HTTP parameters you would like to send. 262 | :param: success The block that is run on a sucessful HTTP Request. 263 | :param: failure The block that is run on a failed HTTP Request. 264 | */ 265 | public func PUT(url: String, parameters: Dictionary?, success:((HTTPResponse) -> Void)!, failure:((NSError, HTTPResponse?) -> Void)!) { 266 | var opt = self.create(url, method:.PUT, parameters: parameters,success,failure) 267 | if opt != nil { 268 | opt!.start() 269 | } 270 | } 271 | 272 | /** 273 | Creates a HTTPOperation as a HTTP DELETE request and starts it for you. 274 | 275 | :param: url The url you would like to make a request to. 276 | :param: parameters The parameters are HTTP parameters you would like to send. 277 | :param: success The block that is run on a sucessful HTTP Request. 278 | :param: failure The block that is run on a failed HTTP Request. 279 | */ 280 | public func DELETE(url: String, parameters: Dictionary?, success:((HTTPResponse) -> Void)!, failure:((NSError, HTTPResponse?) -> Void)!) { 281 | var opt = self.create(url, method:.DELETE, parameters: parameters,success,failure) 282 | if opt != nil { 283 | opt!.start() 284 | } 285 | } 286 | 287 | /** 288 | Creates a HTTPOperation as a HTTP HEAD request and starts it for you. 289 | 290 | :param: url The url you would like to make a request to. 291 | :param: parameters The parameters are HTTP parameters you would like to send. 292 | :param: success The block that is run on a sucessful HTTP Request. 293 | :param: failure The block that is run on a failed HTTP Request. 294 | */ 295 | public func HEAD(url: String, parameters: Dictionary?, success:((HTTPResponse) -> Void)!, failure:((NSError, HTTPResponse?) -> Void)!) { 296 | var opt = self.create(url, method:.HEAD, parameters: parameters,success,failure) 297 | if opt != nil { 298 | opt!.start() 299 | } 300 | } 301 | 302 | /** 303 | Creates and starts a HTTPOperation to download a file in the background. 304 | 305 | :param: url The url you would like to make a request to. 306 | :param: parameters The parameters are HTTP parameters you would like to send. 307 | :param: progress The progress returned in the progress block is between 0 and 1. 308 | :param: success The block that is run on a sucessful HTTP Request. The HTTPResponse responseObject object will be a fileURL. You MUST copy the fileURL return in HTTPResponse.responseObject to a new location before using it (e.g. your documents directory). 309 | :param: failure The block that is run on a failed HTTP Request. 310 | */ 311 | public func download(url: String, parameters: Dictionary?,progress:((Double) -> Void)!, success:((HTTPResponse) -> Void)!, failure:((NSError, HTTPResponse?) -> Void)!) -> NSURLSessionDownloadTask? { 312 | let serialReq = createRequest(url,method: .GET, parameters: parameters) 313 | if serialReq.error != nil { 314 | failure(serialReq.error!, nil) 315 | return nil 316 | } 317 | let ident = createBackgroundIdent() 318 | let config = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(ident) 319 | let session = NSURLSession(configuration: config, delegate: self, delegateQueue: nil) 320 | let task = session.downloadTaskWithRequest(serialReq.request) 321 | self.backgroundTaskMap[ident] = BackgroundBlocks(success,failure,progress) 322 | //this does not have to be queueable as Apple's background dameon *should* handle that. 323 | task.resume() 324 | return task 325 | } 326 | 327 | //TODO: not implemented yet. 328 | /// not implemented yet. 329 | public func uploadFile(url: String, parameters: Dictionary?, progress:((Double) -> Void)!, success:((HTTPResponse) -> Void)!, failure:((NSError) -> Void)!) -> Void { 330 | let serialReq = createRequest(url,method: .GET, parameters: parameters) 331 | if serialReq.error != nil { 332 | failure(serialReq.error!) 333 | return 334 | } 335 | let config = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(createBackgroundIdent()) 336 | let session = NSURLSession(configuration: config, delegate: self, delegateQueue: nil) 337 | //session.uploadTaskWithRequest(serialReq.request, fromData: nil) 338 | } 339 | 340 | //MARK: Private Helper Methods 341 | 342 | /** 343 | Creates and starts a HTTPOperation to download a file in the background. 344 | 345 | :param: url The url you would like to make a request to. 346 | :param: method The HTTP method/verb for the request. 347 | :param: parameters The parameters are HTTP parameters you would like to send. 348 | 349 | :returns: A NSURLRequest from configured requestSerializer. 350 | */ 351 | private func createRequest(url: String, method: HTTPMethod, parameters: Dictionary!) -> (request: NSURLRequest, error: NSError?) { 352 | var urlVal = url 353 | //probably should change the 'http' to something more generic 354 | if !url.hasPrefix("http") && self.baseURL != nil { 355 | var split = url.hasPrefix("/") ? "" : "/" 356 | urlVal = "\(self.baseURL!)\(split)\(url)" 357 | } 358 | if let u = NSURL(string: urlVal) { 359 | return self.requestSerializer.createRequest(u, method: method, parameters: parameters) 360 | } 361 | return (NSURLRequest(),createError(-1001)) 362 | } 363 | 364 | /** 365 | Creates a random string to use for the identifier of the background download/upload requests. 366 | 367 | :returns: Identifier String. 368 | */ 369 | private func createBackgroundIdent() -> String { 370 | let letters = "abcdefghijklmnopqurstuvwxyz" 371 | var str = "" 372 | for var i = 0; i < 14; i++ { 373 | let start = Int(arc4random() % 14) 374 | str.append(letters[advance(letters.startIndex,start)]) 375 | } 376 | return "com.vluxe.swifthttp.request.\(str)" 377 | } 378 | 379 | /** 380 | Creates a random string to use for the identifier of the background download/upload requests. 381 | 382 | :param: code Code for error. 383 | 384 | :returns: An NSError. 385 | */ 386 | private func createError(code: Int) -> NSError { 387 | var text = "An error occured" 388 | if code == 404 { 389 | text = "Page not found" 390 | } else if code == 401 { 391 | text = "Access denied" 392 | } else if code == -1001 { 393 | text = "Invalid URL" 394 | } 395 | return NSError(domain: "HTTPTask", code: code, userInfo: [NSLocalizedDescriptionKey: text]) 396 | } 397 | 398 | 399 | /** 400 | Creates a random string to use for the identifier of the background download/upload requests. 401 | 402 | :param: identifier The identifier string. 403 | 404 | :returns: An NSError. 405 | */ 406 | private func cleanupBackground(identifier: String) { 407 | self.backgroundTaskMap.removeValueForKey(identifier) 408 | } 409 | 410 | //MARK: NSURLSession Delegate Methods 411 | 412 | /// Method for authentication challenge. 413 | public func URLSession(session: NSURLSession, task: NSURLSessionTask, didReceiveChallenge challenge: NSURLAuthenticationChallenge, completionHandler: (NSURLSessionAuthChallengeDisposition, NSURLCredential!) -> Void) { 414 | if let a = auth { 415 | let cred = a(challenge) 416 | if let c = cred { 417 | completionHandler(.UseCredential, c) 418 | return 419 | } 420 | completionHandler(.RejectProtectionSpace, nil) 421 | return 422 | } 423 | completionHandler(.PerformDefaultHandling, nil) 424 | } 425 | 426 | /// Called when the background task failed. 427 | func URLSession(session: NSURLSession!, task: NSURLSessionTask!, didCompleteWithError error: NSError!) { 428 | if error != nil { 429 | let blocks = self.backgroundTaskMap[session.configuration.identifier] 430 | if blocks?.failure != nil { //Swift bug. Can't use && with block (radar: 17469794) 431 | blocks?.failure!(error, nil) 432 | cleanupBackground(session.configuration.identifier) 433 | } 434 | } 435 | } 436 | 437 | /// The background download finished and reports the url the data was saved to. 438 | func URLSession(session: NSURLSession!, downloadTask: NSURLSessionDownloadTask!, didFinishDownloadingToURL location: NSURL!) { 439 | let blocks = self.backgroundTaskMap[session.configuration.identifier] 440 | if blocks?.success != nil { 441 | var resp = HTTPResponse() 442 | if let hresponse = downloadTask.response as? NSHTTPURLResponse { 443 | resp.headers = hresponse.allHeaderFields as? Dictionary 444 | resp.mimeType = hresponse.MIMEType 445 | resp.suggestedFilename = hresponse.suggestedFilename 446 | resp.statusCode = hresponse.statusCode 447 | resp.URL = hresponse.URL 448 | } 449 | resp.responseObject = location 450 | if resp.statusCode > 299 { 451 | if blocks?.failure != nil { 452 | blocks?.failure!(self.createError(resp.statusCode!), resp) 453 | } 454 | return 455 | } 456 | blocks?.success!(resp) 457 | cleanupBackground(session.configuration.identifier) 458 | } 459 | } 460 | 461 | /// Will report progress of background download 462 | func URLSession(session: NSURLSession!, downloadTask: NSURLSessionDownloadTask!, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) { 463 | let increment = 100.0/Double(totalBytesExpectedToWrite) 464 | var current = (increment*Double(totalBytesWritten))*0.01 465 | if current > 1 { 466 | current = 1; 467 | } 468 | let blocks = self.backgroundTaskMap[session.configuration.identifier] 469 | if blocks?.progress != nil { 470 | blocks?.progress!(current) 471 | } 472 | } 473 | 474 | /// The background download finished, don't have to really do anything. 475 | func URLSessionDidFinishEventsForBackgroundURLSession(session: NSURLSession!) { 476 | } 477 | 478 | //TODO: not implemented yet. 479 | /// not implemented yet. The background upload finished and reports the response data (if any). 480 | func URLSession(session: NSURLSession!, dataTask: NSURLSessionDataTask!, didReceiveData data: NSData!) { 481 | //add upload finished logic 482 | } 483 | 484 | //TODO: not implemented yet. 485 | /// not implemented yet. 486 | func URLSession(session: NSURLSession!, task: NSURLSessionTask!, didSendBodyData bytesSent: Int64, totalBytesSent: Int64, totalBytesExpectedToSend: Int64) { 487 | //add progress block logic 488 | } 489 | 490 | //TODO: not implemented yet. 491 | /// not implemented yet. 492 | func URLSession(session: NSURLSession!, downloadTask: NSURLSessionDownloadTask!, didResumeAtOffset fileOffset: Int64, expectedTotalBytes: Int64) { 493 | 494 | } 495 | } 496 | -------------------------------------------------------------------------------- /SwiftHTTP-master/HTTPUpload.swift: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // HTTPUpload.swift 4 | // 5 | // Created by Dalton Cherry on 6/5/14. 6 | // Copyright (c) 2014 Vluxe. All rights reserved. 7 | // 8 | ////////////////////////////////////////////////////////////////////////////////////////////////// 9 | 10 | import Foundation 11 | 12 | #if os(iOS) 13 | import MobileCoreServices 14 | #endif 15 | 16 | 17 | /// Object representation of a HTTP File Upload. 18 | public class HTTPUpload: NSObject { 19 | var fileUrl: NSURL? { 20 | didSet { 21 | updateMimeType() 22 | loadData() 23 | } 24 | } 25 | var mimeType: String? 26 | var data: NSData? 27 | var fileName: String? 28 | 29 | /// Tries to determine the mime type from the fileUrl extension. 30 | func updateMimeType() { 31 | if mimeType == nil && fileUrl != nil { 32 | var UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileUrl?.pathExtension as NSString?, nil); 33 | var str = UTTypeCopyPreferredTagWithClass(UTI.takeUnretainedValue(), kUTTagClassMIMEType); 34 | if (str == nil) { 35 | mimeType = "application/octet-stream"; 36 | } else { 37 | mimeType = str.takeUnretainedValue() as NSString 38 | } 39 | } 40 | } 41 | 42 | /// loads the fileUrl into memory. 43 | func loadData() { 44 | if let url = fileUrl { 45 | self.fileName = url.lastPathComponent 46 | self.data = NSData.dataWithContentsOfMappedFile(url.path!) as? NSData 47 | } 48 | } 49 | 50 | /// Initializes a new HTTPUpload Object. 51 | public override init() { 52 | super.init() 53 | } 54 | 55 | /** 56 | Initializes a new HTTPUpload Object with a fileUrl. The fileName and mimeType will be infered. 57 | 58 | :param: fileUrl The fileUrl is a standard url path to a file. 59 | */ 60 | public convenience init(fileUrl: NSURL) { 61 | self.init() 62 | self.fileUrl = fileUrl 63 | updateMimeType() 64 | loadData() 65 | } 66 | 67 | /** 68 | Initializes a new HTTPUpload Object with a data blob of a file. The fileName and mimeType will be infered if none are provided. 69 | 70 | :param: data The data is a NSData representation of a file's data. 71 | :param: fileName The fileName is just that. The file's name. 72 | :param: mimeType The mimeType is just that. The mime type you would like the file to uploaded as. 73 | */ 74 | ///upload a file from a a data blob. Must add a filename and mimeType as that can't be infered from the data 75 | public convenience init(data: NSData, fileName: String, mimeType: String) { 76 | self.init() 77 | self.data = data 78 | self.fileName = fileName 79 | self.mimeType = mimeType 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /SwiftHTTP-master/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.vluxe.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /SwiftHTTP-master/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /SwiftHTTP-master/README.md: -------------------------------------------------------------------------------- 1 | SwiftHTTP 2 | ========= 3 | 4 | SwiftHTTP is a thin wrapper around NSURLSession in Swift to simplify HTTP requests. 5 | 6 | ## Features 7 | 8 | - Convenient Closure APIs 9 | - NSOperationQueue Support 10 | - Parameter Encoding 11 | - Custom Response Serializer 12 | - Builtin JSON Response Serialization 13 | - Upload/Download with Progress Closure 14 | - Concise Codebase. Under 1000 LOC 15 | 16 | Full article here: [http://vluxe.io/swifthttp.html](http://vluxe.io/swifthttp.html) 17 | 18 | First thing is to import the framework. See the Installation instructions on how to add the framework to your project. 19 | 20 | ```swift 21 | import SwiftHTTP 22 | ``` 23 | 24 | ## Examples 25 | 26 | ### GET 27 | 28 | The most basic request. By default an NSData object will be returned for the response. 29 | ```swift 30 | var request = HTTPTask() 31 | request.GET("http://vluxe.io", parameters: nil, success: {(response: HTTPResponse) in 32 | if let data = response.responseObject as? NSData { 33 | let str = NSString(data: data, encoding: NSUTF8StringEncoding) 34 | println("response: \(str)") //prints the HTML of the page 35 | } 36 | },failure: {(error: NSError, response: HTTPResponse?) in 37 | println("error: \(error)") 38 | }) 39 | ``` 40 | 41 | We can also add parameters as with standard container objects and they will be properly serialized to their respective HTTP equivalent. 42 | 43 | ```swift 44 | var request = HTTPTask() 45 | request.GET("http://google.com", parameters: ["param": "param1", "array": ["first array element","second","third"], "num": 23], success: {(response: HTTPResponse) in 46 | println("response: \(response.responseObject!)") 47 | },failure: {(error: NSError, response: HTTPResponse?) in 48 | println("error: \(error)") 49 | }) 50 | ``` 51 | 52 | The `HTTPResponse` contains all the common HTTP response data, such as the responseObject of the data and the headers of the response. 53 | 54 | ### POST 55 | 56 | A POST request is just as easy as a GET. 57 | 58 | ```swift 59 | var request = HTTPTask() 60 | //we have to add the explicit type, else the wrong type is inferred. See the vluxe.io article for more info. 61 | let params: Dictionary = ["param": "param1", "array": ["first array element","second","third"], "num": 23, "dict": ["someKey": "someVal"]] 62 | request.POST("http://domain.com/create", parameters: params, success: {(response: HTTPResponse) in 63 | 64 | },failure: {(error: NSError, response: HTTPResponse?) in 65 | 66 | }) 67 | ``` 68 | 69 | ### PUT 70 | 71 | PUT works the same as post. The example also include a file upload to do a multi form request. 72 | 73 | ```swift 74 | let fileUrl = NSURL.fileURLWithPath("/Users/dalton/Desktop/file")! 75 | var request = HTTPTask() 76 | request.PUT("http://domain.com/1", parameters: ["param": "hi", "something": "else", "key": "value","file": HTTPUpload(fileUrl: fileUrl!)], success: {(response: HTTPResponse) in 77 | //do stuff 78 | },failure: {(error: NSError, response: HTTPResponse?) in 79 | //error out on stuff 80 | }) 81 | ``` 82 | 83 | The HTTPUpload object is use to represent files on disk or in memory file as data. 84 | 85 | ### DELETE 86 | 87 | DELETE works the same as the GET. 88 | 89 | ```swift 90 | var request = HTTPTask() 91 | request.DELETE("http://domain.com/1", parameters: nil, success: {(response: HTTPResponse) in 92 | println("DELETE was successful!") 93 | },failure: {(error: NSError, response: HTTPResponse?) in 94 | println("print the error: \(error)") 95 | }) 96 | ``` 97 | 98 | ### HEAD 99 | 100 | HEAD works the same as the GET. 101 | 102 | ```swift 103 | var request = HTTPTask() 104 | request.HEAD("http://domain.com/image.png", parameters: nil, success: {(response: HTTPResponse) in 105 | println("The file does exist!") 106 | },failure: {(error: NSError, response: HTTPResponse?) in 107 | println("File not found: \(error)") 108 | }) 109 | ``` 110 | 111 | ### Download 112 | 113 | The download method uses the background download functionality of NSURLSession. It also has a progress closure to report the progress of the download. 114 | 115 | ```swift 116 | var request = HTTPTask() 117 | let downloadTask = request.download("http://vluxe.io/assets/images/logo.png", parameters: nil, progress: {(complete: Double) in 118 | println("percent complete: \(complete)") 119 | }, success: {(response: HTTPResponse) in 120 | println("download finished!") 121 | if response.responseObject != nil { 122 | //we MUST copy the file from its temp location to a permanent location. 123 | if let url = response.responseObject as? NSURL { 124 | if let path = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first as? String { 125 | if let fileName = response.suggestedFilename { 126 | if let newPath = NSURL(fileURLWithPath: "\(path)/\(fileName)") { 127 | let fileManager = NSFileManager.defaultManager() 128 | fileManager.removeItemAtURL(newPath, error: nil) 129 | fileManager.moveItemAtURL(url, toURL: newPath, error:nil) 130 | } 131 | } 132 | } 133 | } 134 | } 135 | 136 | } ,failure: {(error: NSError, response: HTTPResponse?) in 137 | println("failure") 138 | }) 139 | ``` 140 | 141 | Cancel the download. 142 | 143 | ```swift 144 | if let t = downloadTask { 145 | t.cancel() 146 | } 147 | ``` 148 | 149 | ### Upload 150 | 151 | File uploads can be done using the `HTTPUpload` object. All files to upload should be wrapped in a HTTPUpload object and added as a parameter. 152 | 153 | ```swift 154 | let fileUrl = NSURL.fileURLWithPath("/Users/dalton/Desktop/file")! 155 | var request = HTTPTask() 156 | request.POST("http://domain.com/1/upload", parameters: ["aParam": "aValue","file": HTTPUpload(fileUrl: fileUrl!)], success: {(response: HTTPResponse) in 157 | //do stuff 158 | },failure: {(error: NSError, response: HTTPResponse?) in 159 | //error out on stuff 160 | }) 161 | ``` 162 | `HTTPUpload` comes in both a on disk fileUrl version and a NSData version. 163 | 164 | ### Custom Headers 165 | 166 | Custom HTTP headers can be add to a request via the requestSerializer. 167 | 168 | ```swift 169 | var request = HTTPTask() 170 | request.requestSerializer = HTTPRequestSerializer() 171 | request.requestSerializer.headers["someKey"] = "SomeValue" //example of adding a header value 172 | ``` 173 | 174 | ### Authentication 175 | 176 | SwiftHTTP supports authentication through [NSURLCredential](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURLCredential_Class/Reference/Reference.html). Currently only Basic Auth and Digest Auth have been tested. 177 | 178 | ```swift 179 | var request = HTTPTask() 180 | //the auth closures will continually be called until a successful auth or rejection 181 | var attempted = false 182 | request.auth = {(challenge: NSURLAuthenticationChallenge) in 183 | if !attempted { 184 | attempted = true 185 | return NSURLCredential(user: "user", password: "passwd", persistence: .ForSession) 186 | } 187 | return nil //auth failed, nil causes the request to be properly cancelled. 188 | } 189 | request.GET("http://httpbin.org/basic-auth/user/passwd", parameters: nil, success: {(response: HTTPResponse) in 190 | if response.responseObject != nil { 191 | println("winning!") 192 | } 193 | 194 | }, failure: {(error: NSError, response: HTTPResponse?) in 195 | println("failure.") 196 | }) 197 | ``` 198 | 199 | Self-Signed Certificate example: 200 | 201 | ```swift 202 | var request = HTTPTask() 203 | var attempted = false 204 | request.auth = {(challenge: NSURLAuthenticationChallenge) in 205 | if !attempted { 206 | attempted = true 207 | return NSURLCredential(forTrust: challenge.protectionSpace.serverTrust) 208 | } 209 | return nil 210 | } 211 | request.GET("https://somedomain.com", parameters: nil, success: {(response: HTTPResponse) in 212 | if response.responseObject != nil { 213 | println("winning!") 214 | } 215 | 216 | }, failure: {(error: NSError, response: HTTPResponse?) in 217 | println("failure.") 218 | }) 219 | ``` 220 | 221 | 222 | ### BaseURL 223 | 224 | SwiftHTTP also supports use a request object with a baseURL. This is super handy for RESTFul API interaction. 225 | 226 | ```swift 227 | var request = HTTPTask() 228 | request.baseURL = "http://api.someserver.com/1" 229 | request.GET("/users", parameters: ["key": "value"], success: {(response: HTTPResponse) in 230 | println("Got data from http://api.someserver.com/1/users") 231 | },failure: {(error: NSError, response: HTTPResponse?) in 232 | println("print the error: \(error)") 233 | }) 234 | 235 | request.POST("/users", parameters: ["key": "updatedVale"], success: {(response: HTTPResponse) in 236 | println("Got data from http://api.someserver.com/1/users") 237 | },failure: {(error: NSError, response: HTTPResponse?) in 238 | println("print the error: \(error)") 239 | }) 240 | 241 | request.GET("/resources", parameters: ["key": "value"], success: {(response: HTTPResponse) in 242 | println("Got data from http://api.someserver.com/1/resources") 243 | },failure: {(error: NSError, response: HTTPResponse?) in 244 | println("print the error: \(error)") 245 | }) 246 | ``` 247 | 248 | ### Operation Queue 249 | 250 | Operation queues are also supported in SwiftHTTP. 251 | 252 | ```swift 253 | let operationQueue = NSOperationQueue() 254 | operationQueue.maxConcurrentOperationCount = 2 255 | var request = HTTPTask() 256 | var opt = request.create("http://vluxe.io", method: .GET, parameters: nil, success: {(response: HTTPResponse) in 257 | if let data = response.responseObject as? NSData { 258 | let str = NSString(data: data, encoding: NSUTF8StringEncoding) 259 | println("response: \(str)") //prints the HTML of the page 260 | } 261 | },failure: {(error: NSError, response: HTTPResponse?) in 262 | println("error: \(error)") 263 | }) 264 | if let o = opt { 265 | operationQueue.addOperation(o) 266 | } 267 | ``` 268 | 269 | ### Cancel 270 | 271 | Let's say you want to cancel this request a little later, simple use the operationQueue cancel. 272 | 273 | ```swift 274 | if let o = opt { 275 | o.cancel() 276 | } 277 | ``` 278 | 279 | ### Serializers 280 | 281 | Request parameters and request responses can also be serialized as needed. By default request are serialized using standard HTTP form encoding. A JSON request and response serializer are provided as well. It is also very simple to create custom serializer by subclass a request or response serializer 282 | 283 | ```swift 284 | var request = HTTPTask() 285 | //The parameters will be encoding as JSON data and sent. 286 | request.requestSerializer = JSONRequestSerializer() 287 | //The expected response will be JSON and be converted to an object return by NSJSONSerialization instead of a NSData. 288 | request.responseSerializer = JSONResponseSerializer() 289 | request.GET("http://vluxe.io", parameters: nil, success: {(response: HTTPResponse) in 290 | if let dict = response.responseObject as? Dictionary { 291 | println("example of the JSON key: \(dict["key"])") 292 | println("print the whole response: \(response)") 293 | } 294 | },failure: {(error: NSError, response: HTTPResponse?) in 295 | println("error: \(error)") 296 | }) 297 | ``` 298 | 299 | ## Client/Server Example 300 | 301 | This is a full example swiftHTTP in action. First here is a quick web server in Go. 302 | 303 | ```go 304 | package main 305 | 306 | import ( 307 | "fmt" 308 | "log" 309 | "net/http" 310 | ) 311 | 312 | func main() { 313 | http.HandleFunc("/bar", func(w http.ResponseWriter, r *http.Request) { 314 | log.Println("got a web request") 315 | fmt.Println("header: ", r.Header.Get("someKey")) 316 | w.Write([]byte("{\"status\": \"ok\"}")) 317 | }) 318 | 319 | log.Fatal(http.ListenAndServe(":8080", nil)) 320 | } 321 | ``` 322 | 323 | Now for the request: 324 | 325 | ```swift 326 | //The object that will represent our response. More Info in the JSON Parsing section below. 327 | struct Status : JSONJoy { 328 | var status: String? 329 | init() { 330 | 331 | } 332 | init(_ decoder: JSONDecoder) { 333 | status = decoder["status"].string 334 | } 335 | } 336 | //The request 337 | var request = HTTPTask() 338 | request.requestSerializer = HTTPRequestSerializer() 339 | request.requestSerializer.headers["someKey"] = "SomeValue" //example of adding a header value 340 | request.responseSerializer = JSONResponseSerializer() 341 | request.GET("http://localhost:8080/bar", parameters: nil, success: {(response: HTTPResponse) in 342 | if response.responseObject != nil { 343 | let resp = Status(JSONDecoder(response.responseObject!)) 344 | println("status is: \(resp.status)") 345 | } 346 | }, failure: {(error: NSError, response: HTTPResponse?) in 347 | println("got an error: \(error)") 348 | }) 349 | ``` 350 | 351 | ## JSON Parsing 352 | 353 | Swift has a lot of great JSON parsing libraries, but I made one specifically designed for JSON to object serialization. 354 | 355 | [JSONJoy-Swift](https://github.com/daltoniam/JSONJoy-Swift) 356 | 357 | ## Requirements 358 | 359 | SwiftHTTP works with iOS 7/OSX 10.9 or above. It is recommended to use iOS 8/10.10 or above for Cocoapods/framework support. 360 | 361 | ## Installation 362 | 363 | ### Cocoapods 364 | 365 | ### [CocoaPods](http://cocoapods.org/) 366 | At this time, Cocoapods support for Swift frameworks is supported in a [pre-release](http://blog.cocoapods.org/Pod-Authors-Guide-to-CocoaPods-Frameworks/). 367 | 368 | To use SwiftHTTP in your project add the following 'Podfile' to your project 369 | 370 | source 'https://github.com/CocoaPods/Specs.git' 371 | 372 | xcodeproj 'YourProjectName.xcodeproj' 373 | platform :ios, '8.0' 374 | 375 | pod 'SwiftHTTP', :git => "https://github.com/daltoniam/SwiftHTTP.git", :tag => "0.9.1" 376 | 377 | target 'YourProjectNameTests' do 378 | pod 'SwiftHTTP', :git => "https://github.com/daltoniam/SwiftHTTP.git", :tag => "0.9.1" 379 | end 380 | 381 | Then run: 382 | 383 | pod install 384 | 385 | #### Updating the Cocoapod 386 | You can validate SwiftHTTP.podspec using: 387 | 388 | pod spec lint SwiftHTTP.podspec 389 | 390 | This should be tested with a sample project before releasing it. This can be done by adding the following line to a ```Podfile```: 391 | 392 | pod 'SwiftHTTP', :git => 'https://github.com/username/SwiftHTTP.git' 393 | 394 | Then run: 395 | 396 | pod install 397 | 398 | If all goes well you are ready to release. First, create a tag and push: 399 | 400 | git tag 'version' 401 | git push --tags 402 | 403 | Once the tag is available you can send the library to the Specs repo. For this you'll have to follow the instructions in [Getting Setup with Trunk](http://guides.cocoapods.org/making/getting-setup-with-trunk.html). 404 | 405 | pod trunk push SwiftHTTP.podspec 406 | 407 | 408 | 409 | ### Carthage 410 | 411 | Check out the [Carthage](https://github.com/Carthage/Carthage) docs on how to add a install. The `SwiftHTTP` framework is already setup with shared schemes. 412 | 413 | [Carthage Install](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application) 414 | 415 | ### Rogue 416 | 417 | First see the [installation docs](https://github.com/acmacalister/Rogue) for how to install Rogue. 418 | 419 | To install SwiftLog run the command below in the directory you created the rogue file. 420 | 421 | ``` 422 | rogue add https://github.com/daltoniam/SwiftHTTP 423 | ``` 424 | 425 | Next open the `libs` folder and add the `SwiftHTTP.xcodeproj` to your Xcode project. Once that is complete, in your "Build Phases" add the `SwiftHTTP.framework` to your "Link Binary with Libraries" phase. Make sure to add the `libs` folder to your `.gitignore` file. 426 | 427 | ### Other 428 | 429 | Simply grab the framework (either via git submodule or another package manager). 430 | 431 | Add the `SwiftHTTP.xcodeproj` to your Xcode project. Once that is complete, in your "Build Phases" add the `SwiftHTTP.framework` to your "Link Binary with Libraries" phase. 432 | 433 | ### Add Copy Frameworks Phase 434 | 435 | If you are running this in an OSX app or on a physical iOS device you will need to make sure you add the `SwiftHTTP.framework` or `SwiftHTTPOSX.framework` to be included in your app bundle. To do this, in Xcode, navigate to the target configuration window by clicking on the blue project icon, and selecting the application target under the "Targets" heading in the sidebar. In the tab bar at the top of that window, open the "Build Phases" panel. Expand the "Link Binary with Libraries" group, and add `SwiftHTTP.framework` or `SwiftHTTPOSX.framework` depending on if you are building an iOS or OSX app. Click on the + button at the top left of the panel and select "New Copy Files Phase". Rename this new phase to "Copy Frameworks", set the "Destination" to "Frameworks", and add `SwiftHTTP.framework` or `SwiftHTTPOSX.framework` respectively. 436 | 437 | ## TODOs 438 | 439 | - [ ] Complete Docs 440 | - [ ] Add Unit Tests 441 | - [ ] Add Example Project 442 | 443 | ## License 444 | 445 | SwiftHTTP is licensed under the Apache v2 License. 446 | 447 | ## Contact 448 | 449 | ### Dalton Cherry 450 | * https://github.com/daltoniam 451 | * http://twitter.com/daltoniam 452 | * http://daltoniam.com 453 | -------------------------------------------------------------------------------- /SwiftHTTP-master/SwiftHTTP.h: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftHTTP.h 3 | // SwiftHTTP 4 | // 5 | // Created by Austin Cherry on 9/16/14. 6 | // Copyright (c) 2014 Vluxe. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for SwiftHTTP. 12 | FOUNDATION_EXPORT double SwiftHTTPVersionNumber; 13 | 14 | //! Project version string for SwiftHTTP. 15 | FOUNDATION_EXPORT const unsigned char SwiftHTTPVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /SwiftHTTP-master/SwiftHTTP.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "SwiftHTTP" 3 | s.version = "0.9.2" 4 | s.summary = "Thin wrapper around NSURLSession in Swift. Simplifies HTTP requests." 5 | s.homepage = "https://github.com/daltoniam/SwiftHTTP" 6 | s.license = 'Apache License, Version 2.0' 7 | s.author = {'Dalton Cherry' => 'http://daltoniam.com'} 8 | s.source = { :git => 'https://github.com/daltoniam/SwiftHTTP.git', :tag => "#{s.version}"} 9 | s.social_media_url = 'http://twitter.com/daltoniam' 10 | s.ios.deployment_target = '8.0' 11 | s.osx.deployment_target = '10.9' 12 | s.source_files = '*.swift' 13 | s.requires_arc = 'true' 14 | end 15 | -------------------------------------------------------------------------------- /SwiftHTTP-master/SwiftHTTP.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 6BFD903719C8D95C00DD99B6 /* HTTPUpload.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BFD903219C8D95C00DD99B6 /* HTTPUpload.swift */; }; 11 | 6BFD903819C8D95C00DD99B6 /* SwiftHTTP.h in Headers */ = {isa = PBXBuildFile; fileRef = 6BFD903319C8D95C00DD99B6 /* SwiftHTTP.h */; settings = {ATTRIBUTES = (Public, ); }; }; 12 | 6BFD904019C8D9A000DD99B6 /* SwiftHTTPTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BFD903D19C8D98000DD99B6 /* SwiftHTTPTests.swift */; }; 13 | 6BFD904319C928D900DD99B6 /* HTTPRequestSerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BFD902F19C8D95C00DD99B6 /* HTTPRequestSerializer.swift */; }; 14 | 6BFD904419C928D900DD99B6 /* HTTPResponseSerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BFD903019C8D95C00DD99B6 /* HTTPResponseSerializer.swift */; }; 15 | 6BFD904519C928D900DD99B6 /* HTTPTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BFD903119C8D95C00DD99B6 /* HTTPTask.swift */; }; 16 | D958026419E6EEEB003C8218 /* SwiftHTTP.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D958025919E6EEEB003C8218 /* SwiftHTTP.framework */; }; 17 | D958027219E6EF2B003C8218 /* SwiftHTTPTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BFD903D19C8D98000DD99B6 /* SwiftHTTPTests.swift */; }; 18 | D958027319E6EF4B003C8218 /* HTTPRequestSerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BFD902F19C8D95C00DD99B6 /* HTTPRequestSerializer.swift */; }; 19 | D958027419E6EF4B003C8218 /* HTTPResponseSerializer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BFD903019C8D95C00DD99B6 /* HTTPResponseSerializer.swift */; }; 20 | D958027519E6EF4B003C8218 /* HTTPTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BFD903119C8D95C00DD99B6 /* HTTPTask.swift */; }; 21 | D958027619E6EF4B003C8218 /* HTTPUpload.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BFD903219C8D95C00DD99B6 /* HTTPUpload.swift */; }; 22 | D958027719E6EF89003C8218 /* SwiftHTTP.h in Headers */ = {isa = PBXBuildFile; fileRef = 6BFD903319C8D95C00DD99B6 /* SwiftHTTP.h */; settings = {ATTRIBUTES = (Public, ); }; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXContainerItemProxy section */ 26 | D958026519E6EEEB003C8218 /* PBXContainerItemProxy */ = { 27 | isa = PBXContainerItemProxy; 28 | containerPortal = 6BFD900D19C8D8B500DD99B6 /* Project object */; 29 | proxyType = 1; 30 | remoteGlobalIDString = D958025819E6EEEB003C8218; 31 | remoteInfo = SwiftHTTPOSX; 32 | }; 33 | /* End PBXContainerItemProxy section */ 34 | 35 | /* Begin PBXFileReference section */ 36 | 6BFD901619C8D8B500DD99B6 /* SwiftHTTP.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftHTTP.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 37 | 6BFD902119C8D8B500DD99B6 /* SwiftHTTPTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftHTTPTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 38 | 6BFD902F19C8D95C00DD99B6 /* HTTPRequestSerializer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPRequestSerializer.swift; sourceTree = SOURCE_ROOT; }; 39 | 6BFD903019C8D95C00DD99B6 /* HTTPResponseSerializer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPResponseSerializer.swift; sourceTree = SOURCE_ROOT; }; 40 | 6BFD903119C8D95C00DD99B6 /* HTTPTask.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPTask.swift; sourceTree = SOURCE_ROOT; }; 41 | 6BFD903219C8D95C00DD99B6 /* HTTPUpload.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPUpload.swift; sourceTree = SOURCE_ROOT; }; 42 | 6BFD903319C8D95C00DD99B6 /* SwiftHTTP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SwiftHTTP.h; sourceTree = SOURCE_ROOT; }; 43 | 6BFD903919C8D96500DD99B6 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; }; 44 | 6BFD903C19C8D98000DD99B6 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Tests/Info.plist; sourceTree = ""; }; 45 | 6BFD903D19C8D98000DD99B6 /* SwiftHTTPTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftHTTPTests.swift; path = Tests/SwiftHTTPTests.swift; sourceTree = ""; }; 46 | D958025919E6EEEB003C8218 /* SwiftHTTP.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftHTTP.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 47 | D958026319E6EEEB003C8218 /* SwiftHTTPOSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftHTTPOSXTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 48 | /* End PBXFileReference section */ 49 | 50 | /* Begin PBXFrameworksBuildPhase section */ 51 | 6BFD901219C8D8B500DD99B6 /* Frameworks */ = { 52 | isa = PBXFrameworksBuildPhase; 53 | buildActionMask = 2147483647; 54 | files = ( 55 | ); 56 | runOnlyForDeploymentPostprocessing = 0; 57 | }; 58 | 6BFD901E19C8D8B500DD99B6 /* Frameworks */ = { 59 | isa = PBXFrameworksBuildPhase; 60 | buildActionMask = 2147483647; 61 | files = ( 62 | ); 63 | runOnlyForDeploymentPostprocessing = 0; 64 | }; 65 | D958025519E6EEEB003C8218 /* Frameworks */ = { 66 | isa = PBXFrameworksBuildPhase; 67 | buildActionMask = 2147483647; 68 | files = ( 69 | ); 70 | runOnlyForDeploymentPostprocessing = 0; 71 | }; 72 | D958026019E6EEEB003C8218 /* Frameworks */ = { 73 | isa = PBXFrameworksBuildPhase; 74 | buildActionMask = 2147483647; 75 | files = ( 76 | D958026419E6EEEB003C8218 /* SwiftHTTP.framework in Frameworks */, 77 | ); 78 | runOnlyForDeploymentPostprocessing = 0; 79 | }; 80 | /* End PBXFrameworksBuildPhase section */ 81 | 82 | /* Begin PBXGroup section */ 83 | 6BFD900C19C8D8B500DD99B6 = { 84 | isa = PBXGroup; 85 | children = ( 86 | 6BFD901819C8D8B500DD99B6 /* SwiftHTTP */, 87 | 6BFD903B19C8D96A00DD99B6 /* Tests */, 88 | 6BFD901719C8D8B500DD99B6 /* Products */, 89 | ); 90 | sourceTree = ""; 91 | }; 92 | 6BFD901719C8D8B500DD99B6 /* Products */ = { 93 | isa = PBXGroup; 94 | children = ( 95 | 6BFD901619C8D8B500DD99B6 /* SwiftHTTP.framework */, 96 | 6BFD902119C8D8B500DD99B6 /* SwiftHTTPTests.xctest */, 97 | D958025919E6EEEB003C8218 /* SwiftHTTP.framework */, 98 | D958026319E6EEEB003C8218 /* SwiftHTTPOSXTests.xctest */, 99 | ); 100 | name = Products; 101 | sourceTree = ""; 102 | }; 103 | 6BFD901819C8D8B500DD99B6 /* SwiftHTTP */ = { 104 | isa = PBXGroup; 105 | children = ( 106 | 6BFD902F19C8D95C00DD99B6 /* HTTPRequestSerializer.swift */, 107 | 6BFD903019C8D95C00DD99B6 /* HTTPResponseSerializer.swift */, 108 | 6BFD903119C8D95C00DD99B6 /* HTTPTask.swift */, 109 | 6BFD903219C8D95C00DD99B6 /* HTTPUpload.swift */, 110 | 6BFD903319C8D95C00DD99B6 /* SwiftHTTP.h */, 111 | 6BFD901919C8D8B500DD99B6 /* Supporting Files */, 112 | ); 113 | path = SwiftHTTP; 114 | sourceTree = ""; 115 | }; 116 | 6BFD901919C8D8B500DD99B6 /* Supporting Files */ = { 117 | isa = PBXGroup; 118 | children = ( 119 | 6BFD903919C8D96500DD99B6 /* Info.plist */, 120 | ); 121 | name = "Supporting Files"; 122 | sourceTree = ""; 123 | }; 124 | 6BFD903B19C8D96A00DD99B6 /* Tests */ = { 125 | isa = PBXGroup; 126 | children = ( 127 | 6BFD903C19C8D98000DD99B6 /* Info.plist */, 128 | 6BFD903D19C8D98000DD99B6 /* SwiftHTTPTests.swift */, 129 | ); 130 | name = Tests; 131 | sourceTree = ""; 132 | }; 133 | /* End PBXGroup section */ 134 | 135 | /* Begin PBXHeadersBuildPhase section */ 136 | 6BFD901319C8D8B500DD99B6 /* Headers */ = { 137 | isa = PBXHeadersBuildPhase; 138 | buildActionMask = 2147483647; 139 | files = ( 140 | 6BFD903819C8D95C00DD99B6 /* SwiftHTTP.h in Headers */, 141 | ); 142 | runOnlyForDeploymentPostprocessing = 0; 143 | }; 144 | D958025619E6EEEB003C8218 /* Headers */ = { 145 | isa = PBXHeadersBuildPhase; 146 | buildActionMask = 2147483647; 147 | files = ( 148 | D958027719E6EF89003C8218 /* SwiftHTTP.h in Headers */, 149 | ); 150 | runOnlyForDeploymentPostprocessing = 0; 151 | }; 152 | /* End PBXHeadersBuildPhase section */ 153 | 154 | /* Begin PBXNativeTarget section */ 155 | 6BFD901519C8D8B500DD99B6 /* SwiftHTTP */ = { 156 | isa = PBXNativeTarget; 157 | buildConfigurationList = 6BFD902919C8D8B500DD99B6 /* Build configuration list for PBXNativeTarget "SwiftHTTP" */; 158 | buildPhases = ( 159 | 6BFD901119C8D8B500DD99B6 /* Sources */, 160 | 6BFD901219C8D8B500DD99B6 /* Frameworks */, 161 | 6BFD901319C8D8B500DD99B6 /* Headers */, 162 | 6BFD901419C8D8B500DD99B6 /* Resources */, 163 | ); 164 | buildRules = ( 165 | ); 166 | dependencies = ( 167 | ); 168 | name = SwiftHTTP; 169 | productName = SwiftHTTP; 170 | productReference = 6BFD901619C8D8B500DD99B6 /* SwiftHTTP.framework */; 171 | productType = "com.apple.product-type.framework"; 172 | }; 173 | 6BFD902019C8D8B500DD99B6 /* SwiftHTTPTests */ = { 174 | isa = PBXNativeTarget; 175 | buildConfigurationList = 6BFD902C19C8D8B500DD99B6 /* Build configuration list for PBXNativeTarget "SwiftHTTPTests" */; 176 | buildPhases = ( 177 | 6BFD901D19C8D8B500DD99B6 /* Sources */, 178 | 6BFD901E19C8D8B500DD99B6 /* Frameworks */, 179 | 6BFD901F19C8D8B500DD99B6 /* Resources */, 180 | ); 181 | buildRules = ( 182 | ); 183 | dependencies = ( 184 | ); 185 | name = SwiftHTTPTests; 186 | productName = SwiftHTTPTests; 187 | productReference = 6BFD902119C8D8B500DD99B6 /* SwiftHTTPTests.xctest */; 188 | productType = "com.apple.product-type.bundle.unit-test"; 189 | }; 190 | D958025819E6EEEB003C8218 /* SwiftHTTPOSX */ = { 191 | isa = PBXNativeTarget; 192 | buildConfigurationList = D958027019E6EEEB003C8218 /* Build configuration list for PBXNativeTarget "SwiftHTTPOSX" */; 193 | buildPhases = ( 194 | D958025419E6EEEB003C8218 /* Sources */, 195 | D958025519E6EEEB003C8218 /* Frameworks */, 196 | D958025619E6EEEB003C8218 /* Headers */, 197 | D958025719E6EEEB003C8218 /* Resources */, 198 | ); 199 | buildRules = ( 200 | ); 201 | dependencies = ( 202 | ); 203 | name = SwiftHTTPOSX; 204 | productName = SwiftHTTPOSX; 205 | productReference = D958025919E6EEEB003C8218 /* SwiftHTTP.framework */; 206 | productType = "com.apple.product-type.framework"; 207 | }; 208 | D958026219E6EEEB003C8218 /* SwiftHTTPOSXTests */ = { 209 | isa = PBXNativeTarget; 210 | buildConfigurationList = D958027119E6EEEB003C8218 /* Build configuration list for PBXNativeTarget "SwiftHTTPOSXTests" */; 211 | buildPhases = ( 212 | D958025F19E6EEEB003C8218 /* Sources */, 213 | D958026019E6EEEB003C8218 /* Frameworks */, 214 | D958026119E6EEEB003C8218 /* Resources */, 215 | ); 216 | buildRules = ( 217 | ); 218 | dependencies = ( 219 | D958026619E6EEEB003C8218 /* PBXTargetDependency */, 220 | ); 221 | name = SwiftHTTPOSXTests; 222 | productName = SwiftHTTPOSXTests; 223 | productReference = D958026319E6EEEB003C8218 /* SwiftHTTPOSXTests.xctest */; 224 | productType = "com.apple.product-type.bundle.unit-test"; 225 | }; 226 | /* End PBXNativeTarget section */ 227 | 228 | /* Begin PBXProject section */ 229 | 6BFD900D19C8D8B500DD99B6 /* Project object */ = { 230 | isa = PBXProject; 231 | attributes = { 232 | LastUpgradeCheck = 0600; 233 | ORGANIZATIONNAME = Vluxe; 234 | TargetAttributes = { 235 | 6BFD901519C8D8B500DD99B6 = { 236 | CreatedOnToolsVersion = 6.0; 237 | }; 238 | 6BFD902019C8D8B500DD99B6 = { 239 | CreatedOnToolsVersion = 6.0; 240 | }; 241 | D958025819E6EEEB003C8218 = { 242 | CreatedOnToolsVersion = 6.1; 243 | }; 244 | D958026219E6EEEB003C8218 = { 245 | CreatedOnToolsVersion = 6.1; 246 | }; 247 | }; 248 | }; 249 | buildConfigurationList = 6BFD901019C8D8B500DD99B6 /* Build configuration list for PBXProject "SwiftHTTP" */; 250 | compatibilityVersion = "Xcode 3.2"; 251 | developmentRegion = English; 252 | hasScannedForEncodings = 0; 253 | knownRegions = ( 254 | en, 255 | ); 256 | mainGroup = 6BFD900C19C8D8B500DD99B6; 257 | productRefGroup = 6BFD901719C8D8B500DD99B6 /* Products */; 258 | projectDirPath = ""; 259 | projectRoot = ""; 260 | targets = ( 261 | 6BFD901519C8D8B500DD99B6 /* SwiftHTTP */, 262 | 6BFD902019C8D8B500DD99B6 /* SwiftHTTPTests */, 263 | D958025819E6EEEB003C8218 /* SwiftHTTPOSX */, 264 | D958026219E6EEEB003C8218 /* SwiftHTTPOSXTests */, 265 | ); 266 | }; 267 | /* End PBXProject section */ 268 | 269 | /* Begin PBXResourcesBuildPhase section */ 270 | 6BFD901419C8D8B500DD99B6 /* Resources */ = { 271 | isa = PBXResourcesBuildPhase; 272 | buildActionMask = 2147483647; 273 | files = ( 274 | ); 275 | runOnlyForDeploymentPostprocessing = 0; 276 | }; 277 | 6BFD901F19C8D8B500DD99B6 /* Resources */ = { 278 | isa = PBXResourcesBuildPhase; 279 | buildActionMask = 2147483647; 280 | files = ( 281 | ); 282 | runOnlyForDeploymentPostprocessing = 0; 283 | }; 284 | D958025719E6EEEB003C8218 /* Resources */ = { 285 | isa = PBXResourcesBuildPhase; 286 | buildActionMask = 2147483647; 287 | files = ( 288 | ); 289 | runOnlyForDeploymentPostprocessing = 0; 290 | }; 291 | D958026119E6EEEB003C8218 /* Resources */ = { 292 | isa = PBXResourcesBuildPhase; 293 | buildActionMask = 2147483647; 294 | files = ( 295 | ); 296 | runOnlyForDeploymentPostprocessing = 0; 297 | }; 298 | /* End PBXResourcesBuildPhase section */ 299 | 300 | /* Begin PBXSourcesBuildPhase section */ 301 | 6BFD901119C8D8B500DD99B6 /* Sources */ = { 302 | isa = PBXSourcesBuildPhase; 303 | buildActionMask = 2147483647; 304 | files = ( 305 | 6BFD904319C928D900DD99B6 /* HTTPRequestSerializer.swift in Sources */, 306 | 6BFD904419C928D900DD99B6 /* HTTPResponseSerializer.swift in Sources */, 307 | 6BFD904519C928D900DD99B6 /* HTTPTask.swift in Sources */, 308 | 6BFD903719C8D95C00DD99B6 /* HTTPUpload.swift in Sources */, 309 | ); 310 | runOnlyForDeploymentPostprocessing = 0; 311 | }; 312 | 6BFD901D19C8D8B500DD99B6 /* Sources */ = { 313 | isa = PBXSourcesBuildPhase; 314 | buildActionMask = 2147483647; 315 | files = ( 316 | 6BFD904019C8D9A000DD99B6 /* SwiftHTTPTests.swift in Sources */, 317 | ); 318 | runOnlyForDeploymentPostprocessing = 0; 319 | }; 320 | D958025419E6EEEB003C8218 /* Sources */ = { 321 | isa = PBXSourcesBuildPhase; 322 | buildActionMask = 2147483647; 323 | files = ( 324 | D958027319E6EF4B003C8218 /* HTTPRequestSerializer.swift in Sources */, 325 | D958027419E6EF4B003C8218 /* HTTPResponseSerializer.swift in Sources */, 326 | D958027519E6EF4B003C8218 /* HTTPTask.swift in Sources */, 327 | D958027619E6EF4B003C8218 /* HTTPUpload.swift in Sources */, 328 | ); 329 | runOnlyForDeploymentPostprocessing = 0; 330 | }; 331 | D958025F19E6EEEB003C8218 /* Sources */ = { 332 | isa = PBXSourcesBuildPhase; 333 | buildActionMask = 2147483647; 334 | files = ( 335 | D958027219E6EF2B003C8218 /* SwiftHTTPTests.swift in Sources */, 336 | ); 337 | runOnlyForDeploymentPostprocessing = 0; 338 | }; 339 | /* End PBXSourcesBuildPhase section */ 340 | 341 | /* Begin PBXTargetDependency section */ 342 | D958026619E6EEEB003C8218 /* PBXTargetDependency */ = { 343 | isa = PBXTargetDependency; 344 | target = D958025819E6EEEB003C8218 /* SwiftHTTPOSX */; 345 | targetProxy = D958026519E6EEEB003C8218 /* PBXContainerItemProxy */; 346 | }; 347 | /* End PBXTargetDependency section */ 348 | 349 | /* Begin XCBuildConfiguration section */ 350 | 6BFD902719C8D8B500DD99B6 /* Debug */ = { 351 | isa = XCBuildConfiguration; 352 | buildSettings = { 353 | ALWAYS_SEARCH_USER_PATHS = NO; 354 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 355 | CLANG_CXX_LIBRARY = "libc++"; 356 | CLANG_ENABLE_MODULES = YES; 357 | CLANG_ENABLE_OBJC_ARC = YES; 358 | CLANG_WARN_BOOL_CONVERSION = YES; 359 | CLANG_WARN_CONSTANT_CONVERSION = YES; 360 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 361 | CLANG_WARN_EMPTY_BODY = YES; 362 | CLANG_WARN_ENUM_CONVERSION = YES; 363 | CLANG_WARN_INT_CONVERSION = YES; 364 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 365 | CLANG_WARN_UNREACHABLE_CODE = YES; 366 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 367 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 368 | COPY_PHASE_STRIP = NO; 369 | CURRENT_PROJECT_VERSION = 1; 370 | DEFINES_MODULE = NO; 371 | ENABLE_STRICT_OBJC_MSGSEND = YES; 372 | GCC_C_LANGUAGE_STANDARD = gnu99; 373 | GCC_DYNAMIC_NO_PIC = NO; 374 | GCC_OPTIMIZATION_LEVEL = 0; 375 | GCC_PREPROCESSOR_DEFINITIONS = ( 376 | "DEBUG=1", 377 | "$(inherited)", 378 | ); 379 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 380 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 381 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 382 | GCC_WARN_UNDECLARED_SELECTOR = YES; 383 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 384 | GCC_WARN_UNUSED_FUNCTION = YES; 385 | GCC_WARN_UNUSED_VARIABLE = YES; 386 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 387 | MTL_ENABLE_DEBUG_INFO = YES; 388 | ONLY_ACTIVE_ARCH = YES; 389 | PRODUCT_MODULE_NAME = "$(PRODUCT_NAME:c99extidentifier)"; 390 | SDKROOT = iphoneos; 391 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 392 | TARGETED_DEVICE_FAMILY = "1,2"; 393 | VERSIONING_SYSTEM = "apple-generic"; 394 | VERSION_INFO_PREFIX = ""; 395 | }; 396 | name = Debug; 397 | }; 398 | 6BFD902819C8D8B500DD99B6 /* Release */ = { 399 | isa = XCBuildConfiguration; 400 | buildSettings = { 401 | ALWAYS_SEARCH_USER_PATHS = NO; 402 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 403 | CLANG_CXX_LIBRARY = "libc++"; 404 | CLANG_ENABLE_MODULES = YES; 405 | CLANG_ENABLE_OBJC_ARC = YES; 406 | CLANG_WARN_BOOL_CONVERSION = YES; 407 | CLANG_WARN_CONSTANT_CONVERSION = YES; 408 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 409 | CLANG_WARN_EMPTY_BODY = YES; 410 | CLANG_WARN_ENUM_CONVERSION = YES; 411 | CLANG_WARN_INT_CONVERSION = YES; 412 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 413 | CLANG_WARN_UNREACHABLE_CODE = YES; 414 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 415 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 416 | COPY_PHASE_STRIP = YES; 417 | CURRENT_PROJECT_VERSION = 1; 418 | DEFINES_MODULE = NO; 419 | ENABLE_NS_ASSERTIONS = NO; 420 | ENABLE_STRICT_OBJC_MSGSEND = YES; 421 | GCC_C_LANGUAGE_STANDARD = gnu99; 422 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 423 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 424 | GCC_WARN_UNDECLARED_SELECTOR = YES; 425 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 426 | GCC_WARN_UNUSED_FUNCTION = YES; 427 | GCC_WARN_UNUSED_VARIABLE = YES; 428 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 429 | MTL_ENABLE_DEBUG_INFO = NO; 430 | PRODUCT_MODULE_NAME = "$(PRODUCT_NAME:c99extidentifier)"; 431 | SDKROOT = iphoneos; 432 | TARGETED_DEVICE_FAMILY = "1,2"; 433 | VALIDATE_PRODUCT = YES; 434 | VERSIONING_SYSTEM = "apple-generic"; 435 | VERSION_INFO_PREFIX = ""; 436 | }; 437 | name = Release; 438 | }; 439 | 6BFD902A19C8D8B500DD99B6 /* Debug */ = { 440 | isa = XCBuildConfiguration; 441 | buildSettings = { 442 | CLANG_ENABLE_MODULES = YES; 443 | DEFINES_MODULE = YES; 444 | DYLIB_COMPATIBILITY_VERSION = 1; 445 | DYLIB_CURRENT_VERSION = 1; 446 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 447 | INFOPLIST_FILE = "$(SRCROOT)/Info.plist"; 448 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 449 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 450 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 451 | PRODUCT_NAME = "$(TARGET_NAME)"; 452 | SKIP_INSTALL = YES; 453 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 454 | }; 455 | name = Debug; 456 | }; 457 | 6BFD902B19C8D8B500DD99B6 /* Release */ = { 458 | isa = XCBuildConfiguration; 459 | buildSettings = { 460 | CLANG_ENABLE_MODULES = YES; 461 | DEFINES_MODULE = YES; 462 | DYLIB_COMPATIBILITY_VERSION = 1; 463 | DYLIB_CURRENT_VERSION = 1; 464 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 465 | INFOPLIST_FILE = "$(SRCROOT)/Info.plist"; 466 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 467 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 468 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 469 | PRODUCT_NAME = "$(TARGET_NAME)"; 470 | SKIP_INSTALL = YES; 471 | }; 472 | name = Release; 473 | }; 474 | 6BFD902D19C8D8B500DD99B6 /* Debug */ = { 475 | isa = XCBuildConfiguration; 476 | buildSettings = { 477 | FRAMEWORK_SEARCH_PATHS = ( 478 | "$(SDKROOT)/Developer/Library/Frameworks", 479 | "$(inherited)", 480 | ); 481 | GCC_PREPROCESSOR_DEFINITIONS = ( 482 | "DEBUG=1", 483 | "$(inherited)", 484 | ); 485 | INFOPLIST_FILE = Tests/Info.plist; 486 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 487 | PRODUCT_NAME = "$(TARGET_NAME)"; 488 | }; 489 | name = Debug; 490 | }; 491 | 6BFD902E19C8D8B500DD99B6 /* Release */ = { 492 | isa = XCBuildConfiguration; 493 | buildSettings = { 494 | FRAMEWORK_SEARCH_PATHS = ( 495 | "$(SDKROOT)/Developer/Library/Frameworks", 496 | "$(inherited)", 497 | ); 498 | INFOPLIST_FILE = Tests/Info.plist; 499 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 500 | PRODUCT_NAME = "$(TARGET_NAME)"; 501 | }; 502 | name = Release; 503 | }; 504 | D958026C19E6EEEB003C8218 /* Debug */ = { 505 | isa = XCBuildConfiguration; 506 | buildSettings = { 507 | COMBINE_HIDPI_IMAGES = YES; 508 | DEFINES_MODULE = YES; 509 | DYLIB_COMPATIBILITY_VERSION = 1; 510 | DYLIB_CURRENT_VERSION = 1; 511 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 512 | FRAMEWORK_VERSION = A; 513 | GCC_PREPROCESSOR_DEFINITIONS = ( 514 | "DEBUG=1", 515 | "$(inherited)", 516 | ); 517 | INFOPLIST_FILE = Info.plist; 518 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 519 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; 520 | MACOSX_DEPLOYMENT_TARGET = 10.10; 521 | PRODUCT_NAME = SwiftHTTP; 522 | SDKROOT = macosx; 523 | SKIP_INSTALL = YES; 524 | }; 525 | name = Debug; 526 | }; 527 | D958026D19E6EEEB003C8218 /* Release */ = { 528 | isa = XCBuildConfiguration; 529 | buildSettings = { 530 | COMBINE_HIDPI_IMAGES = YES; 531 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 532 | DEFINES_MODULE = YES; 533 | DYLIB_COMPATIBILITY_VERSION = 1; 534 | DYLIB_CURRENT_VERSION = 1; 535 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 536 | FRAMEWORK_VERSION = A; 537 | INFOPLIST_FILE = Info.plist; 538 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 539 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; 540 | MACOSX_DEPLOYMENT_TARGET = 10.10; 541 | PRODUCT_NAME = SwiftHTTP; 542 | SDKROOT = macosx; 543 | SKIP_INSTALL = YES; 544 | }; 545 | name = Release; 546 | }; 547 | D958026E19E6EEEB003C8218 /* Debug */ = { 548 | isa = XCBuildConfiguration; 549 | buildSettings = { 550 | COMBINE_HIDPI_IMAGES = YES; 551 | FRAMEWORK_SEARCH_PATHS = ( 552 | "$(DEVELOPER_FRAMEWORKS_DIR)", 553 | "$(inherited)", 554 | ); 555 | GCC_PREPROCESSOR_DEFINITIONS = ( 556 | "DEBUG=1", 557 | "$(inherited)", 558 | ); 559 | INFOPLIST_FILE = Tests/Info.plist; 560 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 561 | MACOSX_DEPLOYMENT_TARGET = 10.10; 562 | PRODUCT_NAME = "$(TARGET_NAME)"; 563 | SDKROOT = macosx; 564 | }; 565 | name = Debug; 566 | }; 567 | D958026F19E6EEEB003C8218 /* Release */ = { 568 | isa = XCBuildConfiguration; 569 | buildSettings = { 570 | COMBINE_HIDPI_IMAGES = YES; 571 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 572 | FRAMEWORK_SEARCH_PATHS = ( 573 | "$(DEVELOPER_FRAMEWORKS_DIR)", 574 | "$(inherited)", 575 | ); 576 | INFOPLIST_FILE = Tests/Info.plist; 577 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 578 | MACOSX_DEPLOYMENT_TARGET = 10.10; 579 | PRODUCT_NAME = "$(TARGET_NAME)"; 580 | SDKROOT = macosx; 581 | }; 582 | name = Release; 583 | }; 584 | /* End XCBuildConfiguration section */ 585 | 586 | /* Begin XCConfigurationList section */ 587 | 6BFD901019C8D8B500DD99B6 /* Build configuration list for PBXProject "SwiftHTTP" */ = { 588 | isa = XCConfigurationList; 589 | buildConfigurations = ( 590 | 6BFD902719C8D8B500DD99B6 /* Debug */, 591 | 6BFD902819C8D8B500DD99B6 /* Release */, 592 | ); 593 | defaultConfigurationIsVisible = 0; 594 | defaultConfigurationName = Release; 595 | }; 596 | 6BFD902919C8D8B500DD99B6 /* Build configuration list for PBXNativeTarget "SwiftHTTP" */ = { 597 | isa = XCConfigurationList; 598 | buildConfigurations = ( 599 | 6BFD902A19C8D8B500DD99B6 /* Debug */, 600 | 6BFD902B19C8D8B500DD99B6 /* Release */, 601 | ); 602 | defaultConfigurationIsVisible = 0; 603 | defaultConfigurationName = Release; 604 | }; 605 | 6BFD902C19C8D8B500DD99B6 /* Build configuration list for PBXNativeTarget "SwiftHTTPTests" */ = { 606 | isa = XCConfigurationList; 607 | buildConfigurations = ( 608 | 6BFD902D19C8D8B500DD99B6 /* Debug */, 609 | 6BFD902E19C8D8B500DD99B6 /* Release */, 610 | ); 611 | defaultConfigurationIsVisible = 0; 612 | defaultConfigurationName = Release; 613 | }; 614 | D958027019E6EEEB003C8218 /* Build configuration list for PBXNativeTarget "SwiftHTTPOSX" */ = { 615 | isa = XCConfigurationList; 616 | buildConfigurations = ( 617 | D958026C19E6EEEB003C8218 /* Debug */, 618 | D958026D19E6EEEB003C8218 /* Release */, 619 | ); 620 | defaultConfigurationIsVisible = 0; 621 | defaultConfigurationName = Release; 622 | }; 623 | D958027119E6EEEB003C8218 /* Build configuration list for PBXNativeTarget "SwiftHTTPOSXTests" */ = { 624 | isa = XCConfigurationList; 625 | buildConfigurations = ( 626 | D958026E19E6EEEB003C8218 /* Debug */, 627 | D958026F19E6EEEB003C8218 /* Release */, 628 | ); 629 | defaultConfigurationIsVisible = 0; 630 | defaultConfigurationName = Release; 631 | }; 632 | /* End XCConfigurationList section */ 633 | }; 634 | rootObject = 6BFD900D19C8D8B500DD99B6 /* Project object */; 635 | } 636 | -------------------------------------------------------------------------------- /SwiftHTTP-master/SwiftHTTP.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SwiftHTTP-master/SwiftHTTP.xcodeproj/xcshareddata/xcschemes/SwiftHTTP.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 60 | 61 | 67 | 68 | 69 | 70 | 72 | 73 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /SwiftHTTP-master/SwiftHTTP.xcodeproj/xcshareddata/xcschemes/SwiftHTTPOSX.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 93 | 94 | 100 | 101 | 102 | 103 | 105 | 106 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /SwiftHTTP-master/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.vluxe.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /SwiftHTTP-master/Tests/SwiftHTTPTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftHTTPTests.swift 3 | // SwiftHTTPTests 4 | // 5 | // Created by Austin Cherry on 9/16/14. 6 | // Copyright (c) 2014 Vluxe. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | #if os(iOS) 11 | import SwiftHTTP 12 | #elseif os(OSX) 13 | import SwiftHTTPOSX 14 | #endif 15 | 16 | class SwiftHTTPTests: XCTestCase { 17 | 18 | override func setUp() { 19 | super.setUp() 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | override func tearDown() { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | super.tearDown() 26 | } 27 | 28 | func testGetRequest() { 29 | var request = HTTPTask() 30 | request.GET("http://vluxe.io", parameters: nil, success: {(response: HTTPResponse) -> Void in 31 | if response.responseObject != nil { 32 | XCTAssert(true, "Pass") 33 | } 34 | },failure: {(error: NSError, _) -> Void in 35 | XCTAssert(false, "Failure") 36 | }) 37 | } 38 | 39 | func testAuthRequest() { 40 | 41 | var request = HTTPTask() 42 | var attempted = false 43 | request.auth = {(challenge: NSURLAuthenticationChallenge) in 44 | if !attempted { 45 | attempted = true 46 | return NSURLCredential(user: "user", password: "passwd", persistence: .ForSession) 47 | } 48 | return nil 49 | } 50 | request.GET("http://httpbin.org/basic-auth/user/passwd", parameters: nil, success: {(response: HTTPResponse) -> Void in 51 | if response.responseObject != nil { 52 | XCTAssert(true, "Pass") 53 | } 54 | },failure: {(error: NSError, _) -> Void in 55 | XCTAssert(false, "Failure") 56 | }) 57 | } 58 | } 59 | --------------------------------------------------------------------------------