├── .gitignore ├── .travis.yml ├── Example.xcodeproj └── project.pbxproj ├── Example ├── AppDelegate.swift ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── LaunchImage.launchimage │ │ ├── Contents.json │ │ └── Default@2x.png ├── Info.plist ├── SwiftyJSONTests.json └── ViewController.swift ├── LICENSE ├── README.md ├── Source ├── Info.plist ├── SwiftyJSON.h └── SwiftyJSON.swift ├── SwiftyJSON.podspec ├── SwiftyJSON.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── SwiftyJSON.xccheckout ├── xcshareddata │ └── xcschemes │ │ └── SwiftyJSON.xcscheme └── xcuserdata │ └── lebedzeu.xcuserdatad │ └── xcschemes │ ├── SwiftyJSON-OSX.xcscheme │ ├── SwiftyJSON.xcscheme │ └── xcschememanagement.plist ├── SwiftyJSON.xcworkspace └── contents.xcworkspacedata └── Tests ├── ArrayTests.swift ├── BaseTests.swift ├── ComparableTests.swift ├── DictionaryTests.swift ├── Info.plist ├── LiteralConvertibleTests.swift ├── NumberTests.swift ├── PerformanceTests.swift ├── PrintableTests.swift ├── RawRepresentableTests.swift ├── RawTests.swift ├── SequenceTypeTests.swift ├── StringTests.swift ├── SubscriptTests.swift └── Tests.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | .DS_Store 3 | */build/* 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | profile 14 | *.moved-aside 15 | DerivedData 16 | .idea/ 17 | *.hmap 18 | *.xccheckout 19 | 20 | #CocoaPods 21 | Pods 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | script: "xcodebuild test -workspace SwiftyJSON.xcworkspace -scheme SwiftyJSON -destination \"platform=iOS Simulator,name=iPhone 5\"" 3 | -------------------------------------------------------------------------------- /Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | A82A1C1F19D926B8009A653D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A82A1C1E19D926B8009A653D /* AppDelegate.swift */; }; 11 | A82A1C2419D926B8009A653D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A82A1C2219D926B8009A653D /* Main.storyboard */; }; 12 | A82A1C2619D926B8009A653D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A82A1C2519D926B8009A653D /* Images.xcassets */; }; 13 | A82A1C2919D926B8009A653D /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = A82A1C2719D926B8009A653D /* LaunchScreen.xib */; }; 14 | A82A1C4019D94AE5009A653D /* SwiftyJSONTests.json in Resources */ = {isa = PBXBuildFile; fileRef = A82A1C3F19D94AE5009A653D /* SwiftyJSONTests.json */; }; 15 | A82A1C5019D94E96009A653D /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */; }; 16 | A82A1C5119D94E96009A653D /* SwiftyJSON.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 17 | A82A1C5619D95606009A653D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A82A1C5519D95606009A653D /* ViewController.swift */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXContainerItemProxy section */ 21 | 7C5E10861A2E1CBA00333E8B /* PBXContainerItemProxy */ = { 22 | isa = PBXContainerItemProxy; 23 | containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; 24 | proxyType = 2; 25 | remoteGlobalIDString = 4EC1C1C91A0C1A2D0026ED0B; 26 | remoteInfo = SwiftyJSONOSX; 27 | }; 28 | 7C5E10881A2E1CBA00333E8B /* PBXContainerItemProxy */ = { 29 | isa = PBXContainerItemProxy; 30 | containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; 31 | proxyType = 2; 32 | remoteGlobalIDString = 4EC1C1D31A0C1A2D0026ED0B; 33 | remoteInfo = SwiftyJSONOSXTests; 34 | }; 35 | A82A1C4C19D94E86009A653D /* PBXContainerItemProxy */ = { 36 | isa = PBXContainerItemProxy; 37 | containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; 38 | proxyType = 2; 39 | remoteGlobalIDString = 2E4FEFDB19575BE100351305; 40 | remoteInfo = SwiftyJSON; 41 | }; 42 | A82A1C4E19D94E86009A653D /* PBXContainerItemProxy */ = { 43 | isa = PBXContainerItemProxy; 44 | containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; 45 | proxyType = 2; 46 | remoteGlobalIDString = 2E4FEFE619575BE100351305; 47 | remoteInfo = SwiftyJSONTests; 48 | }; 49 | A82A1C5219D94E96009A653D /* PBXContainerItemProxy */ = { 50 | isa = PBXContainerItemProxy; 51 | containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; 52 | proxyType = 1; 53 | remoteGlobalIDString = 2E4FEFDA19575BE100351305; 54 | remoteInfo = SwiftyJSON; 55 | }; 56 | /* End PBXContainerItemProxy section */ 57 | 58 | /* Begin PBXCopyFilesBuildPhase section */ 59 | A82A1C5419D94E97009A653D /* Embed Frameworks */ = { 60 | isa = PBXCopyFilesBuildPhase; 61 | buildActionMask = 2147483647; 62 | dstPath = ""; 63 | dstSubfolderSpec = 10; 64 | files = ( 65 | A82A1C5119D94E96009A653D /* SwiftyJSON.framework in Embed Frameworks */, 66 | ); 67 | name = "Embed Frameworks"; 68 | runOnlyForDeploymentPostprocessing = 0; 69 | }; 70 | /* End PBXCopyFilesBuildPhase section */ 71 | 72 | /* Begin PBXFileReference section */ 73 | A82A1C1919D926B8009A653D /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 74 | A82A1C1D19D926B8009A653D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 75 | A82A1C1E19D926B8009A653D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 76 | A82A1C2319D926B8009A653D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 77 | A82A1C2519D926B8009A653D /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 78 | A82A1C2819D926B8009A653D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 79 | A82A1C3F19D94AE5009A653D /* SwiftyJSONTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = SwiftyJSONTests.json; sourceTree = ""; }; 80 | A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = SwiftyJSON.xcodeproj; sourceTree = ""; }; 81 | A82A1C5519D95606009A653D /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 82 | /* End PBXFileReference section */ 83 | 84 | /* Begin PBXFrameworksBuildPhase section */ 85 | A82A1C1619D926B8009A653D /* Frameworks */ = { 86 | isa = PBXFrameworksBuildPhase; 87 | buildActionMask = 2147483647; 88 | files = ( 89 | A82A1C5019D94E96009A653D /* SwiftyJSON.framework in Frameworks */, 90 | ); 91 | runOnlyForDeploymentPostprocessing = 0; 92 | }; 93 | /* End PBXFrameworksBuildPhase section */ 94 | 95 | /* Begin PBXGroup section */ 96 | A82A1C1019D926B8009A653D = { 97 | isa = PBXGroup; 98 | children = ( 99 | A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */, 100 | A82A1C1B19D926B8009A653D /* Example */, 101 | A82A1C1A19D926B8009A653D /* Products */, 102 | ); 103 | sourceTree = ""; 104 | }; 105 | A82A1C1A19D926B8009A653D /* Products */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | A82A1C1919D926B8009A653D /* Example.app */, 109 | ); 110 | name = Products; 111 | sourceTree = ""; 112 | }; 113 | A82A1C1B19D926B8009A653D /* Example */ = { 114 | isa = PBXGroup; 115 | children = ( 116 | A82A1C3F19D94AE5009A653D /* SwiftyJSONTests.json */, 117 | A82A1C1E19D926B8009A653D /* AppDelegate.swift */, 118 | A82A1C5519D95606009A653D /* ViewController.swift */, 119 | A82A1C2219D926B8009A653D /* Main.storyboard */, 120 | A82A1C2519D926B8009A653D /* Images.xcassets */, 121 | A82A1C2719D926B8009A653D /* LaunchScreen.xib */, 122 | A82A1C1C19D926B8009A653D /* Supporting Files */, 123 | ); 124 | path = Example; 125 | sourceTree = ""; 126 | }; 127 | A82A1C1C19D926B8009A653D /* Supporting Files */ = { 128 | isa = PBXGroup; 129 | children = ( 130 | A82A1C1D19D926B8009A653D /* Info.plist */, 131 | ); 132 | name = "Supporting Files"; 133 | sourceTree = ""; 134 | }; 135 | A82A1C4819D94E86009A653D /* Products */ = { 136 | isa = PBXGroup; 137 | children = ( 138 | A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */, 139 | A82A1C4F19D94E86009A653D /* SwiftyJSONTests.xctest */, 140 | 7C5E10871A2E1CBA00333E8B /* SwiftyJSON.framework */, 141 | 7C5E10891A2E1CBA00333E8B /* SwiftyJSONOSXTests.xctest */, 142 | ); 143 | name = Products; 144 | sourceTree = ""; 145 | }; 146 | /* End PBXGroup section */ 147 | 148 | /* Begin PBXNativeTarget section */ 149 | A82A1C1819D926B8009A653D /* Example */ = { 150 | isa = PBXNativeTarget; 151 | buildConfigurationList = A82A1C3819D926B8009A653D /* Build configuration list for PBXNativeTarget "Example" */; 152 | buildPhases = ( 153 | A82A1C1519D926B8009A653D /* Sources */, 154 | A82A1C1619D926B8009A653D /* Frameworks */, 155 | A82A1C1719D926B8009A653D /* Resources */, 156 | A82A1C5419D94E97009A653D /* Embed Frameworks */, 157 | ); 158 | buildRules = ( 159 | ); 160 | dependencies = ( 161 | A82A1C5319D94E96009A653D /* PBXTargetDependency */, 162 | ); 163 | name = Example; 164 | productName = Example; 165 | productReference = A82A1C1919D926B8009A653D /* Example.app */; 166 | productType = "com.apple.product-type.application"; 167 | }; 168 | /* End PBXNativeTarget section */ 169 | 170 | /* Begin PBXProject section */ 171 | A82A1C1119D926B8009A653D /* Project object */ = { 172 | isa = PBXProject; 173 | attributes = { 174 | LastUpgradeCheck = 0600; 175 | ORGANIZATIONNAME = swiftyjson; 176 | TargetAttributes = { 177 | A82A1C1819D926B8009A653D = { 178 | CreatedOnToolsVersion = 6.0.1; 179 | }; 180 | }; 181 | }; 182 | buildConfigurationList = A82A1C1419D926B8009A653D /* Build configuration list for PBXProject "Example" */; 183 | compatibilityVersion = "Xcode 3.2"; 184 | developmentRegion = English; 185 | hasScannedForEncodings = 0; 186 | knownRegions = ( 187 | en, 188 | Base, 189 | ); 190 | mainGroup = A82A1C1019D926B8009A653D; 191 | productRefGroup = A82A1C1A19D926B8009A653D /* Products */; 192 | projectDirPath = ""; 193 | projectReferences = ( 194 | { 195 | ProductGroup = A82A1C4819D94E86009A653D /* Products */; 196 | ProjectRef = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; 197 | }, 198 | ); 199 | projectRoot = ""; 200 | targets = ( 201 | A82A1C1819D926B8009A653D /* Example */, 202 | ); 203 | }; 204 | /* End PBXProject section */ 205 | 206 | /* Begin PBXReferenceProxy section */ 207 | 7C5E10871A2E1CBA00333E8B /* SwiftyJSON.framework */ = { 208 | isa = PBXReferenceProxy; 209 | fileType = wrapper.framework; 210 | path = SwiftyJSON.framework; 211 | remoteRef = 7C5E10861A2E1CBA00333E8B /* PBXContainerItemProxy */; 212 | sourceTree = BUILT_PRODUCTS_DIR; 213 | }; 214 | 7C5E10891A2E1CBA00333E8B /* SwiftyJSONOSXTests.xctest */ = { 215 | isa = PBXReferenceProxy; 216 | fileType = wrapper.cfbundle; 217 | path = SwiftyJSONOSXTests.xctest; 218 | remoteRef = 7C5E10881A2E1CBA00333E8B /* PBXContainerItemProxy */; 219 | sourceTree = BUILT_PRODUCTS_DIR; 220 | }; 221 | A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */ = { 222 | isa = PBXReferenceProxy; 223 | fileType = wrapper.framework; 224 | path = SwiftyJSON.framework; 225 | remoteRef = A82A1C4C19D94E86009A653D /* PBXContainerItemProxy */; 226 | sourceTree = BUILT_PRODUCTS_DIR; 227 | }; 228 | A82A1C4F19D94E86009A653D /* SwiftyJSONTests.xctest */ = { 229 | isa = PBXReferenceProxy; 230 | fileType = wrapper.cfbundle; 231 | path = SwiftyJSONTests.xctest; 232 | remoteRef = A82A1C4E19D94E86009A653D /* PBXContainerItemProxy */; 233 | sourceTree = BUILT_PRODUCTS_DIR; 234 | }; 235 | /* End PBXReferenceProxy section */ 236 | 237 | /* Begin PBXResourcesBuildPhase section */ 238 | A82A1C1719D926B8009A653D /* Resources */ = { 239 | isa = PBXResourcesBuildPhase; 240 | buildActionMask = 2147483647; 241 | files = ( 242 | A82A1C2419D926B8009A653D /* Main.storyboard in Resources */, 243 | A82A1C2919D926B8009A653D /* LaunchScreen.xib in Resources */, 244 | A82A1C2619D926B8009A653D /* Images.xcassets in Resources */, 245 | A82A1C4019D94AE5009A653D /* SwiftyJSONTests.json in Resources */, 246 | ); 247 | runOnlyForDeploymentPostprocessing = 0; 248 | }; 249 | /* End PBXResourcesBuildPhase section */ 250 | 251 | /* Begin PBXSourcesBuildPhase section */ 252 | A82A1C1519D926B8009A653D /* Sources */ = { 253 | isa = PBXSourcesBuildPhase; 254 | buildActionMask = 2147483647; 255 | files = ( 256 | A82A1C5619D95606009A653D /* ViewController.swift in Sources */, 257 | A82A1C1F19D926B8009A653D /* AppDelegate.swift in Sources */, 258 | ); 259 | runOnlyForDeploymentPostprocessing = 0; 260 | }; 261 | /* End PBXSourcesBuildPhase section */ 262 | 263 | /* Begin PBXTargetDependency section */ 264 | A82A1C5319D94E96009A653D /* PBXTargetDependency */ = { 265 | isa = PBXTargetDependency; 266 | name = SwiftyJSON; 267 | targetProxy = A82A1C5219D94E96009A653D /* PBXContainerItemProxy */; 268 | }; 269 | /* End PBXTargetDependency section */ 270 | 271 | /* Begin PBXVariantGroup section */ 272 | A82A1C2219D926B8009A653D /* Main.storyboard */ = { 273 | isa = PBXVariantGroup; 274 | children = ( 275 | A82A1C2319D926B8009A653D /* Base */, 276 | ); 277 | name = Main.storyboard; 278 | sourceTree = ""; 279 | }; 280 | A82A1C2719D926B8009A653D /* LaunchScreen.xib */ = { 281 | isa = PBXVariantGroup; 282 | children = ( 283 | A82A1C2819D926B8009A653D /* Base */, 284 | ); 285 | name = LaunchScreen.xib; 286 | sourceTree = ""; 287 | }; 288 | /* End PBXVariantGroup section */ 289 | 290 | /* Begin XCBuildConfiguration section */ 291 | A82A1C3619D926B8009A653D /* Debug */ = { 292 | isa = XCBuildConfiguration; 293 | buildSettings = { 294 | ALWAYS_SEARCH_USER_PATHS = NO; 295 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 296 | CLANG_CXX_LIBRARY = "libc++"; 297 | CLANG_ENABLE_MODULES = YES; 298 | CLANG_ENABLE_OBJC_ARC = YES; 299 | CLANG_WARN_BOOL_CONVERSION = YES; 300 | CLANG_WARN_CONSTANT_CONVERSION = YES; 301 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 302 | CLANG_WARN_EMPTY_BODY = YES; 303 | CLANG_WARN_ENUM_CONVERSION = YES; 304 | CLANG_WARN_INT_CONVERSION = YES; 305 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 306 | CLANG_WARN_UNREACHABLE_CODE = YES; 307 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 308 | CODE_SIGN_IDENTITY = "iPhone Developer"; 309 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 310 | COPY_PHASE_STRIP = NO; 311 | ENABLE_STRICT_OBJC_MSGSEND = YES; 312 | GCC_C_LANGUAGE_STANDARD = gnu99; 313 | GCC_DYNAMIC_NO_PIC = NO; 314 | GCC_OPTIMIZATION_LEVEL = 0; 315 | GCC_PREPROCESSOR_DEFINITIONS = ( 316 | "DEBUG=1", 317 | "$(inherited)", 318 | ); 319 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 320 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 321 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 322 | GCC_WARN_UNDECLARED_SELECTOR = YES; 323 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 324 | GCC_WARN_UNUSED_FUNCTION = YES; 325 | GCC_WARN_UNUSED_VARIABLE = YES; 326 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 327 | MTL_ENABLE_DEBUG_INFO = YES; 328 | ONLY_ACTIVE_ARCH = YES; 329 | SDKROOT = iphoneos; 330 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 331 | TARGETED_DEVICE_FAMILY = "1,2"; 332 | }; 333 | name = Debug; 334 | }; 335 | A82A1C3719D926B8009A653D /* Release */ = { 336 | isa = XCBuildConfiguration; 337 | buildSettings = { 338 | ALWAYS_SEARCH_USER_PATHS = NO; 339 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 340 | CLANG_CXX_LIBRARY = "libc++"; 341 | CLANG_ENABLE_MODULES = YES; 342 | CLANG_ENABLE_OBJC_ARC = YES; 343 | CLANG_WARN_BOOL_CONVERSION = YES; 344 | CLANG_WARN_CONSTANT_CONVERSION = YES; 345 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 346 | CLANG_WARN_EMPTY_BODY = YES; 347 | CLANG_WARN_ENUM_CONVERSION = YES; 348 | CLANG_WARN_INT_CONVERSION = YES; 349 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 350 | CLANG_WARN_UNREACHABLE_CODE = YES; 351 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 352 | CODE_SIGN_IDENTITY = "iPhone Distribution"; 353 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 354 | COPY_PHASE_STRIP = YES; 355 | ENABLE_NS_ASSERTIONS = NO; 356 | ENABLE_STRICT_OBJC_MSGSEND = YES; 357 | GCC_C_LANGUAGE_STANDARD = gnu99; 358 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 359 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 360 | GCC_WARN_UNDECLARED_SELECTOR = YES; 361 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 362 | GCC_WARN_UNUSED_FUNCTION = YES; 363 | GCC_WARN_UNUSED_VARIABLE = YES; 364 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 365 | MTL_ENABLE_DEBUG_INFO = NO; 366 | SDKROOT = iphoneos; 367 | TARGETED_DEVICE_FAMILY = "1,2"; 368 | VALIDATE_PRODUCT = YES; 369 | }; 370 | name = Release; 371 | }; 372 | A82A1C3919D926B8009A653D /* Debug */ = { 373 | isa = XCBuildConfiguration; 374 | buildSettings = { 375 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 376 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 377 | INFOPLIST_FILE = Example/Info.plist; 378 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 379 | PRODUCT_NAME = "$(TARGET_NAME)"; 380 | }; 381 | name = Debug; 382 | }; 383 | A82A1C3A19D926B8009A653D /* Release */ = { 384 | isa = XCBuildConfiguration; 385 | buildSettings = { 386 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 387 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 388 | CODE_SIGN_IDENTITY = "iPhone Distribution"; 389 | INFOPLIST_FILE = Example/Info.plist; 390 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 391 | PRODUCT_NAME = "$(TARGET_NAME)"; 392 | }; 393 | name = Release; 394 | }; 395 | /* End XCBuildConfiguration section */ 396 | 397 | /* Begin XCConfigurationList section */ 398 | A82A1C1419D926B8009A653D /* Build configuration list for PBXProject "Example" */ = { 399 | isa = XCConfigurationList; 400 | buildConfigurations = ( 401 | A82A1C3619D926B8009A653D /* Debug */, 402 | A82A1C3719D926B8009A653D /* Release */, 403 | ); 404 | defaultConfigurationIsVisible = 0; 405 | defaultConfigurationName = Release; 406 | }; 407 | A82A1C3819D926B8009A653D /* Build configuration list for PBXNativeTarget "Example" */ = { 408 | isa = XCConfigurationList; 409 | buildConfigurations = ( 410 | A82A1C3919D926B8009A653D /* Debug */, 411 | A82A1C3A19D926B8009A653D /* Release */, 412 | ); 413 | defaultConfigurationIsVisible = 0; 414 | defaultConfigurationName = Release; 415 | }; 416 | /* End XCConfigurationList section */ 417 | }; 418 | rootObject = A82A1C1119D926B8009A653D /* Project object */; 419 | } 420 | -------------------------------------------------------------------------------- /Example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // SwiftyJSON.h 2 | // 3 | // Copyright (c) 2014 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 UIKit 24 | import SwiftyJSON 25 | 26 | @UIApplicationMain 27 | class AppDelegate: UIResponder, UIApplicationDelegate { 28 | 29 | var window: UIWindow? 30 | 31 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 32 | 33 | let navigationController = self.window?.rootViewController as UINavigationController 34 | let viewController = navigationController.topViewController as ViewController 35 | 36 | if let file = NSBundle(forClass:AppDelegate.self).pathForResource("SwiftyJSONTests", ofType: "json") { 37 | let data = NSData(contentsOfFile: file)! 38 | let json = JSON(data:data) 39 | viewController.json = json 40 | } else { 41 | viewController.json = JSON.nullJSON 42 | } 43 | 44 | return true 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /Example/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Example/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /Example/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /Example/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "extent" : "full-screen", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "filename" : "Default@2x.png", 15 | "minimum-system-version" : "7.0", 16 | "orientation" : "portrait", 17 | "scale" : "2x" 18 | }, 19 | { 20 | "orientation" : "portrait", 21 | "idiom" : "ipad", 22 | "extent" : "full-screen", 23 | "minimum-system-version" : "7.0", 24 | "scale" : "1x" 25 | }, 26 | { 27 | "orientation" : "landscape", 28 | "idiom" : "ipad", 29 | "extent" : "full-screen", 30 | "minimum-system-version" : "7.0", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "orientation" : "portrait", 35 | "idiom" : "ipad", 36 | "extent" : "full-screen", 37 | "minimum-system-version" : "7.0", 38 | "scale" : "2x" 39 | }, 40 | { 41 | "orientation" : "landscape", 42 | "idiom" : "ipad", 43 | "extent" : "full-screen", 44 | "minimum-system-version" : "7.0", 45 | "scale" : "2x" 46 | } 47 | ], 48 | "info" : { 49 | "version" : 1, 50 | "author" : "xcode" 51 | } 52 | } -------------------------------------------------------------------------------- /Example/Images.xcassets/LaunchImage.launchimage/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aemaeth-me/SwiftyJSON/8edd3e252bdcc520f28f3b483b6cfe235b0e0f5b/Example/Images.xcassets/LaunchImage.launchimage/Default@2x.png -------------------------------------------------------------------------------- /Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Example/SwiftyJSONTests.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "coordinates":null, 4 | "truncated":false, 5 | "created_at":"Tue Aug 28 21:16:23 +0000 2012", 6 | "favorited":false, 7 | "id_str":"240558470661799936", 8 | "in_reply_to_user_id_str":null, 9 | "entities":{ 10 | "urls":[ 11 | 12 | ], 13 | "hashtags":[ 14 | 15 | ], 16 | "user_mentions":[ 17 | 18 | ] 19 | }, 20 | "text":"just another test", 21 | "contributors":null, 22 | "id":240558470661799936, 23 | "retweet_count":0, 24 | "in_reply_to_status_id_str":null, 25 | "geo":null, 26 | "retweeted":false, 27 | "in_reply_to_user_id":null, 28 | "place":null, 29 | "source":"<a href=\"//realitytechnicians.com\" rel=\"\"nofollow\"\">OAuth Dancer Reborn</a>", 30 | "user":{ 31 | "name":"OAuth Dancer", 32 | "profile_sidebar_fill_color":"DDEEF6", 33 | "profile_background_tile":true, 34 | "profile_sidebar_border_color":"C0DEED", 35 | "profile_image_url":"http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg", 36 | "created_at":"Wed Mar 03 19:37:35 +0000 2010", 37 | "location":"San Francisco, CA", 38 | "follow_request_sent":false, 39 | "id_str":"119476949", 40 | "is_translator":false, 41 | "profile_link_color":"0084B4", 42 | "entities":{ 43 | "url":{ 44 | "urls":[ 45 | { 46 | "expanded_url":null, 47 | "url":"http://bit.ly/oauth-dancer", 48 | "indices":[ 49 | 0, 50 | 26 51 | ], 52 | "display_url":null 53 | } 54 | ] 55 | }, 56 | "description":null 57 | }, 58 | "default_profile":false, 59 | "url":"http://bit.ly/oauth-dancer", 60 | "contributors_enabled":false, 61 | "favourites_count":7, 62 | "utc_offset":null, 63 | "profile_image_url_https":"https://si0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg", 64 | "id":119476949, 65 | "listed_count":1, 66 | "profile_use_background_image":true, 67 | "profile_text_color":"333333", 68 | "followers_count":28, 69 | "lang":"en", 70 | "protected":false, 71 | "geo_enabled":true, 72 | "notifications":false, 73 | "description":"", 74 | "profile_background_color":"C0DEED", 75 | "verified":false, 76 | "time_zone":null, 77 | "profile_background_image_url_https":"https://si0.twimg.com/profile_background_images/80151733/oauth-dance.png", 78 | "statuses_count":166, 79 | "profile_background_image_url":"http://a0.twimg.com/profile_background_images/80151733/oauth-dance.png", 80 | "default_profile_image":false, 81 | "friends_count":14, 82 | "following":false, 83 | "show_all_inline_media":false, 84 | "screen_name":"oauth_dancer" 85 | }, 86 | "in_reply_to_screen_name":null, 87 | "in_reply_to_status_id":null 88 | }, 89 | { 90 | "coordinates":{ 91 | "coordinates":[ 92 | -122.25831, 93 | 37.871609 94 | ], 95 | "type":"Point" 96 | }, 97 | "truncated":false, 98 | "created_at":"Tue Aug 28 21:08:15 +0000 2012", 99 | "favorited":false, 100 | "id_str":"240556426106372096", 101 | "in_reply_to_user_id_str":null, 102 | "entities":{ 103 | "urls":[ 104 | { 105 | "expanded_url":"http://blogs.ischool.berkeley.edu/i290-abdt-s12/", 106 | "url":"http://t.co/bfj7zkDJ", 107 | "indices":[ 108 | 79, 109 | 99 110 | ], 111 | "display_url":"blogs.ischool.berkeley.edu/i290-abdt-s12/" 112 | } 113 | ], 114 | "hashtags":[ 115 | 116 | ], 117 | "user_mentions":[ 118 | { 119 | "name":"Cal", 120 | "id_str":"17445752", 121 | "id":17445752, 122 | "indices":[ 123 | 60, 124 | 64 125 | ], 126 | "screen_name":"Cal" 127 | }, 128 | { 129 | "name":"Othman Laraki", 130 | "id_str":"20495814", 131 | "id":20495814, 132 | "indices":[ 133 | 70, 134 | 77 135 | ], 136 | "screen_name":"othman" 137 | } 138 | ] 139 | }, 140 | "text":"lecturing at the \"analyzing big data with twitter\" class at @cal with @othman http://t.co/bfj7zkDJ", 141 | "contributors":null, 142 | "id":240556426106372096, 143 | "retweet_count":3, 144 | "in_reply_to_status_id_str":null, 145 | "geo":{ 146 | "coordinates":[ 147 | 37.871609, 148 | -122.25831 149 | ], 150 | "type":"Point" 151 | }, 152 | "retweeted":false, 153 | "possibly_sensitive":false, 154 | "in_reply_to_user_id":null, 155 | "place":{ 156 | "name":"Berkeley", 157 | "country_code":"US", 158 | "country":"United States", 159 | "attributes":{ 160 | 161 | }, 162 | "url":"http://api.twitter.com/1/geo/id/5ef5b7f391e30aff.json", 163 | "id":"5ef5b7f391e30aff", 164 | "bounding_box":{ 165 | "coordinates":[ 166 | [ 167 | [ 168 | -122.367781, 169 | 37.835727 170 | ], 171 | [ 172 | -122.234185, 173 | 37.835727 174 | ], 175 | [ 176 | -122.234185, 177 | 37.905824 178 | ], 179 | [ 180 | -122.367781, 181 | 37.905824 182 | ] 183 | ] 184 | ], 185 | "type":"Polygon" 186 | }, 187 | "full_name":"Berkeley, CA", 188 | "place_type":"city" 189 | }, 190 | "source":"<a href=\"//www.apple.com\"\" rel=\"\"nofollow\"\">Safari on iOS</a>", 191 | "user":{ 192 | "name":"Raffi Krikorian", 193 | "profile_sidebar_fill_color":"DDEEF6", 194 | "profile_background_tile":false, 195 | "profile_sidebar_border_color":"C0DEED", 196 | "profile_image_url":"http://a0.twimg.com/profile_images/1270234259/raffi-headshot-casual_normal.png", 197 | "created_at":"Sun Aug 19 14:24:06 +0000 2007", 198 | "location":"San Francisco, California", 199 | "follow_request_sent":false, 200 | "id_str":"8285392", 201 | "is_translator":false, 202 | "profile_link_color":"0084B4", 203 | "entities":{ 204 | "url":{ 205 | "urls":[ 206 | { 207 | "expanded_url":"http://about.me/raffi.krikorian", 208 | "url":"http://t.co/eNmnM6q", 209 | "indices":[ 210 | 0, 211 | 19 212 | ], 213 | "display_url":"about.me/raffi.krikorian" 214 | } 215 | ] 216 | }, 217 | "description":{ 218 | "urls":[ 219 | 220 | ] 221 | } 222 | }, 223 | "default_profile":true, 224 | "url":"http://t.co/eNmnM6q", 225 | "contributors_enabled":false, 226 | "favourites_count":724, 227 | "utc_offset":-28800, 228 | "profile_image_url_https":"https://si0.twimg.com/profile_images/1270234259/raffi-headshot-casual_normal.png", 229 | "id":8285392, 230 | "listed_count":619, 231 | "profile_use_background_image":true, 232 | "profile_text_color":"333333", 233 | "followers_count":18752, 234 | "lang":"en", 235 | "protected":false, 236 | "geo_enabled":true, 237 | "notifications":false, 238 | "description":"Director of @twittereng's Platform Services. I break things.", 239 | "profile_background_color":"C0DEED", 240 | "verified":false, 241 | "time_zone":"Pacific Time (US & Canada)", 242 | "profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme1/bg.png", 243 | "statuses_count":5007, 244 | "profile_background_image_url":"http://a0.twimg.com/images/themes/theme1/bg.png", 245 | "default_profile_image":false, 246 | "friends_count":701, 247 | "following":true, 248 | "show_all_inline_media":true, 249 | "screen_name":"raffi" 250 | }, 251 | "in_reply_to_screen_name":null, 252 | "in_reply_to_status_id":null 253 | }, 254 | { 255 | "coordinates":null, 256 | "truncated":false, 257 | "created_at":"Tue Aug 28 19:59:34 +0000 2012", 258 | "favorited":false, 259 | "id_str":"240539141056638977", 260 | "in_reply_to_user_id_str":null, 261 | "entities":{ 262 | "urls":[ 263 | 264 | ], 265 | "hashtags":[ 266 | 267 | ], 268 | "user_mentions":[ 269 | 270 | ] 271 | }, 272 | "text":"You'd be right more often if you thought you were wrong.", 273 | "contributors":null, 274 | "id":240539141056638977, 275 | "retweet_count":1, 276 | "in_reply_to_status_id_str":null, 277 | "geo":null, 278 | "retweeted":false, 279 | "in_reply_to_user_id":null, 280 | "place":null, 281 | "source":"web", 282 | "user":{ 283 | "name":"Taylor Singletary", 284 | "profile_sidebar_fill_color":"FBFBFB", 285 | "profile_background_tile":true, 286 | "profile_sidebar_border_color":"000000", 287 | "profile_image_url":"http://a0.twimg.com/profile_images/2546730059/f6a8zq58mg1hn0ha8vie_normal.jpeg", 288 | "created_at":"Wed Mar 07 22:23:19 +0000 2007", 289 | "location":"San Francisco, CA", 290 | "follow_request_sent":false, 291 | "id_str":"819797", 292 | "is_translator":false, 293 | "profile_link_color":"c71818", 294 | "entities":{ 295 | "url":{ 296 | "urls":[ 297 | { 298 | "expanded_url":"http://www.rebelmouse.com/episod/", 299 | "url":"http://t.co/Lxw7upbN", 300 | "indices":[ 301 | 0, 302 | 20 303 | ], 304 | "display_url":"rebelmouse.com/episod/" 305 | } 306 | ] 307 | }, 308 | "description":{ 309 | "urls":[ 310 | 311 | ] 312 | } 313 | }, 314 | "default_profile":false, 315 | "url":"http://t.co/Lxw7upbN", 316 | "contributors_enabled":false, 317 | "favourites_count":15990, 318 | "utc_offset":-28800, 319 | "profile_image_url_https":"https://si0.twimg.com/profile_images/2546730059/f6a8zq58mg1hn0ha8vie_normal.jpeg", 320 | "id":819797, 321 | "listed_count":340, 322 | "profile_use_background_image":true, 323 | "profile_text_color":"D20909", 324 | "followers_count":7126, 325 | "lang":"en", 326 | "protected":false, 327 | "geo_enabled":true, 328 | "notifications":false, 329 | "description":"Reality Technician, Twitter API team, synthesizer enthusiast; a most excellent adventure in timelines. I know it's hard to believe in something you can't see.", 330 | "profile_background_color":"000000", 331 | "verified":false, 332 | "time_zone":"Pacific Time (US & Canada)", 333 | "profile_background_image_url_https":"https://si0.twimg.com/profile_background_images/643655842/hzfv12wini4q60zzrthg.png", 334 | "statuses_count":18076, 335 | "profile_background_image_url":"http://a0.twimg.com/profile_background_images/643655842/hzfv12wini4q60zzrthg.png", 336 | "default_profile_image":false, 337 | "friends_count":5444, 338 | "following":true, 339 | "show_all_inline_media":true, 340 | "screen_name":"episod" 341 | }, 342 | "in_reply_to_screen_name":null, 343 | "in_reply_to_status_id":null 344 | } 345 | ] -------------------------------------------------------------------------------- /Example/ViewController.swift: -------------------------------------------------------------------------------- 1 | // SwiftyJSON.h 2 | // 3 | // Copyright (c) 2014 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 UIKit 24 | import SwiftyJSON 25 | 26 | class ViewController: UITableViewController { 27 | 28 | var json: JSON = JSON.nullJSON 29 | 30 | // MARK: - Table view data source 31 | 32 | override func numberOfSectionsInTableView(tableView: UITableView) -> Int { 33 | return 1 34 | } 35 | 36 | override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 37 | switch self.json.type { 38 | case Type.Array, Type.Dictionary: 39 | return self.json.count 40 | default: 41 | return 1 42 | } 43 | } 44 | 45 | override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 46 | let cell = tableView.dequeueReusableCellWithIdentifier("JSONCell", forIndexPath: indexPath) as UITableViewCell 47 | 48 | var row = indexPath.row 49 | 50 | switch self.json.type { 51 | case .Array: 52 | cell.textLabel?.text = "\(row)" 53 | cell.detailTextLabel?.text = self.json.arrayValue.description 54 | case .Dictionary: 55 | let key: AnyObject = (self.json.object as NSDictionary).allKeys[row] 56 | let value = self.json[key as String] 57 | cell.textLabel?.text = "\(key)" 58 | cell.detailTextLabel?.text = value.description 59 | default: 60 | cell.textLabel?.text = "" 61 | cell.detailTextLabel?.text = self.json.description 62 | } 63 | 64 | return cell 65 | } 66 | 67 | // MARK: - Navigation 68 | 69 | override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { 70 | 71 | var object: AnyObject 72 | switch UIDevice.currentDevice().systemVersion.compare("8.0.0", options: NSStringCompareOptions.NumericSearch) { 73 | case .OrderedSame, .OrderedDescending: 74 | object = segue.destinationViewController.topViewController 75 | case .OrderedAscending: 76 | object = segue.destinationViewController 77 | } 78 | 79 | if let nextController = object as? ViewController { 80 | 81 | if let indexPath = self.tableView.indexPathForSelectedRow() { 82 | var row = indexPath.row 83 | var nextJson: JSON = JSON.nullJSON 84 | 85 | switch self.json.type { 86 | case .Array: 87 | nextJson = self.json[row] 88 | case .Dictionary where row < self.json.dictionaryValue.count: 89 | let key = self.json.dictionaryValue.keys.array[row] 90 | if let value = self.json.dictionary?[key] { 91 | nextJson = value 92 | } 93 | default: 94 | print("") 95 | } 96 | nextController.json = nextJson 97 | print(nextJson) 98 | } 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Ruoyu Fu 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #SwiftyJSON [中文介绍](http://tangplin.github.io/swiftyjson/) 2 | 3 | SwiftyJSON makes it easy to deal with JSON data in Swift. 4 | 5 | 1. [Why is the typical JSON handling in Swift NOT good](#why-is-the-typical-json-handling-in-swift-not-good) 6 | 1. [Requirements](#requirements) 7 | 1. [Integration](#integration) 8 | 1. [Usage](#usage) 9 | - [Initialization](#initialization) 10 | - [Subscript](#subscript) 11 | - [Loop](#loop) 12 | - [Error](#error) 13 | - [Optional getter](#optional-getter) 14 | - [Non-optional getter](#non-optional-getter) 15 | - [Setter](#setter) 16 | - [Raw object](#raw-object) 17 | - [Literal convertibles](#literal-convertibles) 18 | 1. [Work with Alamofire](#work-with-alamofire) 19 | 20 | ##Why is the typical JSON handling in Swift NOT good? 21 | Swift is very strict about types. But although explicit typing is good for saving us from mistakes, it becomes painful when dealing with JSON and other areas that are, by nature, implicit about types. 22 | 23 | Take the Twitter API for example. Say we want to retrieve a user's "name" value of some tweet in Swift (according to Twitter's API https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline). 24 | 25 | The code would look like this: 26 | 27 | ```swift 28 | 29 | let jsonObject : AnyObject! = NSJSONSerialization.JSONObjectWithData(dataFromTwitter, options: NSJSONReadingOptions.MutableContainers, error: nil) 30 | if let statusesArray = jsonObject as? NSArray{ 31 | if let aStatus = statusesArray[0] as? NSDictionary{ 32 | if let user = aStatus["user"] as? NSDictionary{ 33 | if let userName = user["name"] as? NSDictionary{ 34 | //Finally We Got The Name 35 | 36 | } 37 | } 38 | } 39 | } 40 | 41 | ``` 42 | 43 | It's not good. 44 | 45 | Even if we use optional chaining, it would also cause a mess: 46 | 47 | ```swift 48 | 49 | let jsonObject : AnyObject! = NSJSONSerialization.JSONObjectWithData(dataFromTwitter, options: NSJSONReadingOptions.MutableContainers, error: nil) 50 | if let userName = (((jsonObject as? NSArray)?[0] as? NSDictionary)?["user"] as? NSDictionary)?["name"]{ 51 | //What A disaster above 52 | } 53 | 54 | ``` 55 | An unreadable mess--for something that should really be simple! 56 | 57 | With SwiftyJSON all you have to do is: 58 | 59 | ```swift 60 | 61 | let json = JSON(data: dataFromNetworking) 62 | if let userName = json[0]["user"]["name"].string{ 63 | //Now you got your value 64 | } 65 | 66 | ``` 67 | 68 | And don't worry about the Optional Wrapping thing. It's done for you automatically 69 | 70 | ```swift 71 | 72 | let json = JSON(data: dataFromNetworking) 73 | if let userName = json[999999]["wrong_key"]["wrong_name"].string{ 74 | //Calm down, take it easy, the ".string" property still produces the correct Optional String type with safety 75 | } else { 76 | //Print the error 77 | println(json[999999]["wrong_key"]["wrong_name"]) 78 | } 79 | 80 | ``` 81 | 82 | ## Requirements 83 | 84 | - iOS 7.0+ / Mac OS X 10.9+ 85 | - Xcode 6.1 86 | 87 | ##Integration 88 | 89 | You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding 90 | `github "SwiftyJSON/SwiftyJSON" >= 2.1.2` to your `Cartfile` 91 | 92 | CocoaPods is now supported for Swift yet. But to use this library in your project manually you should: 93 | 94 | 1. for Projects just drag SwiftyJSON.swift to the project tree 95 | 2. for Workspaces you may include the whole SwiftyJSON.xcodeproj as suggested by @garnett 96 | 97 | ## Usage 98 | 99 | ####Initialization 100 | ```swift 101 | let json = JSON(data: dataFromNetworking) 102 | ``` 103 | ```swift 104 | let json = JSON(jsonObject) 105 | ``` 106 | 107 | ####Subscript 108 | ```swift 109 | //With a int from JSON supposed to an Array 110 | let name = json[0].double 111 | ``` 112 | ```swift 113 | //With a string from JSON supposed to an Dictionary 114 | let name = json["name"].stringValue 115 | ``` 116 | ```swift 117 | //With an array like path to the element 118 | let path = [1,"list",2,"name"] 119 | let name = json[path].string 120 | //Just the same 121 | let name = json[1]["list"][2]["name"].string 122 | ``` 123 | ```swift 124 | //With a literal array to the element 125 | let name = json[1,"list",2,"name"].string 126 | //Just the same 127 | let name = json[1]["list"][2]["name"].string 128 | ``` 129 | ```swift 130 | //With a Hard Way 131 | let name = json[[1,"list",2,"name"]].string 132 | ``` 133 | ####Loop 134 | ```swift 135 | //If json is .Dictionary 136 | for (key: String, subJson: JSON) in json { 137 | //Do something you want 138 | } 139 | ``` 140 | *The first element is always String, even if the JSON's object is Array* 141 | ```swift 142 | //If json is .Array 143 | //The `index` is 0.. = json["list"].arrayValue 241 | ``` 242 | ```swift 243 | //If not a Dictionary or nil, return [:] 244 | let user: Dictionary = json["user"].dictionaryValue 245 | ``` 246 | 247 | ####Setter 248 | ```swift 249 | json["name"] = JSON("new-name") 250 | json[0] = JSON(1) 251 | ``` 252 | ```swift 253 | json["id"].int = 1234567890 254 | json["coordinate"].double = 8766.766 255 | json["name"].string = "Jack" 256 | json.array = [1,2,3,4] 257 | json.dictionary = ["name":"Jack", "age":25] 258 | ``` 259 | 260 | ####Raw object 261 | ```swift 262 | let jsonObject: AnyObject = json.object 263 | ``` 264 | ```swift 265 | if let jsonObject: AnyObject = json.rawValue 266 | ``` 267 | ```swift 268 | //convert the JSON to raw NSData 269 | if let data = json.rawData() { 270 | //Do something you want 271 | } 272 | ``` 273 | ```swift 274 | //convert the JSON to raw String 275 | if let string = json.rawString() { 276 | //Do something you want 277 | } 278 | ``` 279 | ####Literal convertibles 280 | More info about the literal convertibles: [Swift Literal Convertibles](http://nshipster.com/swift-literal-convertible/) 281 | ```swift 282 | //StringLiteralConvertible 283 | let json:JSON = "I'm a json" 284 | ``` 285 | ```swift 286 | //IntegerLiteralConvertible 287 | let json:JSON = 12345 288 | ``` 289 | ```swift 290 | //BooleanLiteralConvertible 291 | let json:JSON = true 292 | ``` 293 | ```swift 294 | //FloatLiteralConvertible 295 | let json:JSON = 2.8765 296 | ``` 297 | ```swift 298 | //DictionaryLiteralConvertible 299 | let json:JSON = ["I":"am", "a":"json"] 300 | ``` 301 | ```swift 302 | //ArrayLiteralConvertible 303 | let json:JSON = ["I", "am", "a", "json"] 304 | ``` 305 | ```swift 306 | //NilLiteralConvertible 307 | let json:JSON = nil 308 | ``` 309 | ```swift 310 | //With subscript in array 311 | var json:JSON = [1,2,3] 312 | json[0] = 100 313 | json[1] = 200 314 | json[2] = 300 315 | json[999] = 300 //Don't worry, nothing will happen 316 | ``` 317 | ```swift 318 | //With subscript in dictionary 319 | var json:JSON = ["name":"Jack", "age": 25] 320 | json["name"] = "Mike" 321 | json["age"] = "25" //It's OK to set String 322 | json["address"] = "L.A." // Add the "address": "L.A." in json 323 | ``` 324 | ```swift 325 | //Array & Dictionary 326 | var json:JSON = ["name":"Jack", "age": 25, "list":["a","b","c",["what":"this"]]] 327 | json["list"][3]["what"] = "that" 328 | json["list",3,"what"] = "that" 329 | let path = ["list",3,"what"] 330 | json[path] = "that" 331 | ``` 332 | ##Work with Alamofire 333 | 334 | SwiftyJSON nicely wraps the result of the Alamofire JSON response handler: 335 | ```swift 336 | Alamofire.request(.GET, url, parameters: parameters) 337 | .responseJSON { (req, res, json, error) in 338 | if(error != nil) { 339 | NSLog("Error: \(error)") 340 | println(req) 341 | println(res) 342 | } 343 | else { 344 | NSLog("Success: \(url)") 345 | var json = JSON(json!) 346 | } 347 | } 348 | ``` 349 | -------------------------------------------------------------------------------- /Source/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.swiftyjson.${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 | -------------------------------------------------------------------------------- /Source/SwiftyJSON.h: -------------------------------------------------------------------------------- 1 | // SwiftyJSON.h 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 | //! Project version number for SwiftyJSON. 26 | FOUNDATION_EXPORT double SwiftyJSONVersionNumber; 27 | 28 | //! Project version string for SwiftyJSON. 29 | FOUNDATION_EXPORT const unsigned char SwiftyJSONVersionString[]; 30 | 31 | 32 | -------------------------------------------------------------------------------- /SwiftyJSON.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "SwiftyJSON" 3 | s.version = "2.1.2" 4 | s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" 5 | s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" 6 | s.license = { :type => "MIT" } 7 | s.authors = { "lingoer" => "lingoerer@gmail.com", "tangplin" => "tangplin@gmail.com" } 8 | 9 | s.osx.deployment_target = "10.9" 10 | s.ios.deployment_target = "7.0" 11 | s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.1.2"} 12 | s.source_files = "Source/*.swift" 13 | end 14 | -------------------------------------------------------------------------------- /SwiftyJSON.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 2E4FEFE119575BE100351305 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; 11 | 2E4FEFE719575BE100351305 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */; }; 12 | 4EC1C1D41A0C1A2D0026ED0B /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4EC1C1C91A0C1A2D0026ED0B /* SwiftyJSON.framework */; }; 13 | 4EC1C1E21A0C1A6E0026ED0B /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; 14 | 4EC1C1E31A0C1A750026ED0B /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; 15 | 4EC1C1E41A0C1A800026ED0B /* Tests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* Tests.json */; }; 16 | 4EC1C1E51A0C1A800026ED0B /* PerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */; }; 17 | 4EC1C1E61A0C1A800026ED0B /* BaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */; }; 18 | 4EC1C1E71A0C1A800026ED0B /* SequenceTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */; }; 19 | 4EC1C1E81A0C1A800026ED0B /* PrintableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C4A019E37FC600ADCC3D /* PrintableTests.swift */; }; 20 | 4EC1C1E91A0C1A800026ED0B /* SubscriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */; }; 21 | 4EC1C1EA1A0C1A800026ED0B /* LiteralConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */; }; 22 | 4EC1C1EB1A0C1A800026ED0B /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */; }; 23 | 4EC1C1EC1A0C1A800026ED0B /* ComparableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E519E3DF7800CDE086 /* ComparableTests.swift */; }; 24 | 4EC1C1ED1A0C1A800026ED0B /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E919E43C0700CDE086 /* StringTests.swift */; }; 25 | 4EC1C1EE1A0C1A800026ED0B /* NumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E719E439DA00CDE086 /* NumberTests.swift */; }; 26 | 4EC1C1EF1A0C1A800026ED0B /* RawTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A863BE2719EED46F0092A41F /* RawTests.swift */; }; 27 | 4EC1C1F01A0C1A800026ED0B /* DictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8B19E51D6500540692 /* DictionaryTests.swift */; }; 28 | 4EC1C1F11A0C1A800026ED0B /* ArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8D19E52F4200540692 /* ArrayTests.swift */; }; 29 | A819C49719E1A7DD00ADCC3D /* LiteralConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */; }; 30 | A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */; }; 31 | A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */; }; 32 | A819C4A119E37FC600ADCC3D /* PrintableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C4A019E37FC600ADCC3D /* PrintableTests.swift */; }; 33 | A8491E1E19CD6DAE00CCFAE6 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; 34 | A863BE2819EED46F0092A41F /* RawTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A863BE2719EED46F0092A41F /* RawTests.swift */; }; 35 | A86BAA0E19EBC32B009EAAEB /* PerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */; }; 36 | A87080E419E3C2A600CDE086 /* SequenceTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */; }; 37 | A87080E619E3DF7800CDE086 /* ComparableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E519E3DF7800CDE086 /* ComparableTests.swift */; }; 38 | A87080E819E439DA00CDE086 /* NumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E719E439DA00CDE086 /* NumberTests.swift */; }; 39 | A87080EA19E43C0700CDE086 /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E919E43C0700CDE086 /* StringTests.swift */; }; 40 | A885D1D219CF1EE6002FD4C3 /* BaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */; }; 41 | A885D1DC19CFCFF0002FD4C3 /* Tests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* Tests.json */; }; 42 | A8B66C8C19E51D6500540692 /* DictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8B19E51D6500540692 /* DictionaryTests.swift */; }; 43 | A8B66C8E19E52F4200540692 /* ArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8D19E52F4200540692 /* ArrayTests.swift */; }; 44 | /* End PBXBuildFile section */ 45 | 46 | /* Begin PBXContainerItemProxy section */ 47 | 2E4FEFE819575BE100351305 /* PBXContainerItemProxy */ = { 48 | isa = PBXContainerItemProxy; 49 | containerPortal = 2E4FEFD219575BE100351305 /* Project object */; 50 | proxyType = 1; 51 | remoteGlobalIDString = 2E4FEFDA19575BE100351305; 52 | remoteInfo = SwiftyJSON; 53 | }; 54 | 4EC1C1D51A0C1A2D0026ED0B /* PBXContainerItemProxy */ = { 55 | isa = PBXContainerItemProxy; 56 | containerPortal = 2E4FEFD219575BE100351305 /* Project object */; 57 | proxyType = 1; 58 | remoteGlobalIDString = 4EC1C1C81A0C1A2D0026ED0B; 59 | remoteInfo = SwiftyJSONOSX; 60 | }; 61 | /* End PBXContainerItemProxy section */ 62 | 63 | /* Begin PBXFileReference section */ 64 | 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65 | 2E4FEFDF19575BE100351305 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 66 | 2E4FEFE019575BE100351305 /* SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftyJSON.h; sourceTree = ""; }; 67 | 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftyJSONTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 68 | 4EC1C1C91A0C1A2D0026ED0B /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 69 | 4EC1C1D31A0C1A2D0026ED0B /* SwiftyJSONOSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftyJSONOSXTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 70 | A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LiteralConvertibleTests.swift; sourceTree = ""; }; 71 | A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentableTests.swift; sourceTree = ""; }; 72 | A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptTests.swift; sourceTree = ""; }; 73 | A819C4A019E37FC600ADCC3D /* PrintableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrintableTests.swift; sourceTree = ""; }; 74 | A82A1C0D19D922DC009A653D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 75 | A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSON.swift; sourceTree = ""; }; 76 | A863BE2719EED46F0092A41F /* RawTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawTests.swift; sourceTree = ""; }; 77 | A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PerformanceTests.swift; sourceTree = ""; }; 78 | A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SequenceTypeTests.swift; sourceTree = ""; }; 79 | A87080E519E3DF7800CDE086 /* ComparableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComparableTests.swift; sourceTree = ""; }; 80 | A87080E719E439DA00CDE086 /* NumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumberTests.swift; sourceTree = ""; }; 81 | A87080E919E43C0700CDE086 /* StringTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringTests.swift; sourceTree = ""; }; 82 | A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseTests.swift; sourceTree = ""; }; 83 | A885D1DA19CFCFF0002FD4C3 /* Tests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Tests.json; sourceTree = ""; }; 84 | A8B66C8B19E51D6500540692 /* DictionaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DictionaryTests.swift; sourceTree = ""; }; 85 | A8B66C8D19E52F4200540692 /* ArrayTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayTests.swift; sourceTree = ""; }; 86 | /* End PBXFileReference section */ 87 | 88 | /* Begin PBXFrameworksBuildPhase section */ 89 | 2E4FEFD719575BE100351305 /* Frameworks */ = { 90 | isa = PBXFrameworksBuildPhase; 91 | buildActionMask = 2147483647; 92 | files = ( 93 | ); 94 | runOnlyForDeploymentPostprocessing = 0; 95 | }; 96 | 2E4FEFE319575BE100351305 /* Frameworks */ = { 97 | isa = PBXFrameworksBuildPhase; 98 | buildActionMask = 2147483647; 99 | files = ( 100 | 2E4FEFE719575BE100351305 /* SwiftyJSON.framework in Frameworks */, 101 | ); 102 | runOnlyForDeploymentPostprocessing = 0; 103 | }; 104 | 4EC1C1C51A0C1A2D0026ED0B /* Frameworks */ = { 105 | isa = PBXFrameworksBuildPhase; 106 | buildActionMask = 2147483647; 107 | files = ( 108 | ); 109 | runOnlyForDeploymentPostprocessing = 0; 110 | }; 111 | 4EC1C1D01A0C1A2D0026ED0B /* Frameworks */ = { 112 | isa = PBXFrameworksBuildPhase; 113 | buildActionMask = 2147483647; 114 | files = ( 115 | 4EC1C1D41A0C1A2D0026ED0B /* SwiftyJSON.framework in Frameworks */, 116 | ); 117 | runOnlyForDeploymentPostprocessing = 0; 118 | }; 119 | /* End PBXFrameworksBuildPhase section */ 120 | 121 | /* Begin PBXGroup section */ 122 | 2E4FEFD119575BE100351305 = { 123 | isa = PBXGroup; 124 | children = ( 125 | 2E4FEFDD19575BE100351305 /* Source */, 126 | 2E4FEFEA19575BE100351305 /* Tests */, 127 | 2E4FEFDC19575BE100351305 /* Products */, 128 | ); 129 | sourceTree = ""; 130 | }; 131 | 2E4FEFDC19575BE100351305 /* Products */ = { 132 | isa = PBXGroup; 133 | children = ( 134 | 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */, 135 | 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */, 136 | 4EC1C1C91A0C1A2D0026ED0B /* SwiftyJSON.framework */, 137 | 4EC1C1D31A0C1A2D0026ED0B /* SwiftyJSONOSXTests.xctest */, 138 | ); 139 | name = Products; 140 | sourceTree = ""; 141 | }; 142 | 2E4FEFDD19575BE100351305 /* Source */ = { 143 | isa = PBXGroup; 144 | children = ( 145 | 2E4FEFE019575BE100351305 /* SwiftyJSON.h */, 146 | A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */, 147 | 2E4FEFDE19575BE100351305 /* Supporting Files */, 148 | ); 149 | path = Source; 150 | sourceTree = ""; 151 | }; 152 | 2E4FEFDE19575BE100351305 /* Supporting Files */ = { 153 | isa = PBXGroup; 154 | children = ( 155 | 2E4FEFDF19575BE100351305 /* Info.plist */, 156 | ); 157 | name = "Supporting Files"; 158 | sourceTree = ""; 159 | }; 160 | 2E4FEFEA19575BE100351305 /* Tests */ = { 161 | isa = PBXGroup; 162 | children = ( 163 | A885D1DA19CFCFF0002FD4C3 /* Tests.json */, 164 | A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */, 165 | A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */, 166 | A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */, 167 | A819C4A019E37FC600ADCC3D /* PrintableTests.swift */, 168 | A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */, 169 | A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */, 170 | A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */, 171 | A87080E519E3DF7800CDE086 /* ComparableTests.swift */, 172 | A87080E919E43C0700CDE086 /* StringTests.swift */, 173 | A87080E719E439DA00CDE086 /* NumberTests.swift */, 174 | A863BE2719EED46F0092A41F /* RawTests.swift */, 175 | A8B66C8B19E51D6500540692 /* DictionaryTests.swift */, 176 | A8B66C8D19E52F4200540692 /* ArrayTests.swift */, 177 | 2E4FEFEB19575BE100351305 /* Supporting Files */, 178 | ); 179 | path = Tests; 180 | sourceTree = ""; 181 | }; 182 | 2E4FEFEB19575BE100351305 /* Supporting Files */ = { 183 | isa = PBXGroup; 184 | children = ( 185 | A82A1C0D19D922DC009A653D /* Info.plist */, 186 | ); 187 | name = "Supporting Files"; 188 | sourceTree = ""; 189 | }; 190 | /* End PBXGroup section */ 191 | 192 | /* Begin PBXHeadersBuildPhase section */ 193 | 2E4FEFD819575BE100351305 /* Headers */ = { 194 | isa = PBXHeadersBuildPhase; 195 | buildActionMask = 2147483647; 196 | files = ( 197 | 2E4FEFE119575BE100351305 /* SwiftyJSON.h in Headers */, 198 | ); 199 | runOnlyForDeploymentPostprocessing = 0; 200 | }; 201 | 4EC1C1C61A0C1A2D0026ED0B /* Headers */ = { 202 | isa = PBXHeadersBuildPhase; 203 | buildActionMask = 2147483647; 204 | files = ( 205 | 4EC1C1E21A0C1A6E0026ED0B /* SwiftyJSON.h in Headers */, 206 | ); 207 | runOnlyForDeploymentPostprocessing = 0; 208 | }; 209 | /* End PBXHeadersBuildPhase section */ 210 | 211 | /* Begin PBXNativeTarget section */ 212 | 2E4FEFDA19575BE100351305 /* SwiftyJSON */ = { 213 | isa = PBXNativeTarget; 214 | buildConfigurationList = 2E4FEFF119575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON" */; 215 | buildPhases = ( 216 | 2E4FEFD619575BE100351305 /* Sources */, 217 | 2E4FEFD719575BE100351305 /* Frameworks */, 218 | 2E4FEFD819575BE100351305 /* Headers */, 219 | 2E4FEFD919575BE100351305 /* Resources */, 220 | ); 221 | buildRules = ( 222 | ); 223 | dependencies = ( 224 | ); 225 | name = SwiftyJSON; 226 | productName = SwiftyJSON; 227 | productReference = 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */; 228 | productType = "com.apple.product-type.framework"; 229 | }; 230 | 2E4FEFE519575BE100351305 /* SwiftyJSONTests */ = { 231 | isa = PBXNativeTarget; 232 | buildConfigurationList = 2E4FEFF419575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSONTests" */; 233 | buildPhases = ( 234 | 2E4FEFE219575BE100351305 /* Sources */, 235 | 2E4FEFE319575BE100351305 /* Frameworks */, 236 | 2E4FEFE419575BE100351305 /* Resources */, 237 | ); 238 | buildRules = ( 239 | ); 240 | dependencies = ( 241 | 2E4FEFE919575BE100351305 /* PBXTargetDependency */, 242 | ); 243 | name = SwiftyJSONTests; 244 | productName = SwiftyJSONTests; 245 | productReference = 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */; 246 | productType = "com.apple.product-type.bundle.unit-test"; 247 | }; 248 | 4EC1C1C81A0C1A2D0026ED0B /* SwiftyJSONOSX */ = { 249 | isa = PBXNativeTarget; 250 | buildConfigurationList = 4EC1C1DC1A0C1A2D0026ED0B /* Build configuration list for PBXNativeTarget "SwiftyJSONOSX" */; 251 | buildPhases = ( 252 | 4EC1C1C41A0C1A2D0026ED0B /* Sources */, 253 | 4EC1C1C51A0C1A2D0026ED0B /* Frameworks */, 254 | 4EC1C1C61A0C1A2D0026ED0B /* Headers */, 255 | 4EC1C1C71A0C1A2D0026ED0B /* Resources */, 256 | ); 257 | buildRules = ( 258 | ); 259 | dependencies = ( 260 | ); 261 | name = SwiftyJSONOSX; 262 | productName = SwiftyJSONOSX; 263 | productReference = 4EC1C1C91A0C1A2D0026ED0B /* SwiftyJSON.framework */; 264 | productType = "com.apple.product-type.framework"; 265 | }; 266 | 4EC1C1D21A0C1A2D0026ED0B /* SwiftyJSONOSXTests */ = { 267 | isa = PBXNativeTarget; 268 | buildConfigurationList = 4EC1C1DF1A0C1A2D0026ED0B /* Build configuration list for PBXNativeTarget "SwiftyJSONOSXTests" */; 269 | buildPhases = ( 270 | 4EC1C1CF1A0C1A2D0026ED0B /* Sources */, 271 | 4EC1C1D01A0C1A2D0026ED0B /* Frameworks */, 272 | 4EC1C1D11A0C1A2D0026ED0B /* Resources */, 273 | ); 274 | buildRules = ( 275 | ); 276 | dependencies = ( 277 | 4EC1C1D61A0C1A2D0026ED0B /* PBXTargetDependency */, 278 | ); 279 | name = SwiftyJSONOSXTests; 280 | productName = SwiftyJSONOSXTests; 281 | productReference = 4EC1C1D31A0C1A2D0026ED0B /* SwiftyJSONOSXTests.xctest */; 282 | productType = "com.apple.product-type.bundle.unit-test"; 283 | }; 284 | /* End PBXNativeTarget section */ 285 | 286 | /* Begin PBXProject section */ 287 | 2E4FEFD219575BE100351305 /* Project object */ = { 288 | isa = PBXProject; 289 | attributes = { 290 | LastUpgradeCheck = 0600; 291 | TargetAttributes = { 292 | 2E4FEFDA19575BE100351305 = { 293 | CreatedOnToolsVersion = 6.0; 294 | }; 295 | 2E4FEFE519575BE100351305 = { 296 | CreatedOnToolsVersion = 6.0; 297 | TestTargetID = 2E4FEFDA19575BE100351305; 298 | }; 299 | 4EC1C1C81A0C1A2D0026ED0B = { 300 | CreatedOnToolsVersion = 6.1; 301 | }; 302 | 4EC1C1D21A0C1A2D0026ED0B = { 303 | CreatedOnToolsVersion = 6.1; 304 | }; 305 | }; 306 | }; 307 | buildConfigurationList = 2E4FEFD519575BE100351305 /* Build configuration list for PBXProject "SwiftyJSON" */; 308 | compatibilityVersion = "Xcode 3.2"; 309 | developmentRegion = English; 310 | hasScannedForEncodings = 0; 311 | knownRegions = ( 312 | en, 313 | ); 314 | mainGroup = 2E4FEFD119575BE100351305; 315 | productRefGroup = 2E4FEFDC19575BE100351305 /* Products */; 316 | projectDirPath = ""; 317 | projectRoot = ""; 318 | targets = ( 319 | 2E4FEFDA19575BE100351305 /* SwiftyJSON */, 320 | 2E4FEFE519575BE100351305 /* SwiftyJSONTests */, 321 | 4EC1C1C81A0C1A2D0026ED0B /* SwiftyJSONOSX */, 322 | 4EC1C1D21A0C1A2D0026ED0B /* SwiftyJSONOSXTests */, 323 | ); 324 | }; 325 | /* End PBXProject section */ 326 | 327 | /* Begin PBXResourcesBuildPhase section */ 328 | 2E4FEFD919575BE100351305 /* Resources */ = { 329 | isa = PBXResourcesBuildPhase; 330 | buildActionMask = 2147483647; 331 | files = ( 332 | ); 333 | runOnlyForDeploymentPostprocessing = 0; 334 | }; 335 | 2E4FEFE419575BE100351305 /* Resources */ = { 336 | isa = PBXResourcesBuildPhase; 337 | buildActionMask = 2147483647; 338 | files = ( 339 | A885D1DC19CFCFF0002FD4C3 /* Tests.json in Resources */, 340 | ); 341 | runOnlyForDeploymentPostprocessing = 0; 342 | }; 343 | 4EC1C1C71A0C1A2D0026ED0B /* Resources */ = { 344 | isa = PBXResourcesBuildPhase; 345 | buildActionMask = 2147483647; 346 | files = ( 347 | ); 348 | runOnlyForDeploymentPostprocessing = 0; 349 | }; 350 | 4EC1C1D11A0C1A2D0026ED0B /* Resources */ = { 351 | isa = PBXResourcesBuildPhase; 352 | buildActionMask = 2147483647; 353 | files = ( 354 | 4EC1C1E41A0C1A800026ED0B /* Tests.json in Resources */, 355 | ); 356 | runOnlyForDeploymentPostprocessing = 0; 357 | }; 358 | /* End PBXResourcesBuildPhase section */ 359 | 360 | /* Begin PBXSourcesBuildPhase section */ 361 | 2E4FEFD619575BE100351305 /* Sources */ = { 362 | isa = PBXSourcesBuildPhase; 363 | buildActionMask = 2147483647; 364 | files = ( 365 | A8491E1E19CD6DAE00CCFAE6 /* SwiftyJSON.swift in Sources */, 366 | ); 367 | runOnlyForDeploymentPostprocessing = 0; 368 | }; 369 | 2E4FEFE219575BE100351305 /* Sources */ = { 370 | isa = PBXSourcesBuildPhase; 371 | buildActionMask = 2147483647; 372 | files = ( 373 | A87080E819E439DA00CDE086 /* NumberTests.swift in Sources */, 374 | A87080E419E3C2A600CDE086 /* SequenceTypeTests.swift in Sources */, 375 | A86BAA0E19EBC32B009EAAEB /* PerformanceTests.swift in Sources */, 376 | A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */, 377 | A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */, 378 | A863BE2819EED46F0092A41F /* RawTests.swift in Sources */, 379 | A885D1D219CF1EE6002FD4C3 /* BaseTests.swift in Sources */, 380 | A8B66C8E19E52F4200540692 /* ArrayTests.swift in Sources */, 381 | A8B66C8C19E51D6500540692 /* DictionaryTests.swift in Sources */, 382 | A819C4A119E37FC600ADCC3D /* PrintableTests.swift in Sources */, 383 | A819C49719E1A7DD00ADCC3D /* LiteralConvertibleTests.swift in Sources */, 384 | A87080EA19E43C0700CDE086 /* StringTests.swift in Sources */, 385 | A87080E619E3DF7800CDE086 /* ComparableTests.swift in Sources */, 386 | ); 387 | runOnlyForDeploymentPostprocessing = 0; 388 | }; 389 | 4EC1C1C41A0C1A2D0026ED0B /* Sources */ = { 390 | isa = PBXSourcesBuildPhase; 391 | buildActionMask = 2147483647; 392 | files = ( 393 | 4EC1C1E31A0C1A750026ED0B /* SwiftyJSON.swift in Sources */, 394 | ); 395 | runOnlyForDeploymentPostprocessing = 0; 396 | }; 397 | 4EC1C1CF1A0C1A2D0026ED0B /* Sources */ = { 398 | isa = PBXSourcesBuildPhase; 399 | buildActionMask = 2147483647; 400 | files = ( 401 | 4EC1C1E71A0C1A800026ED0B /* SequenceTypeTests.swift in Sources */, 402 | 4EC1C1EC1A0C1A800026ED0B /* ComparableTests.swift in Sources */, 403 | 4EC1C1EE1A0C1A800026ED0B /* NumberTests.swift in Sources */, 404 | 4EC1C1EB1A0C1A800026ED0B /* RawRepresentableTests.swift in Sources */, 405 | 4EC1C1E61A0C1A800026ED0B /* BaseTests.swift in Sources */, 406 | 4EC1C1F01A0C1A800026ED0B /* DictionaryTests.swift in Sources */, 407 | 4EC1C1E51A0C1A800026ED0B /* PerformanceTests.swift in Sources */, 408 | 4EC1C1EA1A0C1A800026ED0B /* LiteralConvertibleTests.swift in Sources */, 409 | 4EC1C1E81A0C1A800026ED0B /* PrintableTests.swift in Sources */, 410 | 4EC1C1ED1A0C1A800026ED0B /* StringTests.swift in Sources */, 411 | 4EC1C1EF1A0C1A800026ED0B /* RawTests.swift in Sources */, 412 | 4EC1C1F11A0C1A800026ED0B /* ArrayTests.swift in Sources */, 413 | 4EC1C1E91A0C1A800026ED0B /* SubscriptTests.swift in Sources */, 414 | ); 415 | runOnlyForDeploymentPostprocessing = 0; 416 | }; 417 | /* End PBXSourcesBuildPhase section */ 418 | 419 | /* Begin PBXTargetDependency section */ 420 | 2E4FEFE919575BE100351305 /* PBXTargetDependency */ = { 421 | isa = PBXTargetDependency; 422 | target = 2E4FEFDA19575BE100351305 /* SwiftyJSON */; 423 | targetProxy = 2E4FEFE819575BE100351305 /* PBXContainerItemProxy */; 424 | }; 425 | 4EC1C1D61A0C1A2D0026ED0B /* PBXTargetDependency */ = { 426 | isa = PBXTargetDependency; 427 | target = 4EC1C1C81A0C1A2D0026ED0B /* SwiftyJSONOSX */; 428 | targetProxy = 4EC1C1D51A0C1A2D0026ED0B /* PBXContainerItemProxy */; 429 | }; 430 | /* End PBXTargetDependency section */ 431 | 432 | /* Begin XCBuildConfiguration section */ 433 | 2E4FEFEF19575BE100351305 /* Debug */ = { 434 | isa = XCBuildConfiguration; 435 | buildSettings = { 436 | ALWAYS_SEARCH_USER_PATHS = NO; 437 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 438 | CLANG_CXX_LIBRARY = "libc++"; 439 | CLANG_ENABLE_MODULES = YES; 440 | CLANG_ENABLE_OBJC_ARC = YES; 441 | CLANG_WARN_BOOL_CONVERSION = YES; 442 | CLANG_WARN_CONSTANT_CONVERSION = YES; 443 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 444 | CLANG_WARN_EMPTY_BODY = YES; 445 | CLANG_WARN_ENUM_CONVERSION = YES; 446 | CLANG_WARN_INT_CONVERSION = YES; 447 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 448 | CLANG_WARN_UNREACHABLE_CODE = YES; 449 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 450 | CODE_SIGN_IDENTITY = "iPhone Developer"; 451 | COPY_PHASE_STRIP = NO; 452 | CURRENT_PROJECT_VERSION = 1; 453 | ENABLE_STRICT_OBJC_MSGSEND = YES; 454 | GCC_C_LANGUAGE_STANDARD = gnu99; 455 | GCC_DYNAMIC_NO_PIC = NO; 456 | GCC_OPTIMIZATION_LEVEL = 0; 457 | GCC_PREPROCESSOR_DEFINITIONS = ( 458 | "DEBUG=1", 459 | "$(inherited)", 460 | ); 461 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 462 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 463 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 464 | GCC_WARN_UNDECLARED_SELECTOR = YES; 465 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 466 | GCC_WARN_UNUSED_FUNCTION = YES; 467 | GCC_WARN_UNUSED_VARIABLE = YES; 468 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 469 | MACOSX_DEPLOYMENT_TARGET = 10.10; 470 | METAL_ENABLE_DEBUG_INFO = YES; 471 | ONLY_ACTIVE_ARCH = YES; 472 | SDKROOT = iphoneos; 473 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 474 | TARGETED_DEVICE_FAMILY = "1,2"; 475 | VERSIONING_SYSTEM = "apple-generic"; 476 | VERSION_INFO_PREFIX = ""; 477 | }; 478 | name = Debug; 479 | }; 480 | 2E4FEFF019575BE100351305 /* Release */ = { 481 | isa = XCBuildConfiguration; 482 | buildSettings = { 483 | ALWAYS_SEARCH_USER_PATHS = NO; 484 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 485 | CLANG_CXX_LIBRARY = "libc++"; 486 | CLANG_ENABLE_MODULES = YES; 487 | CLANG_ENABLE_OBJC_ARC = YES; 488 | CLANG_WARN_BOOL_CONVERSION = YES; 489 | CLANG_WARN_CONSTANT_CONVERSION = YES; 490 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 491 | CLANG_WARN_EMPTY_BODY = YES; 492 | CLANG_WARN_ENUM_CONVERSION = YES; 493 | CLANG_WARN_INT_CONVERSION = YES; 494 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 495 | CLANG_WARN_UNREACHABLE_CODE = YES; 496 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 497 | CODE_SIGN_IDENTITY = "iPhone Distribution"; 498 | COPY_PHASE_STRIP = YES; 499 | CURRENT_PROJECT_VERSION = 1; 500 | ENABLE_NS_ASSERTIONS = NO; 501 | ENABLE_STRICT_OBJC_MSGSEND = YES; 502 | GCC_C_LANGUAGE_STANDARD = gnu99; 503 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 504 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 505 | GCC_WARN_UNDECLARED_SELECTOR = YES; 506 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 507 | GCC_WARN_UNUSED_FUNCTION = YES; 508 | GCC_WARN_UNUSED_VARIABLE = YES; 509 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 510 | MACOSX_DEPLOYMENT_TARGET = 10.10; 511 | METAL_ENABLE_DEBUG_INFO = NO; 512 | SDKROOT = iphoneos; 513 | TARGETED_DEVICE_FAMILY = "1,2"; 514 | VALIDATE_PRODUCT = YES; 515 | VERSIONING_SYSTEM = "apple-generic"; 516 | VERSION_INFO_PREFIX = ""; 517 | }; 518 | name = Release; 519 | }; 520 | 2E4FEFF219575BE100351305 /* Debug */ = { 521 | isa = XCBuildConfiguration; 522 | buildSettings = { 523 | APPLICATION_EXTENSION_API_ONLY = YES; 524 | CODE_SIGN_IDENTITY = "iPhone Developer"; 525 | DEFINES_MODULE = YES; 526 | DYLIB_COMPATIBILITY_VERSION = 1; 527 | DYLIB_CURRENT_VERSION = 1; 528 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 529 | INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; 530 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 531 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 532 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 533 | PRODUCT_NAME = "$(TARGET_NAME)"; 534 | SKIP_INSTALL = YES; 535 | }; 536 | name = Debug; 537 | }; 538 | 2E4FEFF319575BE100351305 /* Release */ = { 539 | isa = XCBuildConfiguration; 540 | buildSettings = { 541 | APPLICATION_EXTENSION_API_ONLY = YES; 542 | CODE_SIGN_IDENTITY = "iPhone Distribution"; 543 | DEFINES_MODULE = YES; 544 | DYLIB_COMPATIBILITY_VERSION = 1; 545 | DYLIB_CURRENT_VERSION = 1; 546 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 547 | INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; 548 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 549 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 550 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 551 | PRODUCT_NAME = "$(TARGET_NAME)"; 552 | SKIP_INSTALL = YES; 553 | }; 554 | name = Release; 555 | }; 556 | 2E4FEFF519575BE100351305 /* Debug */ = { 557 | isa = XCBuildConfiguration; 558 | buildSettings = { 559 | FRAMEWORK_SEARCH_PATHS = ( 560 | "$(SDKROOT)/Developer/Library/Frameworks", 561 | "$(inherited)", 562 | ); 563 | GCC_PREPROCESSOR_DEFINITIONS = ( 564 | "DEBUG=1", 565 | "$(inherited)", 566 | ); 567 | INFOPLIST_FILE = Tests/Info.plist; 568 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 569 | METAL_ENABLE_DEBUG_INFO = YES; 570 | PRODUCT_NAME = "$(TARGET_NAME)"; 571 | }; 572 | name = Debug; 573 | }; 574 | 2E4FEFF619575BE100351305 /* Release */ = { 575 | isa = XCBuildConfiguration; 576 | buildSettings = { 577 | FRAMEWORK_SEARCH_PATHS = ( 578 | "$(SDKROOT)/Developer/Library/Frameworks", 579 | "$(inherited)", 580 | ); 581 | INFOPLIST_FILE = Tests/Info.plist; 582 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 583 | METAL_ENABLE_DEBUG_INFO = NO; 584 | PRODUCT_NAME = "$(TARGET_NAME)"; 585 | }; 586 | name = Release; 587 | }; 588 | 4EC1C1DD1A0C1A2D0026ED0B /* Debug */ = { 589 | isa = XCBuildConfiguration; 590 | buildSettings = { 591 | CODE_SIGN_IDENTITY = "Mac Developer"; 592 | COMBINE_HIDPI_IMAGES = YES; 593 | DEFINES_MODULE = YES; 594 | DYLIB_COMPATIBILITY_VERSION = 1; 595 | DYLIB_CURRENT_VERSION = 1; 596 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 597 | FRAMEWORK_VERSION = A; 598 | GCC_PREPROCESSOR_DEFINITIONS = ( 599 | "DEBUG=1", 600 | "$(inherited)", 601 | ); 602 | INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; 603 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 604 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; 605 | MTL_ENABLE_DEBUG_INFO = YES; 606 | PRODUCT_MODULE_NAME = SwiftyJSON; 607 | PRODUCT_NAME = SwiftyJSON; 608 | SDKROOT = macosx; 609 | SKIP_INSTALL = YES; 610 | }; 611 | name = Debug; 612 | }; 613 | 4EC1C1DE1A0C1A2D0026ED0B /* Release */ = { 614 | isa = XCBuildConfiguration; 615 | buildSettings = { 616 | CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application"; 617 | COMBINE_HIDPI_IMAGES = YES; 618 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 619 | DEFINES_MODULE = YES; 620 | DYLIB_COMPATIBILITY_VERSION = 1; 621 | DYLIB_CURRENT_VERSION = 1; 622 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 623 | FRAMEWORK_VERSION = A; 624 | INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; 625 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 626 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; 627 | MTL_ENABLE_DEBUG_INFO = NO; 628 | PRODUCT_MODULE_NAME = SwiftyJSON; 629 | PRODUCT_NAME = SwiftyJSON; 630 | SDKROOT = macosx; 631 | SKIP_INSTALL = YES; 632 | }; 633 | name = Release; 634 | }; 635 | 4EC1C1E01A0C1A2D0026ED0B /* Debug */ = { 636 | isa = XCBuildConfiguration; 637 | buildSettings = { 638 | CODE_SIGN_IDENTITY = "Mac Developer"; 639 | COMBINE_HIDPI_IMAGES = YES; 640 | FRAMEWORK_SEARCH_PATHS = ( 641 | "$(DEVELOPER_FRAMEWORKS_DIR)", 642 | "$(inherited)", 643 | ); 644 | GCC_PREPROCESSOR_DEFINITIONS = ( 645 | "DEBUG=1", 646 | "$(inherited)", 647 | ); 648 | INFOPLIST_FILE = Tests/Info.plist; 649 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 650 | MACOSX_DEPLOYMENT_TARGET = 10.10; 651 | MTL_ENABLE_DEBUG_INFO = YES; 652 | PRODUCT_NAME = "$(TARGET_NAME)"; 653 | SDKROOT = macosx; 654 | }; 655 | name = Debug; 656 | }; 657 | 4EC1C1E11A0C1A2D0026ED0B /* Release */ = { 658 | isa = XCBuildConfiguration; 659 | buildSettings = { 660 | CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application"; 661 | COMBINE_HIDPI_IMAGES = YES; 662 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 663 | FRAMEWORK_SEARCH_PATHS = ( 664 | "$(DEVELOPER_FRAMEWORKS_DIR)", 665 | "$(inherited)", 666 | ); 667 | INFOPLIST_FILE = Tests/Info.plist; 668 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 669 | MACOSX_DEPLOYMENT_TARGET = 10.10; 670 | MTL_ENABLE_DEBUG_INFO = NO; 671 | PRODUCT_NAME = "$(TARGET_NAME)"; 672 | SDKROOT = macosx; 673 | }; 674 | name = Release; 675 | }; 676 | /* End XCBuildConfiguration section */ 677 | 678 | /* Begin XCConfigurationList section */ 679 | 2E4FEFD519575BE100351305 /* Build configuration list for PBXProject "SwiftyJSON" */ = { 680 | isa = XCConfigurationList; 681 | buildConfigurations = ( 682 | 2E4FEFEF19575BE100351305 /* Debug */, 683 | 2E4FEFF019575BE100351305 /* Release */, 684 | ); 685 | defaultConfigurationIsVisible = 0; 686 | defaultConfigurationName = Release; 687 | }; 688 | 2E4FEFF119575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON" */ = { 689 | isa = XCConfigurationList; 690 | buildConfigurations = ( 691 | 2E4FEFF219575BE100351305 /* Debug */, 692 | 2E4FEFF319575BE100351305 /* Release */, 693 | ); 694 | defaultConfigurationIsVisible = 0; 695 | defaultConfigurationName = Release; 696 | }; 697 | 2E4FEFF419575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSONTests" */ = { 698 | isa = XCConfigurationList; 699 | buildConfigurations = ( 700 | 2E4FEFF519575BE100351305 /* Debug */, 701 | 2E4FEFF619575BE100351305 /* Release */, 702 | ); 703 | defaultConfigurationIsVisible = 0; 704 | defaultConfigurationName = Release; 705 | }; 706 | 4EC1C1DC1A0C1A2D0026ED0B /* Build configuration list for PBXNativeTarget "SwiftyJSONOSX" */ = { 707 | isa = XCConfigurationList; 708 | buildConfigurations = ( 709 | 4EC1C1DD1A0C1A2D0026ED0B /* Debug */, 710 | 4EC1C1DE1A0C1A2D0026ED0B /* Release */, 711 | ); 712 | defaultConfigurationIsVisible = 0; 713 | defaultConfigurationName = Release; 714 | }; 715 | 4EC1C1DF1A0C1A2D0026ED0B /* Build configuration list for PBXNativeTarget "SwiftyJSONOSXTests" */ = { 716 | isa = XCConfigurationList; 717 | buildConfigurations = ( 718 | 4EC1C1E01A0C1A2D0026ED0B /* Debug */, 719 | 4EC1C1E11A0C1A2D0026ED0B /* Release */, 720 | ); 721 | defaultConfigurationIsVisible = 0; 722 | defaultConfigurationName = Release; 723 | }; 724 | /* End XCConfigurationList section */ 725 | }; 726 | rootObject = 2E4FEFD219575BE100351305 /* Project object */; 727 | } 728 | -------------------------------------------------------------------------------- /SwiftyJSON.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SwiftyJSON.xcodeproj/project.xcworkspace/xcshareddata/SwiftyJSON.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 3A573BC4-D26F-4B75-AEB7-A02DA780E705 9 | IDESourceControlProjectName 10 | SwiftyJSON 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | C861FC00CEE0F6A6BE81FCFF6785FAA78C58EBB3 14 | https://github.com/lingoer/SwiftyJSON.git 15 | 16 | IDESourceControlProjectPath 17 | SwiftyJSON.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | C861FC00CEE0F6A6BE81FCFF6785FAA78C58EBB3 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/lingoer/SwiftyJSON.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | C861FC00CEE0F6A6BE81FCFF6785FAA78C58EBB3 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | C861FC00CEE0F6A6BE81FCFF6785FAA78C58EBB3 36 | IDESourceControlWCCName 37 | SwiftyJSON 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON.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 | -------------------------------------------------------------------------------- /SwiftyJSON.xcodeproj/xcuserdata/lebedzeu.xcuserdatad/xcschemes/SwiftyJSON-OSX.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 52 | 53 | 54 | 55 | 61 | 62 | 64 | 65 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /SwiftyJSON.xcodeproj/xcuserdata/lebedzeu.xcuserdatad/xcschemes/SwiftyJSON.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 52 | 53 | 54 | 55 | 61 | 62 | 64 | 65 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /SwiftyJSON.xcodeproj/xcuserdata/lebedzeu.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SwiftyJSON-OSX.xcscheme 8 | 9 | orderHint 10 | 1 11 | 12 | SwiftyJSON.xcscheme 13 | 14 | orderHint 15 | 0 16 | 17 | 18 | SuppressBuildableAutocreation 19 | 20 | 2E4FEFDA19575BE100351305 21 | 22 | primary 23 | 24 | 25 | 2E4FEFE519575BE100351305 26 | 27 | primary 28 | 29 | 30 | 2E4FF00119575CE600351305 31 | 32 | primary 33 | 34 | 35 | 2E4FF00B19575CE600351305 36 | 37 | primary 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /SwiftyJSON.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Tests/ArrayTests.swift: -------------------------------------------------------------------------------- 1 | // ArrayTests.swift 2 | // 3 | // Copyright (c) 2014 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 XCTest 24 | import SwiftyJSON 25 | 26 | class ArrayTests: XCTestCase { 27 | 28 | func testSingleDimensionalArraysGetter() { 29 | let array = ["1","2", "a", "B", "D"] 30 | let json = JSON(array) 31 | XCTAssertEqual((json.array![0] as JSON).string!, "1") 32 | XCTAssertEqual((json.array![1] as JSON).string!, "2") 33 | XCTAssertEqual((json.array![2] as JSON).string!, "a") 34 | XCTAssertEqual((json.array![3] as JSON).string!, "B") 35 | XCTAssertEqual((json.array![4] as JSON).string!, "D") 36 | } 37 | 38 | func testSingleDimensionalArraysSetter() { 39 | let array = ["1","2", "a", "B", "D"] 40 | var json = JSON(array) 41 | json.arrayObject = ["111", "222"] 42 | XCTAssertEqual((json.array![0] as JSON).string!, "111") 43 | XCTAssertEqual((json.array![1] as JSON).string!, "222") 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Tests/BaseTests.swift: -------------------------------------------------------------------------------- 1 | // BaseTests.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 XCTest 24 | import SwiftyJSON 25 | 26 | class BaseTests: XCTestCase { 27 | 28 | var testData: NSData! 29 | 30 | override func setUp() { 31 | 32 | super.setUp() 33 | 34 | if let file = NSBundle(forClass:BaseTests.self).pathForResource("Tests", ofType: "json") { 35 | self.testData = NSData(contentsOfFile: file) 36 | } else { 37 | XCTFail("Can't find the test JSON file") 38 | } 39 | } 40 | 41 | override func tearDown() { 42 | super.tearDown() 43 | } 44 | 45 | func testInit() { 46 | let json0 = JSON(data:self.testData) 47 | XCTAssertEqual(json0.array!.count, 3) 48 | XCTAssertEqual(JSON("123").description, "123") 49 | XCTAssertEqual(JSON(["1":"2"])["1"].string!, "2") 50 | var dictionary = NSMutableDictionary() 51 | dictionary.setObject(NSNumber(double: 1.0), forKey: "number" as NSString) 52 | dictionary.setObject(NSNull(), forKey: "null" as NSString) 53 | let json1 = JSON(dictionary) 54 | if let object: AnyObject = NSJSONSerialization.JSONObjectWithData(self.testData, options: nil, error: nil){ 55 | let json2 = JSON(object) 56 | XCTAssertEqual(json0, json2) 57 | } 58 | } 59 | 60 | func testCompare2() { 61 | let json = JSON("32.1234567890") 62 | } 63 | 64 | func testCompare() { 65 | XCTAssertNotEqual(JSON("32.1234567890"), JSON(32.1234567890)) 66 | XCTAssertNotEqual(JSON("9876543210987654321"),JSON(NSNumber(unsignedLongLong:9876543210987654321))) 67 | XCTAssertNotEqual(JSON("9876543210987654321.12345678901234567890"), JSON(9876543210987654321.12345678901234567890)) 68 | XCTAssertEqual(JSON("😊"), JSON("😊")) 69 | XCTAssertNotEqual(JSON("😱"), JSON("😁")) 70 | XCTAssertEqual(JSON([123,321,456]), JSON([123,321,456])) 71 | XCTAssertNotEqual(JSON([123,321,456]), JSON(123456789)) 72 | XCTAssertNotEqual(JSON([123,321,456]), JSON("string")) 73 | XCTAssertNotEqual(JSON(["1":123,"2":321,"3":456]), JSON("string")) 74 | XCTAssertEqual(JSON(["1":123,"2":321,"3":456]), JSON(["2":321,"1":123,"3":456])) 75 | XCTAssertEqual(JSON(NSNull()),JSON(NSNull())) 76 | XCTAssertNotEqual(JSON(NSNull()), JSON(123)) 77 | } 78 | 79 | func testJSONDoesProduceValidWithCorrectKeyPath() { 80 | let json = JSON(data:self.testData) 81 | 82 | let tweets = json 83 | let tweets_array = json.array 84 | let tweets_1 = json[1] 85 | let tweets_array_1 = tweets_1[1] 86 | let tweets_1_user_name = tweets_1["user"]["name"] 87 | let tweets_1_user_name_string = tweets_1["user"]["name"].string 88 | XCTAssertNotEqual(tweets.type, Type.Null) 89 | XCTAssert(tweets_array != nil) 90 | XCTAssertNotEqual(tweets_1.type, Type.Null) 91 | XCTAssertEqual(tweets_1_user_name, JSON("Raffi Krikorian")) 92 | XCTAssertEqual(tweets_1_user_name_string!, "Raffi Krikorian") 93 | 94 | let tweets_1_coordinates = tweets_1["coordinates"] 95 | let tweets_1_coordinates_coordinates = tweets_1_coordinates["coordinates"] 96 | let tweets_1_coordinates_coordinates_point_0_double = tweets_1_coordinates_coordinates[0].double 97 | let tweets_1_coordinates_coordinates_point_1_float = tweets_1_coordinates_coordinates[1].float 98 | let new_tweets_1_coordinates_coordinates = JSON([-122.25831,37.871609] as NSArray) 99 | XCTAssertEqual(tweets_1_coordinates_coordinates, new_tweets_1_coordinates_coordinates) 100 | XCTAssertEqual(tweets_1_coordinates_coordinates_point_0_double!, -122.25831) 101 | XCTAssertTrue(tweets_1_coordinates_coordinates_point_1_float! == 37.871609) 102 | let tweets_1_coordinates_coordinates_point_0_string = tweets_1_coordinates_coordinates[0].stringValue 103 | let tweets_1_coordinates_coordinates_point_1_string = tweets_1_coordinates_coordinates[1].stringValue 104 | XCTAssertEqual(tweets_1_coordinates_coordinates_point_0_string, "-122.25831") 105 | XCTAssertEqual(tweets_1_coordinates_coordinates_point_1_string, "37.871609") 106 | let tweets_1_coordinates_coordinates_point_0 = tweets_1_coordinates_coordinates[0] 107 | let tweets_1_coordinates_coordinates_point_1 = tweets_1_coordinates_coordinates[1] 108 | XCTAssertEqual(tweets_1_coordinates_coordinates_point_0, JSON(-122.25831)) 109 | XCTAssertEqual(tweets_1_coordinates_coordinates_point_1, JSON(37.871609)) 110 | 111 | let created_at = json[0]["created_at"].string 112 | let id_str = json[0]["id_str"].string 113 | let favorited = json[0]["favorited"].bool 114 | let id = json[0]["id"].int 115 | let in_reply_to_user_id_str = json[0]["in_reply_to_user_id_str"] 116 | XCTAssertEqual(created_at!, "Tue Aug 28 21:16:23 +0000 2012") 117 | XCTAssertEqual(id_str!,"240558470661799936") 118 | XCTAssertFalse(favorited!) 119 | XCTAssertEqual(id!,240558470661799936) 120 | XCTAssertEqual(in_reply_to_user_id_str.type, Type.Null) 121 | 122 | let user = json[0]["user"] 123 | let user_name = user["name"].string 124 | let user_profile_image_url = user["profile_image_url"].URL 125 | XCTAssert(user_name == "OAuth Dancer") 126 | XCTAssert(user_profile_image_url == NSURL(string: "http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg")) 127 | 128 | let user_dictionary = json[0]["user"].dictionary 129 | let user_dictionary_name = user_dictionary?["name"]?.string 130 | let user_dictionary_name_profile_image_url = user_dictionary?["profile_image_url"]?.URL 131 | XCTAssert(user_dictionary_name == "OAuth Dancer") 132 | XCTAssert(user_dictionary_name_profile_image_url == NSURL(string: "http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg")) 133 | } 134 | 135 | func testSequenceType() { 136 | let json = JSON(data:self.testData) 137 | XCTAssertEqual(json.count, 3) 138 | for (_, aJson) in json { 139 | XCTAssertEqual(aJson, json[0]) 140 | break 141 | } 142 | 143 | var index = 0 144 | let keys = (json[1].dictionaryObject! as NSDictionary).allKeys as [String] 145 | for (aKey, aJson) in json[1] { 146 | XCTAssertEqual(aKey, keys[index]) 147 | XCTAssertEqual(aJson, json[1][keys[index]]) 148 | break 149 | } 150 | } 151 | 152 | func testJSONNumberCompare() { 153 | XCTAssertEqual(JSON(12376352.123321), JSON(12376352.123321)) 154 | XCTAssertGreaterThan(JSON(20.211), JSON(20.112)) 155 | XCTAssertGreaterThanOrEqual(JSON(30.211), JSON(20.112)) 156 | XCTAssertGreaterThanOrEqual(JSON(65232), JSON(65232)) 157 | XCTAssertLessThan(JSON(-82320.211), JSON(20.112)) 158 | XCTAssertLessThanOrEqual(JSON(-320.211), JSON(123.1)) 159 | XCTAssertLessThanOrEqual(JSON(-8763), JSON(-8763)) 160 | 161 | XCTAssertEqual(JSON(12376352.123321), JSON(12376352.123321)) 162 | XCTAssertGreaterThan(JSON(20.211), JSON(20.112)) 163 | XCTAssertGreaterThanOrEqual(JSON(30.211), JSON(20.112)) 164 | XCTAssertGreaterThanOrEqual(JSON(65232), JSON(65232)) 165 | XCTAssertLessThan(JSON(-82320.211), JSON(20.112)) 166 | XCTAssertLessThanOrEqual(JSON(-320.211), JSON(123.1)) 167 | XCTAssertLessThanOrEqual(JSON(-8763), JSON(-8763)) 168 | } 169 | 170 | func testNumberConverToString(){ 171 | XCTAssertEqual(JSON(true).stringValue, "true") 172 | XCTAssertEqual(JSON(999.9823).stringValue, "999.9823") 173 | XCTAssertEqual(JSON(true).number!.stringValue, "1") 174 | XCTAssertEqual(JSON(false).number!.stringValue, "0") 175 | XCTAssertEqual(JSON("hello").numberValue.stringValue, "0") 176 | XCTAssertEqual(JSON(NSNull()).numberValue.stringValue, "0") 177 | XCTAssertEqual(JSON(["a","b","c","d"]).numberValue.stringValue, "0") 178 | XCTAssertEqual(JSON(["a":"b","c":"d"]).numberValue.stringValue, "0") 179 | } 180 | 181 | func testNumberPrint(){ 182 | 183 | XCTAssertEqual(JSON(false).description,"false") 184 | XCTAssertEqual(JSON(true).description,"true") 185 | 186 | XCTAssertEqual(JSON(1).description,"1") 187 | XCTAssertEqual(JSON(22).description,"22") 188 | #if (arch(x86_64) || arch(arm64)) 189 | XCTAssertEqual(JSON(9.22337203685478E18).description,"9.22337203685478e+18") 190 | #elseif (arch(i386) || arch(arm)) 191 | XCTAssertEqual(JSON(2147483647).description,"2147483647") 192 | #endif 193 | XCTAssertEqual(JSON(-1).description,"-1") 194 | XCTAssertEqual(JSON(-934834834).description,"-934834834") 195 | XCTAssertEqual(JSON(-2147483648).description,"-2147483648") 196 | 197 | XCTAssertEqual(JSON(1.5555).description,"1.5555") 198 | XCTAssertEqual(JSON(-9.123456789).description,"-9.123456789") 199 | XCTAssertEqual(JSON(-0.00000000000000001).description,"-1e-17") 200 | XCTAssertEqual(JSON(-999999999999999999999999.000000000000000000000001).description,"-1e+24") 201 | XCTAssertEqual(JSON(-9999999991999999999999999.88888883433343439438493483483943948341).stringValue,"-9.999999991999999e+24") 202 | 203 | XCTAssertEqual(JSON(Int(Int.max)).description,"\(Int.max)") 204 | XCTAssertEqual(JSON(NSNumber(long: Int.min)).description,"\(Int.min)") 205 | XCTAssertEqual(JSON(NSNumber(unsignedLong: ULONG_MAX)).description,"\(ULONG_MAX)") 206 | XCTAssertEqual(JSON(NSNumber(unsignedLongLong: UInt64.max)).description,"\(UInt64.max)") 207 | XCTAssertEqual(JSON(NSNumber(longLong: Int64.max)).description,"\(Int64.max)") 208 | XCTAssertEqual(JSON(NSNumber(unsignedLongLong: UInt64.max)).description,"\(UInt64.max)") 209 | 210 | XCTAssertEqual(JSON(Double.infinity).description,"inf") 211 | XCTAssertEqual(JSON(-Double.infinity).description,"-inf") 212 | XCTAssertEqual(JSON(Double.NaN).description,"nan") 213 | 214 | XCTAssertEqual(JSON(1.0/0.0).description,"inf") 215 | XCTAssertEqual(JSON(-1.0/0.0).description,"-inf") 216 | XCTAssertEqual(JSON(0.0/0.0).description,"nan") 217 | } 218 | 219 | func testNullJSON() { 220 | XCTAssertEqual(JSON(NSNull()).debugDescription,"null") 221 | 222 | let json:JSON = nil 223 | XCTAssertEqual(json.debugDescription,"null") 224 | XCTAssertNil(json.error) 225 | let json1:JSON = JSON(NSNull()) 226 | if json1 != nil { 227 | XCTFail("json1 should be nil") 228 | } 229 | } 230 | 231 | func testErrorHandle() { 232 | let json = JSON(data:self.testData) 233 | if let wrongType = json["wrong-type"].string { 234 | XCTFail("Should not run into here") 235 | } else { 236 | XCTAssertEqual(json["wrong-type"].error!.code, SwiftyJSON.ErrorWrongType) 237 | } 238 | 239 | if let notExist = json[0]["not-exist"].string { 240 | XCTFail("Should not run into here") 241 | } else { 242 | XCTAssertEqual(json[0]["not-exist"].error!.code, SwiftyJSON.ErrorNotExist) 243 | } 244 | 245 | let wrongJSON = JSON(NSObject()) 246 | if let error = wrongJSON.error { 247 | XCTAssertEqual(error.code, SwiftyJSON.ErrorUnsupportedType) 248 | } 249 | } 250 | 251 | func testReturnObject() { 252 | let json = JSON(data:self.testData) 253 | XCTAssertNotNil(json.object) 254 | } 255 | 256 | func testNumberCompare(){ 257 | XCTAssertEqual(NSNumber(double: 888332), NSNumber(int:888332)) 258 | XCTAssertNotEqual(NSNumber(double: 888332.1), NSNumber(int:888332)) 259 | XCTAssertLessThan(NSNumber(int: 888332), NSNumber(double:888332.1)) 260 | XCTAssertGreaterThan(NSNumber(double: 888332.1), NSNumber(int:888332)) 261 | XCTAssertNotEqual(NSNumber(double: 1), NSNumber(bool:true)) 262 | XCTAssertNotEqual(NSNumber(int: 0), NSNumber(bool:false)) 263 | XCTAssertEqual(NSNumber(bool: false), NSNumber(bool:false)) 264 | XCTAssertEqual(NSNumber(bool: true), NSNumber(bool:true)) 265 | } 266 | 267 | 268 | } -------------------------------------------------------------------------------- /Tests/ComparableTests.swift: -------------------------------------------------------------------------------- 1 | // ComparableTests.swift 2 | // 3 | // Copyright (c) 2014 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 XCTest 24 | import SwiftyJSON 25 | 26 | class ComparableTests: XCTestCase { 27 | 28 | func testNumberEqual() { 29 | var jsonL1:JSON = 1234567890.876623 30 | var jsonR1:JSON = JSON(1234567890.876623) 31 | XCTAssertEqual(jsonL1, jsonR1) 32 | XCTAssertTrue(jsonL1 == 1234567890.876623) 33 | 34 | var jsonL2:JSON = 987654321 35 | var jsonR2:JSON = JSON(987654321) 36 | XCTAssertEqual(jsonL2, jsonR2) 37 | XCTAssertTrue(jsonR2 == 987654321) 38 | 39 | 40 | var jsonL3:JSON = JSON(NSNumber(double:87654321.12345678)) 41 | var jsonR3:JSON = JSON(NSNumber(double:87654321.12345678)) 42 | XCTAssertEqual(jsonL3, jsonR3) 43 | XCTAssertTrue(jsonR3 == 87654321.12345678) 44 | } 45 | 46 | func testNumberNotEqual() { 47 | var jsonL1:JSON = 1234567890.876623 48 | var jsonR1:JSON = JSON(123.123) 49 | XCTAssertNotEqual(jsonL1, jsonR1) 50 | XCTAssertFalse(jsonL1 == 34343) 51 | 52 | var jsonL2:JSON = 8773 53 | var jsonR2:JSON = JSON(123.23) 54 | XCTAssertNotEqual(jsonL2, jsonR2) 55 | XCTAssertFalse(jsonR1 == 454352) 56 | 57 | var jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) 58 | var jsonR3:JSON = JSON(NSNumber(double:87654321.45678)) 59 | XCTAssertNotEqual(jsonL3, jsonR3) 60 | XCTAssertFalse(jsonL3 == 4545.232) 61 | } 62 | 63 | func testNumberGreaterThanOrEqual() { 64 | var jsonL1:JSON = 1234567890.876623 65 | var jsonR1:JSON = JSON(123.123) 66 | XCTAssertGreaterThanOrEqual(jsonL1, jsonR1) 67 | XCTAssertTrue(jsonL1 >= -37434) 68 | 69 | var jsonL2:JSON = 8773 70 | var jsonR2:JSON = JSON(-87343) 71 | XCTAssertGreaterThanOrEqual(jsonL2, jsonR2) 72 | XCTAssertTrue(jsonR2 >= -988343) 73 | 74 | var jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) 75 | var jsonR3:JSON = JSON(NSNumber(double:87621.12345678)) 76 | XCTAssertGreaterThanOrEqual(jsonL3, jsonR3) 77 | XCTAssertTrue(jsonR3 >= 0.3232) 78 | } 79 | 80 | func testNumberLessThanOrEqual() { 81 | var jsonL1:JSON = 1234567890.876623 82 | var jsonR1:JSON = JSON(123.123) 83 | XCTAssertLessThanOrEqual(jsonR1, jsonL1) 84 | XCTAssertFalse(83487343.3493 <= jsonR1) 85 | 86 | var jsonL2:JSON = 8773 87 | var jsonR2:JSON = JSON(-123.23) 88 | XCTAssertLessThanOrEqual(jsonR2, jsonL2) 89 | XCTAssertFalse(9348343 <= jsonR2) 90 | 91 | var jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) 92 | var jsonR3:JSON = JSON(NSNumber(double:87621.12345678)) 93 | XCTAssertLessThanOrEqual(jsonR3, jsonL3) 94 | XCTAssertTrue(87621.12345678 <= jsonR3) 95 | } 96 | 97 | func testNumberGreaterThan() { 98 | var jsonL1:JSON = 1234567890.876623 99 | var jsonR1:JSON = JSON(123.123) 100 | XCTAssertGreaterThan(jsonL1, jsonR1) 101 | XCTAssertFalse(jsonR1 > 192388843.0988) 102 | 103 | var jsonL2:JSON = 8773 104 | var jsonR2:JSON = JSON(123.23) 105 | XCTAssertGreaterThan(jsonL2, jsonR2) 106 | XCTAssertFalse(jsonR2 > 877434) 107 | 108 | var jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) 109 | var jsonR3:JSON = JSON(NSNumber(double:87621.1234567)) 110 | XCTAssertGreaterThan(jsonL3, jsonR3) 111 | XCTAssertFalse(-7799 > jsonR3) 112 | } 113 | 114 | func testNumberLessThan() { 115 | var jsonL1:JSON = 1234567890.876623 116 | var jsonR1:JSON = JSON(123.123) 117 | XCTAssertLessThan(jsonR1, jsonL1) 118 | XCTAssertTrue(jsonR1 < 192388843.0988) 119 | 120 | var jsonL2:JSON = 8773 121 | var jsonR2:JSON = JSON(123.23) 122 | XCTAssertLessThan(jsonR2, jsonL2) 123 | XCTAssertTrue(jsonR2 < 877434) 124 | 125 | var jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) 126 | var jsonR3:JSON = JSON(NSNumber(double:87621.1234567)) 127 | XCTAssertLessThan(jsonR3, jsonL3) 128 | XCTAssertTrue(-7799 < jsonR3) 129 | } 130 | 131 | func testBoolEqual() { 132 | var jsonL1:JSON = true 133 | var jsonR1:JSON = JSON(true) 134 | XCTAssertEqual(jsonL1, jsonR1) 135 | XCTAssertTrue(jsonL1 == true) 136 | 137 | var jsonL2:JSON = false 138 | var jsonR2:JSON = JSON(false) 139 | XCTAssertEqual(jsonL2, jsonR2) 140 | XCTAssertTrue(jsonL2 == false) 141 | } 142 | 143 | func testBoolNotEqual() { 144 | var jsonL1:JSON = true 145 | var jsonR1:JSON = JSON(false) 146 | XCTAssertNotEqual(jsonL1, jsonR1) 147 | XCTAssertTrue(jsonL1 != false) 148 | 149 | var jsonL2:JSON = false 150 | var jsonR2:JSON = JSON(true) 151 | XCTAssertNotEqual(jsonL2, jsonR2) 152 | XCTAssertTrue(jsonL2 != true) 153 | } 154 | 155 | func testBoolGreaterThanOrEqual() { 156 | var jsonL1:JSON = true 157 | var jsonR1:JSON = JSON(true) 158 | XCTAssertGreaterThanOrEqual(jsonL1, jsonR1) 159 | XCTAssertTrue(jsonL1 >= true) 160 | 161 | var jsonL2:JSON = false 162 | var jsonR2:JSON = JSON(false) 163 | XCTAssertGreaterThanOrEqual(jsonL2, jsonR2) 164 | XCTAssertFalse(jsonL2 >= true) 165 | } 166 | 167 | func testBoolLessThanOrEqual() { 168 | var jsonL1:JSON = true 169 | var jsonR1:JSON = JSON(true) 170 | XCTAssertLessThanOrEqual(jsonL1, jsonR1) 171 | XCTAssertTrue(true <= jsonR1) 172 | 173 | var jsonL2:JSON = false 174 | var jsonR2:JSON = JSON(false) 175 | XCTAssertLessThanOrEqual(jsonL2, jsonR2) 176 | XCTAssertFalse(jsonL2 <= true) 177 | } 178 | 179 | func testBoolGreaterThan() { 180 | var jsonL1:JSON = true 181 | var jsonR1:JSON = JSON(true) 182 | XCTAssertFalse(jsonL1 > jsonR1) 183 | XCTAssertFalse(jsonL1 > true) 184 | XCTAssertFalse(jsonR1 > false) 185 | 186 | var jsonL2:JSON = false 187 | var jsonR2:JSON = JSON(false) 188 | XCTAssertFalse(jsonL2 > jsonR2) 189 | XCTAssertFalse(jsonL2 > false) 190 | XCTAssertFalse(jsonR2 > true) 191 | 192 | var jsonL3:JSON = true 193 | var jsonR3:JSON = JSON(false) 194 | XCTAssertFalse(jsonL3 > jsonR3) 195 | XCTAssertFalse(jsonL3 > false) 196 | XCTAssertFalse(jsonR3 > true) 197 | 198 | var jsonL4:JSON = false 199 | var jsonR4:JSON = JSON(true) 200 | XCTAssertFalse(jsonL4 > jsonR4) 201 | XCTAssertFalse(jsonL4 > false) 202 | XCTAssertFalse(jsonR4 > true) 203 | } 204 | 205 | func testBoolLessThan() { 206 | var jsonL1:JSON = true 207 | var jsonR1:JSON = JSON(true) 208 | XCTAssertFalse(jsonL1 < jsonR1) 209 | XCTAssertFalse(jsonL1 < true) 210 | XCTAssertFalse(jsonR1 < false) 211 | 212 | var jsonL2:JSON = false 213 | var jsonR2:JSON = JSON(false) 214 | XCTAssertFalse(jsonL2 < jsonR2) 215 | XCTAssertFalse(jsonL2 < false) 216 | XCTAssertFalse(jsonR2 < true) 217 | 218 | var jsonL3:JSON = true 219 | var jsonR3:JSON = JSON(false) 220 | XCTAssertFalse(jsonL3 < jsonR3) 221 | XCTAssertFalse(jsonL3 < false) 222 | XCTAssertFalse(jsonR3 < true) 223 | 224 | var jsonL4:JSON = false 225 | var jsonR4:JSON = JSON(true) 226 | XCTAssertFalse(jsonL4 < jsonR4) 227 | XCTAssertFalse(jsonL4 < false) 228 | XCTAssertFalse(true < jsonR4) 229 | } 230 | 231 | func testStringEqual() { 232 | var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" 233 | var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") 234 | 235 | XCTAssertEqual(jsonL1, jsonR1) 236 | XCTAssertTrue(jsonL1 == "abcdefg 123456789 !@#$%^&*()") 237 | } 238 | 239 | func testStringNotEqual() { 240 | var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" 241 | var jsonR1:JSON = JSON("-=[]\\\"987654321") 242 | 243 | XCTAssertNotEqual(jsonL1, jsonR1) 244 | XCTAssertTrue(jsonL1 != "not equal") 245 | } 246 | 247 | func testStringGreaterThanOrEqual() { 248 | var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" 249 | var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") 250 | 251 | XCTAssertGreaterThanOrEqual(jsonL1, jsonR1) 252 | XCTAssertTrue(jsonL1 >= "abcdefg 123456789 !@#$%^&*()") 253 | 254 | var jsonL2:JSON = "z-+{}:" 255 | var jsonR2:JSON = JSON("a<>?:") 256 | XCTAssertGreaterThanOrEqual(jsonL2, jsonR2) 257 | XCTAssertTrue(jsonL2 >= "mnbvcxz") 258 | } 259 | 260 | func testStringLessThanOrEqual() { 261 | var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" 262 | var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") 263 | 264 | XCTAssertLessThanOrEqual(jsonL1, jsonR1) 265 | XCTAssertTrue(jsonL1 <= "abcdefg 123456789 !@#$%^&*()") 266 | 267 | var jsonL2:JSON = "z-+{}:" 268 | var jsonR2:JSON = JSON("a<>?:") 269 | XCTAssertLessThanOrEqual(jsonR2, jsonL2) 270 | XCTAssertTrue("mnbvcxz" <= jsonL2) 271 | } 272 | 273 | func testStringGreaterThan() { 274 | var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" 275 | var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") 276 | 277 | XCTAssertFalse(jsonL1 > jsonR1) 278 | XCTAssertFalse(jsonL1 > "abcdefg 123456789 !@#$%^&*()") 279 | 280 | var jsonL2:JSON = "z-+{}:" 281 | var jsonR2:JSON = JSON("a<>?:") 282 | XCTAssertGreaterThan(jsonL2, jsonR2) 283 | XCTAssertFalse("87663434" > jsonL2) 284 | } 285 | 286 | func testStringLessThan() { 287 | var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" 288 | var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") 289 | 290 | XCTAssertFalse(jsonL1 < jsonR1) 291 | XCTAssertFalse(jsonL1 < "abcdefg 123456789 !@#$%^&*()") 292 | 293 | var jsonL2:JSON = "98774" 294 | var jsonR2:JSON = JSON("123456") 295 | XCTAssertLessThan(jsonR2, jsonL2) 296 | XCTAssertFalse(jsonL2 < "09") 297 | } 298 | 299 | func testNil() { 300 | var jsonL1:JSON = nil 301 | var jsonR1:JSON = JSON(NSNull()) 302 | XCTAssertEqual(jsonL1, jsonR1) 303 | XCTAssertTrue(jsonL1 != "123") 304 | XCTAssertFalse(jsonL1 > "abcd") 305 | XCTAssertFalse(jsonR1 < "*&^") 306 | XCTAssertFalse(jsonL1 >= "jhfid") 307 | XCTAssertFalse(jsonR1 <= "你好") 308 | XCTAssertTrue(jsonL1 >= jsonR1) 309 | XCTAssertTrue(jsonL1 <= jsonR1) 310 | } 311 | 312 | func testArray() { 313 | var jsonL1:JSON = [1,2,"4",5,"6"] 314 | var jsonR1:JSON = JSON([1,2,"4",5,"6"]) 315 | XCTAssertEqual(jsonL1, jsonR1) 316 | XCTAssertTrue(jsonL1 == [1,2,"4",5,"6"]) 317 | XCTAssertTrue(jsonL1 != ["abcd","efg"]) 318 | XCTAssertTrue(jsonL1 >= jsonR1) 319 | XCTAssertTrue(jsonL1 <= jsonR1) 320 | XCTAssertFalse(jsonL1 > ["abcd",""]) 321 | XCTAssertFalse(jsonR1 < []) 322 | XCTAssertFalse(jsonL1 >= [:]) 323 | } 324 | 325 | func testDictionary() { 326 | var jsonL1:JSON = ["2": 2, "name": "Jack", "List": ["a", 1.09, NSNull()]] 327 | var jsonR1:JSON = JSON(["2": 2, "name": "Jack", "List": ["a", 1.09, NSNull()]]) 328 | 329 | XCTAssertEqual(jsonL1, jsonR1) 330 | XCTAssertTrue(jsonL1 != ["1":2,"Hello":"World","Koo":"Foo"]) 331 | XCTAssertTrue(jsonL1 >= jsonR1) 332 | XCTAssertTrue(jsonL1 <= jsonR1) 333 | XCTAssertFalse(jsonL1 >= [:]) 334 | XCTAssertFalse(jsonR1 <= ["999":"aaaa"]) 335 | XCTAssertFalse(jsonL1 > [")(*&^":1234567]) 336 | XCTAssertFalse(jsonR1 < ["MNHH":"JUYTR"]) 337 | } 338 | } 339 | -------------------------------------------------------------------------------- /Tests/DictionaryTests.swift: -------------------------------------------------------------------------------- 1 | // DictionaryTests.swift 2 | // 3 | // Copyright (c) 2014 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 XCTest 24 | import SwiftyJSON 25 | 26 | class DictionaryTests: XCTestCase { 27 | 28 | func testGetter() { 29 | let dictionary = ["number":9823.212, "name":"NAME", "list":[1234, 4.212], "object":["sub_number":877.2323, "sub_name":"sub_name"], "bool":true] 30 | let json = JSON(dictionary) 31 | //dictionary 32 | XCTAssertEqual((json.dictionary!["number"]! as JSON).double!, 9823.212) 33 | XCTAssertEqual((json.dictionary!["name"]! as JSON).string!, "NAME") 34 | XCTAssertEqual(((json.dictionary!["list"]! as JSON).array![0] as JSON).int!, 1234) 35 | XCTAssertEqual(((json.dictionary!["list"]! as JSON).array![1] as JSON).double!, 4.212) 36 | XCTAssertEqual((((json.dictionary!["object"]! as JSON).dictionaryValue)["sub_number"]! as JSON).double!, 877.2323) 37 | XCTAssertTrue(json.dictionary!["null"] == nil) 38 | //dictionaryValue 39 | XCTAssertEqual(((((json.dictionaryValue)["object"]! as JSON).dictionaryValue)["sub_name"]! as JSON).string!, "sub_name") 40 | XCTAssertEqual((json.dictionaryValue["bool"]! as JSON).bool!, true) 41 | XCTAssertTrue(json.dictionaryValue["null"] == nil) 42 | XCTAssertTrue(JSON.nullJSON.dictionaryValue == [:]) 43 | //dictionaryObject 44 | XCTAssertEqual(json.dictionaryObject!["number"]! as Double, 9823.212) 45 | XCTAssertTrue(json.dictionaryObject!["null"] == nil) 46 | XCTAssertTrue(JSON.nullJSON.dictionaryObject == nil) 47 | } 48 | 49 | func testSetter() { 50 | var json:JSON = ["test":"case"] 51 | XCTAssertEqual(json.dictionaryObject! as [String : String], ["test":"case"]) 52 | json.dictionaryObject = ["name":"NAME"] 53 | XCTAssertEqual(json.dictionaryObject! as [String : String], ["name":"NAME"]) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.swiftyjson.${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 | -------------------------------------------------------------------------------- /Tests/LiteralConvertibleTests.swift: -------------------------------------------------------------------------------- 1 | // LiteralConvertibleTests.swift 2 | // 3 | // Copyright (c) 2014 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 XCTest 24 | import SwiftyJSON 25 | 26 | class LiteralConvertibleTests: XCTestCase { 27 | 28 | func testNumber() { 29 | var json:JSON = 1234567890.876623 30 | XCTAssertEqual(json.int!, 1234567890) 31 | XCTAssertEqual(json.intValue, 1234567890) 32 | XCTAssertEqual(json.double!, 1234567890.876623) 33 | XCTAssertEqual(json.doubleValue, 1234567890.876623) 34 | XCTAssertTrue(json.float! == 1234567890.876623) 35 | XCTAssertTrue(json.floatValue == 1234567890.876623) 36 | } 37 | 38 | func testBool() { 39 | var jsonTrue:JSON = true 40 | XCTAssertEqual(jsonTrue.bool!, true) 41 | XCTAssertEqual(jsonTrue.boolValue, true) 42 | var jsonFalse:JSON = false 43 | XCTAssertEqual(jsonFalse.bool!, false) 44 | XCTAssertEqual(jsonFalse.boolValue, false) 45 | } 46 | 47 | func testString() { 48 | var json:JSON = "abcd efg, HIJK;LMn" 49 | XCTAssertEqual(json.string!, "abcd efg, HIJK;LMn") 50 | XCTAssertEqual(json.stringValue, "abcd efg, HIJK;LMn") 51 | } 52 | 53 | func testNil() { 54 | var jsonNil_1:JSON = nil 55 | XCTAssert(jsonNil_1 == nil) 56 | var jsonNil_2:JSON = JSON(NSNull) 57 | XCTAssert(jsonNil_2 != nil) 58 | var jsonNil_3:JSON = JSON([1:2]) 59 | XCTAssert(jsonNil_3 != nil) 60 | } 61 | 62 | func testArray() { 63 | var json:JSON = [1,2,"4",5,"6"] 64 | XCTAssertEqual(json.array!, [1,2,"4",5,"6"]) 65 | XCTAssertEqual(json.arrayValue, [1,2,"4",5,"6"]) 66 | } 67 | 68 | func testDictionary() { 69 | var json:JSON = ["1":2,"2":2,"three":3,"list":["aa","bb","dd"]] 70 | XCTAssertEqual(json.dictionary!, ["1":2,"2":2,"three":3,"list":["aa","bb","dd"]]) 71 | XCTAssertEqual(json.dictionaryValue, ["1":2,"2":2,"three":3,"list":["aa","bb","dd"]]) 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Tests/NumberTests.swift: -------------------------------------------------------------------------------- 1 | // NumberTests.swift 2 | // 3 | // Copyright (c) 2014 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 XCTest 24 | import SwiftyJSON 25 | class NumberTests: XCTestCase { 26 | 27 | func testNumber() { 28 | //getter 29 | var json = JSON(NSNumber(double: 9876543210.123456789)) 30 | XCTAssertEqual(json.number!, 9876543210.123456789) 31 | XCTAssertEqual(json.numberValue, 9876543210.123456789) 32 | XCTAssertEqual(json.stringValue, "9876543210.123457") 33 | 34 | //setter 35 | json.number = NSNumber(double: 123456789.0987654321) 36 | XCTAssertEqual(json.number!, 123456789.0987654321) 37 | XCTAssertEqual(json.numberValue, 123456789.0987654321) 38 | json.number = nil 39 | XCTAssertEqual(json.numberValue, 0) 40 | XCTAssertEqual(json.object as NSNull, NSNull()) 41 | XCTAssertTrue(json.number == nil) 42 | json.numberValue = 2.9876 43 | XCTAssertEqual(json.number!, 2.9876) 44 | } 45 | 46 | func testBool() { 47 | var json = JSON(true) 48 | XCTAssertEqual(json.bool!, true) 49 | XCTAssertEqual(json.boolValue, true) 50 | XCTAssertEqual(json.numberValue, true as NSNumber) 51 | XCTAssertEqual(json.stringValue, "true") 52 | 53 | json.bool = false 54 | XCTAssertEqual(json.bool!, false) 55 | XCTAssertEqual(json.boolValue, false) 56 | XCTAssertEqual(json.numberValue, false as NSNumber) 57 | 58 | json.bool = nil 59 | XCTAssertTrue(json.bool == nil) 60 | XCTAssertEqual(json.boolValue, false) 61 | XCTAssertEqual(json.numberValue, 0) 62 | 63 | json.boolValue = true 64 | XCTAssertEqual(json.bool!, true) 65 | XCTAssertEqual(json.boolValue, true) 66 | XCTAssertEqual(json.numberValue, true as NSNumber) 67 | } 68 | 69 | func testDouble() { 70 | var json = JSON(9876543210.123456789) 71 | XCTAssertEqual(json.double!, 9876543210.123456789) 72 | XCTAssertEqual(json.doubleValue, 9876543210.123456789) 73 | XCTAssertEqual(json.numberValue, 9876543210.123456789) 74 | XCTAssertEqual(json.stringValue, "9876543210.123457") 75 | 76 | json.double = 2.8765432 77 | XCTAssertEqual(json.double!, 2.8765432) 78 | XCTAssertEqual(json.doubleValue, 2.8765432) 79 | XCTAssertEqual(json.numberValue, 2.8765432) 80 | 81 | json.doubleValue = 89.0987654 82 | XCTAssertEqual(json.double!, 89.0987654) 83 | XCTAssertEqual(json.doubleValue, 89.0987654) 84 | XCTAssertEqual(json.numberValue, 89.0987654) 85 | 86 | json.double = nil 87 | XCTAssertEqual(json.boolValue, false) 88 | XCTAssertEqual(json.doubleValue, 0.0) 89 | XCTAssertEqual(json.numberValue, 0) 90 | } 91 | 92 | func testFloat() { 93 | var json = JSON(54321.12345) 94 | XCTAssertTrue(json.float! == 54321.12345) 95 | XCTAssertTrue(json.floatValue == 54321.12345) 96 | println(json.numberValue.doubleValue) 97 | XCTAssertEqual(json.numberValue, 54321.12345) 98 | XCTAssertEqual(json.stringValue, "54321.12345") 99 | 100 | json.float = 23231.65 101 | XCTAssertTrue(json.float! == 23231.65) 102 | XCTAssertTrue(json.floatValue == 23231.65) 103 | XCTAssertEqual(json.numberValue, NSNumber(float:23231.65)) 104 | 105 | json.floatValue = -98766.23 106 | XCTAssertEqual(json.float!, -98766.23) 107 | XCTAssertEqual(json.floatValue, -98766.23) 108 | XCTAssertEqual(json.numberValue, NSNumber(float:-98766.23)) 109 | } 110 | 111 | func testInt() { 112 | var json = JSON(123456789) 113 | XCTAssertEqual(json.int!, 123456789) 114 | XCTAssertEqual(json.intValue, 123456789) 115 | XCTAssertEqual(json.numberValue, NSNumber(integer: 123456789)) 116 | XCTAssertEqual(json.stringValue, "123456789") 117 | 118 | json.int = nil 119 | XCTAssertTrue(json.boolValue == false) 120 | XCTAssertTrue(json.intValue == 0) 121 | XCTAssertEqual(json.numberValue, 0) 122 | XCTAssertEqual(json.object as NSNull, NSNull()) 123 | XCTAssertTrue(json.int == nil) 124 | 125 | json.intValue = 76543 126 | XCTAssertEqual(json.int!, 76543) 127 | XCTAssertEqual(json.intValue, 76543) 128 | XCTAssertEqual(json.numberValue, NSNumber(integer: 76543)) 129 | 130 | json.intValue = 98765421 131 | XCTAssertEqual(json.int!, 98765421) 132 | XCTAssertEqual(json.intValue, 98765421) 133 | XCTAssertEqual(json.numberValue, NSNumber(integer: 98765421)) 134 | } 135 | 136 | func testUInt() { 137 | var json = JSON(123456789) 138 | XCTAssertTrue(json.uInt! == 123456789) 139 | XCTAssertTrue(json.uIntValue == 123456789) 140 | XCTAssertEqual(json.numberValue, NSNumber(unsignedInteger: 123456789)) 141 | XCTAssertEqual(json.stringValue, "123456789") 142 | 143 | json.uInt = nil 144 | XCTAssertTrue(json.boolValue == false) 145 | XCTAssertTrue(json.uIntValue == 0) 146 | XCTAssertEqual(json.numberValue, 0) 147 | XCTAssertEqual(json.object as NSNull, NSNull()) 148 | XCTAssertTrue(json.uInt == nil) 149 | 150 | json.uIntValue = 76543 151 | XCTAssertTrue(json.uInt! == 76543) 152 | XCTAssertTrue(json.uIntValue == 76543) 153 | XCTAssertEqual(json.numberValue, NSNumber(unsignedInteger: 76543)) 154 | 155 | json.uIntValue = 98765421 156 | XCTAssertTrue(json.uInt! == 98765421) 157 | XCTAssertTrue(json.uIntValue == 98765421) 158 | XCTAssertEqual(json.numberValue, NSNumber(unsignedInteger: 98765421)) 159 | } 160 | 161 | func testInt8() { 162 | let n127 = NSNumber(char: 127) 163 | var json = JSON(n127) 164 | XCTAssertTrue(json.int8! == n127.charValue) 165 | XCTAssertTrue(json.int8Value == n127.charValue) 166 | XCTAssertTrue(json.number! == n127) 167 | XCTAssertEqual(json.numberValue, n127) 168 | XCTAssertEqual(json.stringValue, "127") 169 | 170 | let nm128 = NSNumber(char: -128) 171 | json.int8Value = nm128.charValue 172 | XCTAssertTrue(json.int8! == nm128.charValue) 173 | XCTAssertTrue(json.int8Value == nm128.charValue) 174 | XCTAssertTrue(json.number! == nm128) 175 | XCTAssertEqual(json.numberValue, nm128) 176 | XCTAssertEqual(json.stringValue, "-128") 177 | 178 | let n0 = NSNumber(char: 0 as Int8) 179 | json.int8Value = n0.charValue 180 | XCTAssertTrue(json.int8! == n0.charValue) 181 | XCTAssertTrue(json.int8Value == n0.charValue) 182 | println(json.number) 183 | XCTAssertTrue(json.number! == n0) 184 | XCTAssertEqual(json.numberValue, n0) 185 | #if (arch(x86_64) || arch(arm64)) 186 | XCTAssertEqual(json.stringValue, "false") 187 | #elseif (arch(i386) || arch(arm)) 188 | XCTAssertEqual(json.stringValue, "0") 189 | #endif 190 | 191 | 192 | let n1 = NSNumber(char: 1 as Int8) 193 | json.int8Value = n1.charValue 194 | XCTAssertTrue(json.int8! == n1.charValue) 195 | XCTAssertTrue(json.int8Value == n1.charValue) 196 | XCTAssertTrue(json.number! == n1) 197 | XCTAssertEqual(json.numberValue, n1) 198 | #if (arch(x86_64) || arch(arm64)) 199 | XCTAssertEqual(json.stringValue, "true") 200 | #elseif (arch(i386) || arch(arm)) 201 | XCTAssertEqual(json.stringValue, "1") 202 | #endif 203 | } 204 | 205 | func testUInt8() { 206 | let n255 = NSNumber(unsignedChar: 255) 207 | var json = JSON(n255) 208 | XCTAssertTrue(json.uInt8! == n255.unsignedCharValue) 209 | XCTAssertTrue(json.uInt8Value == n255.unsignedCharValue) 210 | XCTAssertTrue(json.number! == n255) 211 | XCTAssertEqual(json.numberValue, n255) 212 | XCTAssertEqual(json.stringValue, "255") 213 | 214 | let nm2 = NSNumber(unsignedChar: 2) 215 | json.uInt8Value = nm2.unsignedCharValue 216 | XCTAssertTrue(json.uInt8! == nm2.unsignedCharValue) 217 | XCTAssertTrue(json.uInt8Value == nm2.unsignedCharValue) 218 | XCTAssertTrue(json.number! == nm2) 219 | XCTAssertEqual(json.numberValue, nm2) 220 | XCTAssertEqual(json.stringValue, "2") 221 | 222 | let nm0 = NSNumber(unsignedChar: 0) 223 | json.uInt8Value = nm0.unsignedCharValue 224 | XCTAssertTrue(json.uInt8! == nm0.unsignedCharValue) 225 | XCTAssertTrue(json.uInt8Value == nm0.unsignedCharValue) 226 | XCTAssertTrue(json.number! == nm0) 227 | XCTAssertEqual(json.numberValue, nm0) 228 | XCTAssertEqual(json.stringValue, "0") 229 | 230 | let nm1 = NSNumber(unsignedChar: 1) 231 | json.uInt8 = nm1.unsignedCharValue 232 | XCTAssertTrue(json.uInt8! == nm1.unsignedCharValue) 233 | XCTAssertTrue(json.uInt8Value == nm1.unsignedCharValue) 234 | XCTAssertTrue(json.number! == nm1) 235 | XCTAssertEqual(json.numberValue, nm1) 236 | XCTAssertEqual(json.stringValue, "1") 237 | } 238 | 239 | func testInt16() { 240 | 241 | let n32767 = NSNumber(short: 32767) 242 | var json = JSON(n32767) 243 | XCTAssertTrue(json.int16! == n32767.shortValue) 244 | XCTAssertTrue(json.int16Value == n32767.shortValue) 245 | XCTAssertTrue(json.number! == n32767) 246 | XCTAssertEqual(json.numberValue, n32767) 247 | XCTAssertEqual(json.stringValue, "32767") 248 | 249 | let nm32768 = NSNumber(short: -32768) 250 | json.int16Value = nm32768.shortValue 251 | XCTAssertTrue(json.int16! == nm32768.shortValue) 252 | XCTAssertTrue(json.int16Value == nm32768.shortValue) 253 | XCTAssertTrue(json.number! == nm32768) 254 | XCTAssertEqual(json.numberValue, nm32768) 255 | XCTAssertEqual(json.stringValue, "-32768") 256 | 257 | let n0 = NSNumber(short: 0) 258 | json.int16Value = n0.shortValue 259 | XCTAssertTrue(json.int16! == n0.shortValue) 260 | XCTAssertTrue(json.int16Value == n0.shortValue) 261 | println(json.number) 262 | XCTAssertTrue(json.number! == n0) 263 | XCTAssertEqual(json.numberValue, n0) 264 | XCTAssertEqual(json.stringValue, "0") 265 | 266 | let n1 = NSNumber(short: 1) 267 | json.int16 = n1.shortValue 268 | XCTAssertTrue(json.int16! == n1.shortValue) 269 | XCTAssertTrue(json.int16Value == n1.shortValue) 270 | XCTAssertTrue(json.number! == n1) 271 | XCTAssertEqual(json.numberValue, n1) 272 | XCTAssertEqual(json.stringValue, "1") 273 | } 274 | 275 | func testUInt16() { 276 | 277 | let n65535 = NSNumber(unsignedInteger: 65535) 278 | var json = JSON(n65535) 279 | XCTAssertTrue(json.uInt16! == n65535.unsignedShortValue) 280 | XCTAssertTrue(json.uInt16Value == n65535.unsignedShortValue) 281 | XCTAssertTrue(json.number! == n65535) 282 | XCTAssertEqual(json.numberValue, n65535) 283 | XCTAssertEqual(json.stringValue, "65535") 284 | 285 | let n32767 = NSNumber(unsignedInteger: 32767) 286 | json.uInt16 = n32767.unsignedShortValue 287 | XCTAssertTrue(json.uInt16! == n32767.unsignedShortValue) 288 | XCTAssertTrue(json.uInt16Value == n32767.unsignedShortValue) 289 | XCTAssertTrue(json.number! == n32767) 290 | XCTAssertEqual(json.numberValue, n32767) 291 | XCTAssertEqual(json.stringValue, "32767") 292 | } 293 | 294 | func testInt32() { 295 | let n2147483647 = NSNumber(int: 2147483647) 296 | var json = JSON(n2147483647) 297 | XCTAssertTrue(json.int32! == n2147483647.intValue) 298 | XCTAssertTrue(json.int32Value == n2147483647.intValue) 299 | XCTAssertTrue(json.number! == n2147483647) 300 | XCTAssertEqual(json.numberValue, n2147483647) 301 | XCTAssertEqual(json.stringValue, "2147483647") 302 | 303 | let n32767 = NSNumber(int: 32767) 304 | json.int32 = n32767.intValue 305 | XCTAssertTrue(json.int32! == n32767.intValue) 306 | XCTAssertTrue(json.int32Value == n32767.intValue) 307 | XCTAssertTrue(json.number! == n32767) 308 | XCTAssertEqual(json.numberValue, n32767) 309 | XCTAssertEqual(json.stringValue, "32767") 310 | 311 | let nm2147483648 = NSNumber(int: -2147483648) 312 | json.int32Value = nm2147483648.intValue 313 | XCTAssertTrue(json.int32! == nm2147483648.intValue) 314 | XCTAssertTrue(json.int32Value == nm2147483648.intValue) 315 | XCTAssertTrue(json.number! == nm2147483648) 316 | XCTAssertEqual(json.numberValue, nm2147483648) 317 | XCTAssertEqual(json.stringValue, "-2147483648") 318 | } 319 | 320 | func testUInt32() { 321 | let n2147483648 = NSNumber(unsignedInt: 2147483648) 322 | var json = JSON(n2147483648) 323 | XCTAssertTrue(json.uInt32! == n2147483648.unsignedIntValue) 324 | XCTAssertTrue(json.uInt32Value == n2147483648.unsignedIntValue) 325 | XCTAssertTrue(json.number! == n2147483648) 326 | XCTAssertEqual(json.numberValue, n2147483648) 327 | XCTAssertEqual(json.stringValue, "2147483648") 328 | 329 | let n32767 = NSNumber(unsignedInt: 32767) 330 | json.uInt32 = n32767.unsignedIntValue 331 | XCTAssertTrue(json.uInt32! == n32767.unsignedIntValue) 332 | XCTAssertTrue(json.uInt32Value == n32767.unsignedIntValue) 333 | XCTAssertTrue(json.number! == n32767) 334 | XCTAssertEqual(json.numberValue, n32767) 335 | XCTAssertEqual(json.stringValue, "32767") 336 | 337 | let n0 = NSNumber(unsignedInt: 0) 338 | json.uInt32Value = n0.unsignedIntValue 339 | XCTAssertTrue(json.uInt32! == n0.unsignedIntValue) 340 | XCTAssertTrue(json.uInt32Value == n0.unsignedIntValue) 341 | XCTAssertTrue(json.number! == n0) 342 | XCTAssertEqual(json.numberValue, n0) 343 | XCTAssertEqual(json.stringValue, "0") 344 | } 345 | 346 | func testInt64() { 347 | let int64Max = NSNumber(longLong: INT64_MAX) 348 | var json = JSON(int64Max) 349 | XCTAssertTrue(json.int64! == int64Max.longLongValue) 350 | XCTAssertTrue(json.int64Value == int64Max.longLongValue) 351 | XCTAssertTrue(json.number! == int64Max) 352 | XCTAssertEqual(json.numberValue, int64Max) 353 | XCTAssertEqual(json.stringValue, int64Max.stringValue) 354 | 355 | let n32767 = NSNumber(longLong: 32767) 356 | json.int64 = n32767.longLongValue 357 | XCTAssertTrue(json.int64! == n32767.longLongValue) 358 | XCTAssertTrue(json.int64Value == n32767.longLongValue) 359 | XCTAssertTrue(json.number! == n32767) 360 | XCTAssertEqual(json.numberValue, n32767) 361 | XCTAssertEqual(json.stringValue, "32767") 362 | 363 | let int64Min = NSNumber(longLong: (INT64_MAX-1) * -1) 364 | json.int64Value = int64Min.longLongValue 365 | XCTAssertTrue(json.int64! == int64Min.longLongValue) 366 | XCTAssertTrue(json.int64Value == int64Min.longLongValue) 367 | XCTAssertTrue(json.number! == int64Min) 368 | XCTAssertEqual(json.numberValue, int64Min) 369 | XCTAssertEqual(json.stringValue, int64Min.stringValue) 370 | } 371 | 372 | func testUInt64() { 373 | let uInt64Max = NSNumber(unsignedLongLong: UINT64_MAX) 374 | var json = JSON(uInt64Max) 375 | XCTAssertTrue(json.uInt64! == uInt64Max.unsignedLongLongValue) 376 | XCTAssertTrue(json.uInt64Value == uInt64Max.unsignedLongLongValue) 377 | XCTAssertTrue(json.number! == uInt64Max) 378 | XCTAssertEqual(json.numberValue, uInt64Max) 379 | XCTAssertEqual(json.stringValue, uInt64Max.stringValue) 380 | 381 | let n32767 = NSNumber(longLong: 32767) 382 | json.int64 = n32767.longLongValue 383 | XCTAssertTrue(json.int64! == n32767.longLongValue) 384 | XCTAssertTrue(json.int64Value == n32767.longLongValue) 385 | XCTAssertTrue(json.number! == n32767) 386 | XCTAssertEqual(json.numberValue, n32767) 387 | XCTAssertEqual(json.stringValue, "32767") 388 | } 389 | } 390 | -------------------------------------------------------------------------------- /Tests/PerformanceTests.swift: -------------------------------------------------------------------------------- 1 | // PerformanceTests.swift 2 | // 3 | // Copyright (c) 2014 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 XCTest 24 | import SwiftyJSON 25 | 26 | class PerformanceTests: XCTestCase { 27 | 28 | var testData: NSData! 29 | 30 | override func setUp() { 31 | super.setUp() 32 | 33 | if let file = NSBundle(forClass:PerformanceTests.self).pathForResource("Tests", ofType: "json") { 34 | self.testData = NSData(contentsOfFile: file) 35 | } else { 36 | XCTFail("Can't find the test JSON file") 37 | } 38 | } 39 | 40 | override func tearDown() { 41 | // Put teardown code here. This method is called after the invocation of each test method in the class. 42 | super.tearDown() 43 | } 44 | 45 | func testInitPerformance() { 46 | self.measureBlock() { 47 | for _ in 1...100 { 48 | let json = JSON(data:self.testData) 49 | XCTAssertTrue(json != JSON.nullJSON) 50 | } 51 | } 52 | } 53 | 54 | func testObjectMethodPerformance() { 55 | var json = JSON(data:self.testData) 56 | self.measureBlock() { 57 | for _ in 1...100 { 58 | let object:AnyObject? = json.object 59 | XCTAssertTrue(object != nil) 60 | } 61 | } 62 | } 63 | 64 | func testArrayMethodPerformance() { 65 | let json = JSON(data:self.testData) 66 | self.measureBlock() { 67 | for _ in 1...100 { 68 | autoreleasepool{ 69 | let array = json.array 70 | XCTAssertTrue(array?.count > 0) 71 | } 72 | } 73 | } 74 | } 75 | 76 | func testDictionaryMethodPerformance() { 77 | let json = JSON(data:testData)[0] 78 | self.measureBlock() { 79 | for _ in 1...100 { 80 | autoreleasepool{ 81 | var dictionary = json.dictionary 82 | XCTAssertTrue(dictionary?.count > 0) 83 | } 84 | } 85 | } 86 | } 87 | 88 | func testRawStringMethodPerformance() { 89 | let json = JSON(data:testData) 90 | self.measureBlock() { 91 | for _ in 1...100 { 92 | autoreleasepool{ 93 | var string = json.rawString() 94 | XCTAssertTrue(string != nil) 95 | } 96 | } 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /Tests/PrintableTests.swift: -------------------------------------------------------------------------------- 1 | // PrintableTests.swift 2 | // 3 | // Copyright (c) 2014 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 XCTest 24 | import SwiftyJSON 25 | 26 | class PrintableTests: XCTestCase { 27 | func testNumber() { 28 | var json:JSON = 1234567890.876623 29 | XCTAssertEqual(json.description, "1234567890.876623") 30 | XCTAssertEqual(json.debugDescription, "1234567890.876623") 31 | } 32 | 33 | func testBool() { 34 | var jsonTrue:JSON = true 35 | XCTAssertEqual(jsonTrue.description, "true") 36 | XCTAssertEqual(jsonTrue.debugDescription, "true") 37 | var jsonFalse:JSON = false 38 | XCTAssertEqual(jsonFalse.description, "false") 39 | XCTAssertEqual(jsonFalse.debugDescription, "false") 40 | } 41 | 42 | func testString() { 43 | var json:JSON = "abcd efg, HIJK;LMn" 44 | XCTAssertEqual(json.description, "abcd efg, HIJK;LMn") 45 | XCTAssertEqual(json.debugDescription, "abcd efg, HIJK;LMn") 46 | } 47 | 48 | func testNil() { 49 | var jsonNil_1:JSON = nil 50 | XCTAssertEqual(jsonNil_1.description, "null") 51 | XCTAssertEqual(jsonNil_1.debugDescription, "null") 52 | var jsonNil_2:JSON = JSON(NSNull()) 53 | XCTAssertEqual(jsonNil_2.description, "null") 54 | XCTAssertEqual(jsonNil_2.debugDescription, "null") 55 | } 56 | 57 | func testArray() { 58 | var json:JSON = [1,2,"4",5,"6"] 59 | var description = json.description.stringByReplacingOccurrencesOfString("\n", withString: "") 60 | description = description.stringByReplacingOccurrencesOfString(" ", withString: "") 61 | XCTAssertEqual(description, "[1,2,\"4\",5,\"6\"]") 62 | XCTAssertTrue(json.description.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) 63 | XCTAssertTrue(json.debugDescription.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) 64 | } 65 | 66 | func testDictionary() { 67 | var json:JSON = ["1":2,"2":"two", "3":3] 68 | var debugDescription = json.debugDescription.stringByReplacingOccurrencesOfString("\n", withString: "") 69 | debugDescription = debugDescription.stringByReplacingOccurrencesOfString(" ", withString: "") 70 | XCTAssertTrue(json.description.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) 71 | XCTAssertTrue(debugDescription.rangeOfString("\"1\":2", options: NSStringCompareOptions.CaseInsensitiveSearch) != nil) 72 | XCTAssertTrue(debugDescription.rangeOfString("\"2\":\"two\"", options: NSStringCompareOptions.CaseInsensitiveSearch) != nil) 73 | XCTAssertTrue(debugDescription.rangeOfString("\"3\":3", options: NSStringCompareOptions.CaseInsensitiveSearch) != nil) 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Tests/RawRepresentableTests.swift: -------------------------------------------------------------------------------- 1 | // RawRepresentableTests.swift 2 | // 3 | // Copyright (c) 2014 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 XCTest 24 | import SwiftyJSON 25 | 26 | class RawRepresentableTests: XCTestCase { 27 | 28 | func testNumber() { 29 | var json:JSON = JSON(rawValue: 948394394.347384 as NSNumber)! 30 | XCTAssertEqual(json.int!, 948394394) 31 | XCTAssertEqual(json.intValue, 948394394) 32 | XCTAssertEqual(json.double!, 948394394.347384) 33 | XCTAssertEqual(json.doubleValue, 948394394.347384) 34 | XCTAssertTrue(json.float! == 948394394.347384) 35 | XCTAssertTrue(json.floatValue == 948394394.347384) 36 | 37 | var object: AnyObject = json.rawValue 38 | XCTAssertEqual(object as Int, 948394394) 39 | XCTAssertEqual(object as Double, 948394394.347384) 40 | XCTAssertTrue(object as Float == 948394394.347384) 41 | XCTAssertEqual(object as NSNumber, 948394394.347384) 42 | } 43 | 44 | func testBool() { 45 | var jsonTrue:JSON = JSON(rawValue: true as NSNumber)! 46 | XCTAssertEqual(jsonTrue.bool!, true) 47 | XCTAssertEqual(jsonTrue.boolValue, true) 48 | 49 | var jsonFalse:JSON = JSON(rawValue: false)! 50 | XCTAssertEqual(jsonFalse.bool!, false) 51 | XCTAssertEqual(jsonFalse.boolValue, false) 52 | 53 | var objectTrue: AnyObject = jsonTrue.rawValue 54 | XCTAssertEqual(objectTrue as Int, 1) 55 | XCTAssertEqual(objectTrue as Double, 1.0) 56 | XCTAssertEqual(objectTrue as Bool, true) 57 | XCTAssertEqual(objectTrue as NSNumber, NSNumber(bool: true)) 58 | 59 | var objectFalse: AnyObject = jsonFalse.rawValue 60 | XCTAssertEqual(objectFalse as Int, 0) 61 | XCTAssertEqual(objectFalse as Double, 0.0) 62 | XCTAssertEqual(objectFalse as Bool, false) 63 | XCTAssertEqual(objectFalse as NSNumber, NSNumber(bool: false)) 64 | } 65 | 66 | func testString() { 67 | let string = "The better way to deal with JSON data in Swift." 68 | if let json:JSON = JSON(rawValue: string) { 69 | XCTAssertEqual(json.string!, string) 70 | XCTAssertEqual(json.stringValue, string) 71 | XCTAssertTrue(json.array == nil) 72 | XCTAssertTrue(json.dictionary == nil) 73 | XCTAssertTrue(json.null == nil) 74 | XCTAssertTrue(json.error == nil) 75 | XCTAssertTrue(json.type == .String) 76 | XCTAssertEqual(json.object as String, string) 77 | } else { 78 | XCTFail("Should not run into here") 79 | } 80 | 81 | let object: AnyObject = JSON(rawValue: string)!.rawValue 82 | XCTAssertEqual(object as String, string) 83 | } 84 | 85 | func testNil() { 86 | if let json = JSON(rawValue: NSObject()) { 87 | XCTFail("Should not run into here") 88 | } 89 | } 90 | 91 | func testArray() { 92 | let array = [1,2,"3",4102,"5632", "abocde", "!@# $%^&*()"] as NSArray 93 | if let json:JSON = JSON(rawValue: array) { 94 | XCTAssertEqual(json, JSON(array)) 95 | } 96 | 97 | let object: AnyObject = JSON(rawValue: array)!.rawValue 98 | XCTAssertTrue(array == object as NSArray) 99 | } 100 | 101 | func testDictionary() { 102 | let dictionary = ["1":2,"2":2,"three":3,"list":["aa","bb","dd"]] as NSDictionary 103 | if let json:JSON = JSON(rawValue: dictionary) { 104 | XCTAssertEqual(json, JSON(dictionary)) 105 | } 106 | 107 | let object: AnyObject = JSON(rawValue: dictionary)!.rawValue 108 | XCTAssertTrue(dictionary == object as NSDictionary) 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /Tests/RawTests.swift: -------------------------------------------------------------------------------- 1 | // RawTests.swift 2 | // 3 | // Copyright (c) 2014 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 XCTest 24 | import SwiftyJSON 25 | 26 | class RawTests: XCTestCase { 27 | 28 | func testArray() { 29 | let json:JSON = [1, "2", 3.12, NSNull(), true, ["name": "Jack"]] 30 | let data = json.rawData() 31 | let string = json.rawString() 32 | XCTAssertTrue (data != nil) 33 | XCTAssertTrue (string!.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) 34 | println(string!) 35 | } 36 | 37 | func testDictionary() { 38 | let json:JSON = ["number":111111.23456789, "name":"Jack", "list":[1,2,3,4], "bool":false, "null":NSNull()] 39 | let data = json.rawData() 40 | let string = json.rawString() 41 | XCTAssertTrue (data != nil) 42 | XCTAssertTrue (string!.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) 43 | println(string!) 44 | } 45 | 46 | func testString() { 47 | let json:JSON = "I'm a json" 48 | println(json.rawString()) 49 | XCTAssertTrue(json.rawString() == "I'm a json") 50 | } 51 | 52 | func testNumber() { 53 | let json:JSON = 123456789.123 54 | println(json.rawString()) 55 | XCTAssertTrue(json.rawString() == "123456789.123") 56 | } 57 | 58 | func testBool() { 59 | let json:JSON = true 60 | println(json.rawString()) 61 | XCTAssertTrue(json.rawString() == "true") 62 | } 63 | 64 | func testNull() { 65 | let json:JSON = nil 66 | println(json.rawString()) 67 | XCTAssertTrue(json.rawString() == "null") 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Tests/SequenceTypeTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SequenceTypeTests.swift 3 | // 4 | // Copyright (c) 2014 Pinglin Tang 5 | // 6 | // Permission is hereby granted, free of charge, to any person obtaining a copy 7 | // of this software and associated documentation files (the "Software"), to deal 8 | // in the Software without restriction, including without limitation the rights 9 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | // copies of the Software, and to permit persons to whom the Software is 11 | // furnished to do so, subject to the following conditions: 12 | // 13 | // The above copyright notice and this permission notice shall be included in 14 | // all copies or substantial portions of the Software. 15 | // 16 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | // THE SOFTWARE. 23 | 24 | import XCTest 25 | import SwiftyJSON 26 | 27 | class SequenceTypeTests: XCTestCase { 28 | 29 | func testJSONFile() { 30 | if let file = NSBundle(forClass:BaseTests.self).pathForResource("Tests", ofType: "json") { 31 | let testData = NSData(contentsOfFile: file) 32 | let json = JSON(data:testData!) 33 | for (index, sub) in json { 34 | switch (index as NSString).integerValue { 35 | case 0: 36 | XCTAssertTrue(sub["id_str"] == "240558470661799936") 37 | case 1: 38 | XCTAssertTrue(sub["id_str"] == "240556426106372096") 39 | case 2: 40 | XCTAssertTrue(sub["id_str"] == "240539141056638977") 41 | default:0 42 | } 43 | } 44 | } else { 45 | XCTFail("Can't find the test JSON file") 46 | } 47 | } 48 | 49 | func testArrayAllNumber() { 50 | var json:JSON = [1,2.0,3.3,123456789,987654321.123456789] 51 | XCTAssertEqual(json.count, 5) 52 | 53 | var index = 0 54 | var array = [NSNumber]() 55 | for (i, sub) in json { 56 | XCTAssertEqual(sub, json[index]) 57 | XCTAssertEqual(i, "\(index)") 58 | array.append(sub.number!) 59 | index++ 60 | } 61 | XCTAssertEqual(index, 5) 62 | XCTAssertEqual(array, [1,2.0,3.3,123456789,987654321.123456789]) 63 | } 64 | 65 | func testArrayAllBool() { 66 | var json:JSON = JSON([true, false, false, true, true]) 67 | XCTAssertEqual(json.count, 5) 68 | 69 | var index = 0 70 | var array = [Bool]() 71 | for (i, sub) in json { 72 | XCTAssertEqual(sub, json[index]) 73 | XCTAssertEqual(i, "\(index)") 74 | array.append(sub.bool!) 75 | index++ 76 | } 77 | XCTAssertEqual(index, 5) 78 | XCTAssertEqual(array, [true, false, false, true, true]) 79 | } 80 | 81 | func testArrayAllString() { 82 | var json:JSON = JSON(rawValue: ["aoo","bpp","zoo"] as NSArray)! 83 | XCTAssertEqual(json.count, 3) 84 | 85 | var index = 0 86 | var array = [String]() 87 | for (i, sub) in json { 88 | XCTAssertEqual(sub, json[index]) 89 | XCTAssertEqual(i, "\(index)") 90 | array.append(sub.string!) 91 | index++ 92 | } 93 | XCTAssertEqual(index, 3) 94 | XCTAssertEqual(array, ["aoo","bpp","zoo"]) 95 | } 96 | 97 | func testArrayWithNull() { 98 | var json:JSON = JSON(rawValue: ["aoo","bpp", NSNull() ,"zoo"] as NSArray)! 99 | XCTAssertEqual(json.count, 4) 100 | 101 | var index = 0 102 | var array = [AnyObject]() 103 | for (i, sub) in json { 104 | XCTAssertEqual(sub, json[index]) 105 | XCTAssertEqual(i, "\(index)") 106 | array.append(sub.object) 107 | index++ 108 | } 109 | XCTAssertEqual(index, 4) 110 | XCTAssertEqual(array[0] as String, "aoo") 111 | XCTAssertEqual(array[2] as NSNull, NSNull()) 112 | } 113 | 114 | func testArrayAllDictionary() { 115 | var json:JSON = [["1":1, "2":2], ["a":"A", "b":"B"], ["null":NSNull()]] 116 | XCTAssertEqual(json.count, 3) 117 | 118 | var index = 0 119 | var array = [AnyObject]() 120 | for (i, sub) in json { 121 | XCTAssertEqual(sub, json[index]) 122 | XCTAssertEqual(i, "\(index)") 123 | array.append(sub.object) 124 | index++ 125 | } 126 | XCTAssertEqual(index, 3) 127 | XCTAssertEqual((array[0] as [String : Int])["1"]!, 1) 128 | XCTAssertEqual((array[0] as [String : Int])["2"]!, 2) 129 | XCTAssertEqual((array[1] as [String : String])["a"]!, "A") 130 | XCTAssertEqual((array[1] as [String : String])["b"]!, "B") 131 | XCTAssertEqual((array[2] as [String : NSNull])["null"]!, NSNull()) 132 | } 133 | 134 | func testDictionaryAllNumber() { 135 | var json:JSON = ["double":1.11111, "int":987654321] 136 | XCTAssertEqual(json.count, 2) 137 | 138 | var index = 0 139 | var dictionary = [String:NSNumber]() 140 | for (key, sub) in json { 141 | XCTAssertEqual(sub, json[key]) 142 | dictionary[key] = sub.number! 143 | index++ 144 | } 145 | 146 | XCTAssertEqual(index, 2) 147 | XCTAssertEqual(dictionary["double"]! as NSNumber, 1.11111) 148 | XCTAssertEqual(dictionary["int"]! as NSNumber, 987654321) 149 | } 150 | 151 | func testDictionaryAllBool() { 152 | var json:JSON = ["t":true, "f":false, "false":false, "tr":true, "true":true] 153 | XCTAssertEqual(json.count, 5) 154 | 155 | var index = 0 156 | var dictionary = [String:Bool]() 157 | for (key, sub) in json { 158 | XCTAssertEqual(sub, json[key]) 159 | dictionary[key] = sub.bool! 160 | index++ 161 | } 162 | 163 | XCTAssertEqual(index, 5) 164 | XCTAssertEqual(dictionary["t"]! as Bool, true) 165 | XCTAssertEqual(dictionary["false"]! as Bool, false) 166 | } 167 | 168 | func testDictionaryAllString() { 169 | var json:JSON = JSON(rawValue: ["a":"aoo","bb":"bpp","z":"zoo"] as NSDictionary)! 170 | XCTAssertEqual(json.count, 3) 171 | 172 | var index = 0 173 | var dictionary = [String:String]() 174 | for (key, sub) in json { 175 | XCTAssertEqual(sub, json[key]) 176 | dictionary[key] = sub.string! 177 | index++ 178 | } 179 | 180 | XCTAssertEqual(index, 3) 181 | XCTAssertEqual(dictionary["a"]! as String, "aoo") 182 | XCTAssertEqual(dictionary["bb"]! as String, "bpp") 183 | } 184 | 185 | func testDictionaryWithNull() { 186 | var json:JSON = JSON(rawValue: ["a":"aoo","bb":"bpp","null":NSNull(), "z":"zoo"] as NSDictionary)! 187 | XCTAssertEqual(json.count, 4) 188 | 189 | var index = 0 190 | var dictionary = [String:AnyObject]() 191 | for (key, sub) in json { 192 | XCTAssertEqual(sub, json[key]) 193 | dictionary[key] = sub.object 194 | index++ 195 | } 196 | 197 | XCTAssertEqual(index, 4) 198 | XCTAssertEqual(dictionary["a"]! as String, "aoo") 199 | XCTAssertEqual(dictionary["bb"]! as String, "bpp") 200 | XCTAssertEqual(dictionary["null"]! as NSNull, NSNull()) 201 | } 202 | 203 | func testDictionaryAllArray() { 204 | var json:JSON = JSON (["Number":[NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)], "String":["aa","bbb","cccc"], "Mix":[true, "766", NSNull(), 655231.9823]]) 205 | 206 | XCTAssertEqual(json.count, 3) 207 | 208 | var index = 0 209 | var dictionary = [String:AnyObject]() 210 | for (key, sub) in json { 211 | XCTAssertEqual(sub, json[key]) 212 | dictionary[key] = sub.object 213 | index++ 214 | } 215 | 216 | XCTAssertEqual(index, 3) 217 | XCTAssertEqual((dictionary["Number"] as NSArray)[0] as Int, 1) 218 | XCTAssertEqual((dictionary["Number"] as NSArray)[1] as Double, 2.123456) 219 | XCTAssertEqual((dictionary["String"] as NSArray)[0] as String, "aa") 220 | XCTAssertEqual((dictionary["Mix"] as NSArray)[0] as Bool, true) 221 | XCTAssertEqual((dictionary["Mix"] as NSArray)[1] as String, "766") 222 | XCTAssertEqual((dictionary["Mix"] as NSArray)[2] as NSNull, NSNull()) 223 | XCTAssertEqual((dictionary["Mix"] as NSArray)[3] as Double, 655231.9823) 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /Tests/StringTests.swift: -------------------------------------------------------------------------------- 1 | // StringTests.swift 2 | // 3 | // Copyright (c) 2014 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 XCTest 24 | import SwiftyJSON 25 | 26 | class StringTests: XCTestCase { 27 | 28 | func testString() { 29 | //getter 30 | var json = JSON("abcdefg hijklmn;opqrst.?+_()") 31 | XCTAssertEqual(json.string!, "abcdefg hijklmn;opqrst.?+_()") 32 | XCTAssertEqual(json.stringValue, "abcdefg hijklmn;opqrst.?+_()") 33 | 34 | json.string = "12345?67890.@#" 35 | XCTAssertEqual(json.string!, "12345?67890.@#") 36 | XCTAssertEqual(json.stringValue, "12345?67890.@#") 37 | } 38 | 39 | func testURL() { 40 | let json = JSON("http://github.com") 41 | XCTAssertEqual(json.URL!, NSURL(string:"http://github.com")!) 42 | } 43 | 44 | func testURLPercentEscapes() { 45 | let emDash = "\\u2014" 46 | let urlString = "http://examble.com/unencoded" + emDash + "string" 47 | let encodedURLString = urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) 48 | let json = JSON(urlString) 49 | XCTAssertEqual(json.URL!, NSURL(string: encodedURLString!)!, "Wrong unpacked ") 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Tests/SubscriptTests.swift: -------------------------------------------------------------------------------- 1 | // SubscriptTests.swift 2 | // 3 | // Copyright (c) 2014 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 XCTest 24 | import SwiftyJSON 25 | 26 | class SubscriptTests: XCTestCase { 27 | 28 | func testArrayAllNumber() { 29 | var json:JSON = [1,2.0,3.3,123456789,987654321.123456789] 30 | XCTAssertTrue(json == [1,2.0,3.3,123456789,987654321.123456789]) 31 | XCTAssertTrue(json[0] == 1) 32 | XCTAssertEqual(json[1].double!, 2.0) 33 | XCTAssertTrue(json[2].floatValue == 3.3) 34 | XCTAssertEqual(json[3].int!, 123456789) 35 | XCTAssertEqual(json[4].doubleValue, 987654321.123456789) 36 | 37 | json[0] = 1.9 38 | json[1] = 2.899 39 | json[2] = 3.567 40 | json[3] = 0.999 41 | json[4] = 98732 42 | 43 | XCTAssertTrue(json[0] == 1.9) 44 | XCTAssertEqual(json[1].doubleValue, 2.899) 45 | XCTAssertTrue(json[2] == 3.567) 46 | XCTAssertTrue(json[3].float! == 0.999) 47 | XCTAssertTrue(json[4].intValue == 98732) 48 | } 49 | 50 | func testArrayAllBool() { 51 | var json:JSON = [true, false, false, true, true] 52 | XCTAssertTrue(json == [true, false, false, true, true]) 53 | XCTAssertTrue(json[0] == true) 54 | XCTAssertTrue(json[1] == false) 55 | XCTAssertTrue(json[2] == false) 56 | XCTAssertTrue(json[3] == true) 57 | XCTAssertTrue(json[4] == true) 58 | 59 | json[0] = false 60 | json[4] = true 61 | XCTAssertTrue(json[0] == false) 62 | XCTAssertTrue(json[4] == true) 63 | } 64 | 65 | func testArrayAllString() { 66 | var json:JSON = JSON(rawValue: ["aoo","bpp","zoo"] as NSArray)! 67 | XCTAssertTrue(json == ["aoo","bpp","zoo"]) 68 | XCTAssertTrue(json[0] == "aoo") 69 | XCTAssertTrue(json[1] == "bpp") 70 | XCTAssertTrue(json[2] == "zoo") 71 | 72 | json[1] = "update" 73 | XCTAssertTrue(json[0] == "aoo") 74 | XCTAssertTrue(json[1] == "update") 75 | XCTAssertTrue(json[2] == "zoo") 76 | } 77 | 78 | func testArrayWithNull() { 79 | var json:JSON = JSON(rawValue: ["aoo","bpp", NSNull() ,"zoo"] as NSArray)! 80 | XCTAssertTrue(json[0] == "aoo") 81 | XCTAssertTrue(json[1] == "bpp") 82 | XCTAssertNil(json[2].string) 83 | XCTAssertNotNil(json[2].null) 84 | XCTAssertTrue(json[3] == "zoo") 85 | 86 | json[2] = "update" 87 | json[3] = JSON(NSNull()) 88 | XCTAssertTrue(json[0] == "aoo") 89 | XCTAssertTrue(json[1] == "bpp") 90 | XCTAssertTrue(json[2] == "update") 91 | XCTAssertNil(json[3].string) 92 | XCTAssertNotNil(json[3].null) 93 | } 94 | 95 | func testArrayAllDictionary() { 96 | var json:JSON = [["1":1, "2":2], ["a":"A", "b":"B"], ["null":NSNull()]] 97 | XCTAssertTrue(json[0] == ["1":1, "2":2]) 98 | XCTAssertEqual(json[1].dictionary!, ["a":"A", "b":"B"]) 99 | XCTAssertEqual(json[2], JSON(["null":NSNull()])) 100 | XCTAssertTrue(json[0]["1"] == 1) 101 | XCTAssertTrue(json[0]["2"] == 2) 102 | XCTAssertEqual(json[1]["a"], JSON(rawValue: "A")!) 103 | XCTAssertEqual(json[1]["b"], JSON("B")) 104 | XCTAssertNotNil(json[2]["null"].null) 105 | XCTAssertNotNil(json[2,"null"].null) 106 | } 107 | 108 | func testDictionaryAllNumber() { 109 | var json:JSON = ["double":1.11111, "int":987654321] 110 | XCTAssertEqual(json["double"].double!, 1.11111) 111 | XCTAssertTrue(json["int"] == 987654321) 112 | 113 | json["double"] = 2.2222 114 | json["int"] = 123456789 115 | json["add"] = 7890 116 | XCTAssertTrue(json["double"] == 2.2222) 117 | XCTAssertEqual(json["int"].doubleValue, 123456789.0) 118 | XCTAssertEqual(json["add"].intValue, 7890) 119 | } 120 | 121 | func testDictionaryAllBool() { 122 | var json:JSON = ["t":true, "f":false, "false":false, "tr":true, "true":true] 123 | XCTAssertTrue(json["t"] == true) 124 | XCTAssertTrue(json["f"] == false) 125 | XCTAssertTrue(json["false"] == false) 126 | XCTAssertTrue(json["tr"] == true) 127 | XCTAssertTrue(json["true"] == true) 128 | 129 | json["f"] = true 130 | json["tr"] = false 131 | XCTAssertTrue(json["f"] == true) 132 | XCTAssertTrue(json["tr"] == JSON(false)) 133 | } 134 | 135 | func testDictionaryAllString() { 136 | var json:JSON = JSON(rawValue: ["a":"aoo","bb":"bpp","z":"zoo"] as NSDictionary)! 137 | XCTAssertTrue(json["a"] == "aoo") 138 | XCTAssertEqual(json["bb"], JSON("bpp")) 139 | XCTAssertTrue(json["z"] == "zoo") 140 | 141 | json["bb"] = "update" 142 | XCTAssertTrue(json["a"] == "aoo") 143 | XCTAssertTrue(json["bb"] == "update") 144 | XCTAssertTrue(json["z"] == "zoo") 145 | } 146 | 147 | func testDictionaryWithNull() { 148 | var json:JSON = JSON(rawValue: ["a":"aoo","bb":"bpp","null":NSNull(), "z":"zoo"] as NSDictionary)! 149 | XCTAssertTrue(json["a"] == "aoo") 150 | XCTAssertEqual(json["bb"], JSON("bpp")) 151 | XCTAssertEqual(json["null"], JSON(NSNull())) 152 | XCTAssertTrue(json["z"] == "zoo") 153 | 154 | json["null"] = "update" 155 | XCTAssertTrue(json["a"] == "aoo") 156 | XCTAssertTrue(json["null"] == "update") 157 | XCTAssertTrue(json["z"] == "zoo") 158 | } 159 | 160 | func testDictionaryAllArray() { 161 | //Swift bug: [1, 2.01,3.09] is convert to [1, 2, 3] (Array) 162 | let json:JSON = JSON ([[NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) 163 | XCTAssertTrue(json[0] == [1,2.123456,123456789]) 164 | XCTAssertEqual(json[0][1].double!, 2.123456) 165 | XCTAssertTrue(json[0][2] == 123456789) 166 | XCTAssertTrue(json[1][0] == "aa") 167 | XCTAssertTrue(json[1] == ["aa","bbb","cccc"]) 168 | XCTAssertTrue(json[2][0] == true) 169 | XCTAssertTrue(json[2][1] == "766") 170 | XCTAssertTrue(json[[2,1]] == "766") 171 | XCTAssertEqual(json[2][2], JSON(NSNull())) 172 | XCTAssertEqual(json[2,2], JSON(NSNull())) 173 | XCTAssertEqual(json[2][3], JSON(655231.9823)) 174 | XCTAssertEqual(json[2,3], JSON(655231.9823)) 175 | XCTAssertEqual(json[[2,3]], JSON(655231.9823)) 176 | } 177 | 178 | func testOutOfBounds() { 179 | let json:JSON = JSON ([[NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) 180 | XCTAssertEqual(json[9], JSON.nullJSON) 181 | XCTAssertEqual(json[-2].error!.code, ErrorIndexOutOfBounds) 182 | XCTAssertEqual(json[6].error!.code, ErrorIndexOutOfBounds) 183 | XCTAssertEqual(json[9][8], JSON.nullJSON) 184 | XCTAssertEqual(json[8][7].error!.code, ErrorIndexOutOfBounds) 185 | XCTAssertEqual(json[8,7].error!.code, ErrorIndexOutOfBounds) 186 | XCTAssertEqual(json[999].error!.code, ErrorIndexOutOfBounds) 187 | } 188 | 189 | func testErrorWrongType() { 190 | let json = JSON(12345) 191 | XCTAssertEqual(json[9], JSON.nullJSON) 192 | XCTAssertEqual(json[9].error!.code, ErrorWrongType) 193 | XCTAssertEqual(json[8][7].error!.code, ErrorWrongType) 194 | XCTAssertEqual(json["name"], JSON.nullJSON) 195 | XCTAssertEqual(json["name"].error!.code, ErrorWrongType) 196 | XCTAssertEqual(json[0]["name"].error!.code, ErrorWrongType) 197 | XCTAssertEqual(json["type"]["name"].error!.code, ErrorWrongType) 198 | XCTAssertEqual(json["name"][99].error!.code, ErrorWrongType) 199 | XCTAssertEqual(json[1,"Value"].error!.code, ErrorWrongType) 200 | XCTAssertEqual(json[1, 2,"Value"].error!.code, ErrorWrongType) 201 | XCTAssertEqual(json[[1, 2,"Value"]].error!.code, ErrorWrongType) 202 | } 203 | 204 | func testErrorNotExist() { 205 | let json:JSON = ["name":"NAME", "age":15] 206 | XCTAssertEqual(json["Type"], JSON.nullJSON) 207 | XCTAssertEqual(json["Type"].error!.code, ErrorNotExist) 208 | XCTAssertEqual(json["Type"][1].error!.code, ErrorNotExist) 209 | XCTAssertEqual(json["Type", 1].error!.code, ErrorNotExist) 210 | XCTAssertEqual(json["Type"]["Value"].error!.code, ErrorNotExist) 211 | XCTAssertEqual(json["Type","Value"].error!.code, ErrorNotExist) 212 | } 213 | 214 | func testMultilevelGetter() { 215 | let json:JSON = [[[[["one":1]]]]] 216 | XCTAssertEqual(json[[0, 0, 0, 0, "one"]].int!, 1) 217 | XCTAssertEqual(json[0, 0, 0, 0, "one"].int!, 1) 218 | XCTAssertEqual(json[0][0][0][0]["one"].int!, 1) 219 | } 220 | 221 | func testMultilevelSetter() { 222 | var json:JSON = [[[[["num":1]]]]] 223 | json[0, 0, 0, 0, "num"] = 2 224 | XCTAssertEqual(json[[0, 0, 0, 0, "num"]].intValue, 2) 225 | json[0, 0, 0, 0, "num"] = nil 226 | XCTAssertEqual(json[0, 0, 0, 0, "num"].null!, NSNull()) 227 | json[0, 0, 0, 0, "num"] = 100.009 228 | XCTAssertEqual(json[0][0][0][0]["num"].doubleValue, 100.009) 229 | json[[0, 0, 0, 0]] = ["name":"Jack"] 230 | XCTAssertEqual(json[0,0,0,0,"name"].stringValue, "Jack") 231 | XCTAssertEqual(json[0][0][0][0]["name"].stringValue, "Jack") 232 | XCTAssertEqual(json[[0,0,0,0,"name"]].stringValue, "Jack") 233 | json[[0,0,0,0,"name"]].string = "Mike" 234 | XCTAssertEqual(json[0,0,0,0,"name"].stringValue, "Mike") 235 | let path:[SubscriptType] = [0,0,0,0,"name"] 236 | json[path].string = "Jim" 237 | XCTAssertEqual(json[path].stringValue, "Jim") 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /Tests/Tests.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "coordinates":null, 4 | "truncated":false, 5 | "created_at":"Tue Aug 28 21:16:23 +0000 2012", 6 | "favorited":false, 7 | "id_str":"240558470661799936", 8 | "in_reply_to_user_id_str":null, 9 | "entities":{ 10 | "urls":[ 11 | 12 | ], 13 | "hashtags":[ 14 | 15 | ], 16 | "user_mentions":[ 17 | 18 | ] 19 | }, 20 | "text":"just another test", 21 | "contributors":null, 22 | "id":240558470661799936, 23 | "retweet_count":0, 24 | "in_reply_to_status_id_str":null, 25 | "geo":null, 26 | "retweeted":false, 27 | "in_reply_to_user_id":null, 28 | "place":null, 29 | "source":"<a href=\"//realitytechnicians.com\" rel=\"\"nofollow\"\">OAuth Dancer Reborn</a>", 30 | "user":{ 31 | "name":"OAuth Dancer", 32 | "profile_sidebar_fill_color":"DDEEF6", 33 | "profile_background_tile":true, 34 | "profile_sidebar_border_color":"C0DEED", 35 | "profile_image_url":"http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg", 36 | "created_at":"Wed Mar 03 19:37:35 +0000 2010", 37 | "location":"San Francisco, CA", 38 | "follow_request_sent":false, 39 | "id_str":"119476949", 40 | "is_translator":false, 41 | "profile_link_color":"0084B4", 42 | "entities":{ 43 | "url":{ 44 | "urls":[ 45 | { 46 | "expanded_url":null, 47 | "url":"http://bit.ly/oauth-dancer", 48 | "indices":[ 49 | 0, 50 | 26 51 | ], 52 | "display_url":null 53 | } 54 | ] 55 | }, 56 | "description":null 57 | }, 58 | "default_profile":false, 59 | "url":"http://bit.ly/oauth-dancer", 60 | "contributors_enabled":false, 61 | "favourites_count":7, 62 | "utc_offset":null, 63 | "profile_image_url_https":"https://si0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg", 64 | "id":119476949, 65 | "listed_count":1, 66 | "profile_use_background_image":true, 67 | "profile_text_color":"333333", 68 | "followers_count":28, 69 | "lang":"en", 70 | "protected":false, 71 | "geo_enabled":true, 72 | "notifications":false, 73 | "description":"", 74 | "profile_background_color":"C0DEED", 75 | "verified":false, 76 | "time_zone":null, 77 | "profile_background_image_url_https":"https://si0.twimg.com/profile_background_images/80151733/oauth-dance.png", 78 | "statuses_count":166, 79 | "profile_background_image_url":"http://a0.twimg.com/profile_background_images/80151733/oauth-dance.png", 80 | "default_profile_image":false, 81 | "friends_count":14, 82 | "following":false, 83 | "show_all_inline_media":false, 84 | "screen_name":"oauth_dancer" 85 | }, 86 | "in_reply_to_screen_name":null, 87 | "in_reply_to_status_id":null 88 | }, 89 | { 90 | "coordinates":{ 91 | "coordinates":[ 92 | -122.25831, 93 | 37.871609 94 | ], 95 | "type":"Point" 96 | }, 97 | "truncated":false, 98 | "created_at":"Tue Aug 28 21:08:15 +0000 2012", 99 | "favorited":false, 100 | "id_str":"240556426106372096", 101 | "in_reply_to_user_id_str":null, 102 | "entities":{ 103 | "urls":[ 104 | { 105 | "expanded_url":"http://blogs.ischool.berkeley.edu/i290-abdt-s12/", 106 | "url":"http://t.co/bfj7zkDJ", 107 | "indices":[ 108 | 79, 109 | 99 110 | ], 111 | "display_url":"blogs.ischool.berkeley.edu/i290-abdt-s12/" 112 | } 113 | ], 114 | "hashtags":[ 115 | 116 | ], 117 | "user_mentions":[ 118 | { 119 | "name":"Cal", 120 | "id_str":"17445752", 121 | "id":17445752, 122 | "indices":[ 123 | 60, 124 | 64 125 | ], 126 | "screen_name":"Cal" 127 | }, 128 | { 129 | "name":"Othman Laraki", 130 | "id_str":"20495814", 131 | "id":20495814, 132 | "indices":[ 133 | 70, 134 | 77 135 | ], 136 | "screen_name":"othman" 137 | } 138 | ] 139 | }, 140 | "text":"lecturing at the \"analyzing big data with twitter\" class at @cal with @othman http://t.co/bfj7zkDJ", 141 | "contributors":null, 142 | "id":240556426106372096, 143 | "retweet_count":3, 144 | "in_reply_to_status_id_str":null, 145 | "geo":{ 146 | "coordinates":[ 147 | 37.871609, 148 | -122.25831 149 | ], 150 | "type":"Point" 151 | }, 152 | "retweeted":false, 153 | "possibly_sensitive":false, 154 | "in_reply_to_user_id":null, 155 | "place":{ 156 | "name":"Berkeley", 157 | "country_code":"US", 158 | "country":"United States", 159 | "attributes":{ 160 | 161 | }, 162 | "url":"http://api.twitter.com/1/geo/id/5ef5b7f391e30aff.json", 163 | "id":"5ef5b7f391e30aff", 164 | "bounding_box":{ 165 | "coordinates":[ 166 | [ 167 | [ 168 | -122.367781, 169 | 37.835727 170 | ], 171 | [ 172 | -122.234185, 173 | 37.835727 174 | ], 175 | [ 176 | -122.234185, 177 | 37.905824 178 | ], 179 | [ 180 | -122.367781, 181 | 37.905824 182 | ] 183 | ] 184 | ], 185 | "type":"Polygon" 186 | }, 187 | "full_name":"Berkeley, CA", 188 | "place_type":"city" 189 | }, 190 | "source":"<a href=\"//www.apple.com\"\" rel=\"\"nofollow\"\">Safari on iOS</a>", 191 | "user":{ 192 | "name":"Raffi Krikorian", 193 | "profile_sidebar_fill_color":"DDEEF6", 194 | "profile_background_tile":false, 195 | "profile_sidebar_border_color":"C0DEED", 196 | "profile_image_url":"http://a0.twimg.com/profile_images/1270234259/raffi-headshot-casual_normal.png", 197 | "created_at":"Sun Aug 19 14:24:06 +0000 2007", 198 | "location":"San Francisco, California", 199 | "follow_request_sent":false, 200 | "id_str":"8285392", 201 | "is_translator":false, 202 | "profile_link_color":"0084B4", 203 | "entities":{ 204 | "url":{ 205 | "urls":[ 206 | { 207 | "expanded_url":"http://about.me/raffi.krikorian", 208 | "url":"http://t.co/eNmnM6q", 209 | "indices":[ 210 | 0, 211 | 19 212 | ], 213 | "display_url":"about.me/raffi.krikorian" 214 | } 215 | ] 216 | }, 217 | "description":{ 218 | "urls":[ 219 | 220 | ] 221 | } 222 | }, 223 | "default_profile":true, 224 | "url":"http://t.co/eNmnM6q", 225 | "contributors_enabled":false, 226 | "favourites_count":724, 227 | "utc_offset":-28800, 228 | "profile_image_url_https":"https://si0.twimg.com/profile_images/1270234259/raffi-headshot-casual_normal.png", 229 | "id":8285392, 230 | "listed_count":619, 231 | "profile_use_background_image":true, 232 | "profile_text_color":"333333", 233 | "followers_count":18752, 234 | "lang":"en", 235 | "protected":false, 236 | "geo_enabled":true, 237 | "notifications":false, 238 | "description":"Director of @twittereng's Platform Services. I break things.", 239 | "profile_background_color":"C0DEED", 240 | "verified":false, 241 | "time_zone":"Pacific Time (US & Canada)", 242 | "profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme1/bg.png", 243 | "statuses_count":5007, 244 | "profile_background_image_url":"http://a0.twimg.com/images/themes/theme1/bg.png", 245 | "default_profile_image":false, 246 | "friends_count":701, 247 | "following":true, 248 | "show_all_inline_media":true, 249 | "screen_name":"raffi" 250 | }, 251 | "in_reply_to_screen_name":null, 252 | "in_reply_to_status_id":null 253 | }, 254 | { 255 | "coordinates":null, 256 | "truncated":false, 257 | "created_at":"Tue Aug 28 19:59:34 +0000 2012", 258 | "favorited":false, 259 | "id_str":"240539141056638977", 260 | "in_reply_to_user_id_str":null, 261 | "entities":{ 262 | "urls":[ 263 | 264 | ], 265 | "hashtags":[ 266 | 267 | ], 268 | "user_mentions":[ 269 | 270 | ] 271 | }, 272 | "text":"You'd be right more often if you thought you were wrong.", 273 | "contributors":null, 274 | "id":240539141056638977, 275 | "retweet_count":1, 276 | "in_reply_to_status_id_str":null, 277 | "geo":null, 278 | "retweeted":false, 279 | "in_reply_to_user_id":null, 280 | "place":null, 281 | "source":"web", 282 | "user":{ 283 | "name":"Taylor Singletary", 284 | "profile_sidebar_fill_color":"FBFBFB", 285 | "profile_background_tile":true, 286 | "profile_sidebar_border_color":"000000", 287 | "profile_image_url":"http://a0.twimg.com/profile_images/2546730059/f6a8zq58mg1hn0ha8vie_normal.jpeg", 288 | "created_at":"Wed Mar 07 22:23:19 +0000 2007", 289 | "location":"San Francisco, CA", 290 | "follow_request_sent":false, 291 | "id_str":"819797", 292 | "is_translator":false, 293 | "profile_link_color":"c71818", 294 | "entities":{ 295 | "url":{ 296 | "urls":[ 297 | { 298 | "expanded_url":"http://www.rebelmouse.com/episod/", 299 | "url":"http://t.co/Lxw7upbN", 300 | "indices":[ 301 | 0, 302 | 20 303 | ], 304 | "display_url":"rebelmouse.com/episod/" 305 | } 306 | ] 307 | }, 308 | "description":{ 309 | "urls":[ 310 | 311 | ] 312 | } 313 | }, 314 | "default_profile":false, 315 | "url":"http://t.co/Lxw7upbN", 316 | "contributors_enabled":false, 317 | "favourites_count":15990, 318 | "utc_offset":-28800, 319 | "profile_image_url_https":"https://si0.twimg.com/profile_images/2546730059/f6a8zq58mg1hn0ha8vie_normal.jpeg", 320 | "id":819797, 321 | "listed_count":340, 322 | "profile_use_background_image":true, 323 | "profile_text_color":"D20909", 324 | "followers_count":7126, 325 | "lang":"en", 326 | "protected":false, 327 | "geo_enabled":true, 328 | "notifications":false, 329 | "description":"Reality Technician, Twitter API team, synthesizer enthusiast; a most excellent adventure in timelines. I know it's hard to believe in something you can't see.", 330 | "profile_background_color":"000000", 331 | "verified":false, 332 | "time_zone":"Pacific Time (US & Canada)", 333 | "profile_background_image_url_https":"https://si0.twimg.com/profile_background_images/643655842/hzfv12wini4q60zzrthg.png", 334 | "statuses_count":18076, 335 | "profile_background_image_url":"http://a0.twimg.com/profile_background_images/643655842/hzfv12wini4q60zzrthg.png", 336 | "default_profile_image":false, 337 | "friends_count":5444, 338 | "following":true, 339 | "show_all_inline_media":true, 340 | "screen_name":"episod" 341 | }, 342 | "in_reply_to_screen_name":null, 343 | "in_reply_to_status_id":null 344 | } 345 | ] --------------------------------------------------------------------------------