├── .gitignore ├── LICENSE ├── README.md ├── SwiftJson.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── SwiftJson.xccheckout ├── SwiftJson ├── AppDelegate.swift ├── Base.lproj │ ├── Main.storyboard │ └── MainMenu.xib ├── Images.xcassets │ └── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── sjLogo1024.png │ │ ├── sjLogo128.png │ │ ├── sjLogo16.png │ │ ├── sjLogo256-1.png │ │ ├── sjLogo256.png │ │ ├── sjLogo32-1.png │ │ ├── sjLogo32.png │ │ ├── sjLogo512-1.png │ │ ├── sjLogo512.png │ │ └── sjLogo64.png ├── IndentableOutput.swift ├── Info.plist ├── MenuController.swift ├── ModelGenerator.swift ├── SwiftyJSON.swift ├── ViewController.swift └── main.swift ├── SwiftJsonTests ├── Info.plist └── SwiftJsonTests.swift └── screenshot.png /.gitignore: -------------------------------------------------------------------------------- 1 | ######################### 2 | # .gitignore file for Xcode4 and Xcode5 Source projects 3 | # 4 | # Apple bugs, waiting for Apple to fix/respond: 5 | # 6 | # 15564624 - what does the xccheckout file in Xcode5 do? Where's the documentation? 7 | # 8 | # Version 2.1 9 | # For latest version, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects 10 | # 11 | # 2013 updates: 12 | # - fixed the broken "save personal Schemes" 13 | # - added line-by-line explanations for EVERYTHING (some were missing) 14 | # 15 | # NB: if you are storing "built" products, this WILL NOT WORK, 16 | # and you should use a different .gitignore (or none at all) 17 | # This file is for SOURCE projects, where there are many extra 18 | # files that we want to exclude 19 | # 20 | ######################### 21 | 22 | ##### 23 | # OS X temporary files that should never be committed 24 | # 25 | # c.f. http://www.westwind.com/reference/os-x/invisibles.html 26 | 27 | .DS_Store 28 | 29 | # c.f. http://www.westwind.com/reference/os-x/invisibles.html 30 | 31 | .Trashes 32 | 33 | # c.f. http://www.westwind.com/reference/os-x/invisibles.html 34 | 35 | *.swp 36 | 37 | # *.lock - this is used and abused by many editors for many different things. 38 | # For the main ones I use (e.g. Eclipse), it should be excluded 39 | # from source-control, but YMMV 40 | 41 | *.lock 42 | 43 | # 44 | # profile - REMOVED temporarily (on double-checking, this seems incorrect; I can't find it in OS X docs?) 45 | #profile 46 | 47 | 48 | #### 49 | # Xcode temporary files that should never be committed 50 | # 51 | # NB: NIB/XIB files still exist even on Storyboard projects, so we want this... 52 | 53 | *~.nib 54 | 55 | 56 | #### 57 | # Xcode build files - 58 | # 59 | # NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "DerivedData" 60 | 61 | DerivedData/ 62 | 63 | # NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "build" 64 | 65 | build/ 66 | 67 | 68 | ##### 69 | # Xcode private settings (window sizes, bookmarks, breakpoints, custom executables, smart groups) 70 | # 71 | # This is complicated: 72 | # 73 | # SOMETIMES you need to put this file in version control. 74 | # Apple designed it poorly - if you use "custom executables", they are 75 | # saved in this file. 76 | # 99% of projects do NOT use those, so they do NOT want to version control this file. 77 | # ..but if you're in the 1%, comment out the line "*.pbxuser" 78 | 79 | # .pbxuser: http://lists.apple.com/archives/xcode-users/2004/Jan/msg00193.html 80 | 81 | *.pbxuser 82 | 83 | # .mode1v3: http://lists.apple.com/archives/xcode-users/2007/Oct/msg00465.html 84 | 85 | *.mode1v3 86 | 87 | # .mode2v3: http://lists.apple.com/archives/xcode-users/2007/Oct/msg00465.html 88 | 89 | *.mode2v3 90 | 91 | # .perspectivev3: http://stackoverflow.com/questions/5223297/xcode-projects-what-is-a-perspectivev3-file 92 | 93 | *.perspectivev3 94 | 95 | # NB: also, whitelist the default ones, some projects need to use these 96 | !default.pbxuser 97 | !default.mode1v3 98 | !default.mode2v3 99 | !default.perspectivev3 100 | 101 | 102 | #### 103 | # Xcode 4 - semi-personal settings 104 | # 105 | # 106 | # OPTION 1: --------------------------------- 107 | # throw away ALL personal settings (including custom schemes! 108 | # - unless they are "shared") 109 | # 110 | # NB: this is exclusive with OPTION 2 below 111 | xcuserdata 112 | 113 | # OPTION 2: --------------------------------- 114 | # get rid of ALL personal settings, but KEEP SOME OF THEM 115 | # - NB: you must manually uncomment the bits you want to keep 116 | # 117 | # NB: this *requires* git v1.8.2 or above; you may need to upgrade to latest OS X, 118 | # or manually install git over the top of the OS X version 119 | # NB: this is exclusive with OPTION 1 above 120 | # 121 | #xcuserdata/**/* 122 | 123 | # (requires option 2 above): Personal Schemes 124 | # 125 | #!xcuserdata/**/xcschemes/* 126 | 127 | #### 128 | # XCode 4 workspaces - more detailed 129 | # 130 | # Workspaces are important! They are a core feature of Xcode - don't exclude them :) 131 | # 132 | # Workspace layout is quite spammy. For reference: 133 | # 134 | # /(root)/ 135 | # /(project-name).xcodeproj/ 136 | # project.pbxproj 137 | # /project.xcworkspace/ 138 | # contents.xcworkspacedata 139 | # /xcuserdata/ 140 | # /(your name)/xcuserdatad/ 141 | # UserInterfaceState.xcuserstate 142 | # /xcsshareddata/ 143 | # /xcschemes/ 144 | # (shared scheme name).xcscheme 145 | # /xcuserdata/ 146 | # /(your name)/xcuserdatad/ 147 | # (private scheme).xcscheme 148 | # xcschememanagement.plist 149 | # 150 | # 151 | 152 | #### 153 | # Xcode 4 - Deprecated classes 154 | # 155 | # Allegedly, if you manually "deprecate" your classes, they get moved here. 156 | # 157 | # We're using source-control, so this is a "feature" that we do not want! 158 | 159 | *.moved-aside 160 | 161 | #### 162 | # UNKNOWN: recommended by others, but I can't discover what these files are 163 | # 164 | # ...none. Everything is now explained. 165 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Philip Woods 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 | ##Swift JSON## 2 | Swift JSON takes away the monotony of hand writing serialization code for JSON structures. Needs to be updated for the Swift 3 3 | -------------------------------------------------------------------------------- /SwiftJson.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 073B4B53196B7D5000A62AF4 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 073B4B52196B7D5000A62AF4 /* SwiftyJSON.swift */; }; 11 | 073B4B54196B7D5000A62AF4 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 073B4B52196B7D5000A62AF4 /* SwiftyJSON.swift */; }; 12 | 07859D7F194909F100D04588 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07859D7E194909F100D04588 /* main.swift */; }; 13 | 07859D81194909F100D04588 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07859D80194909F100D04588 /* ViewController.swift */; }; 14 | 07859D83194909F100D04588 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07859D82194909F100D04588 /* AppDelegate.swift */; }; 15 | 07859D85194909F100D04588 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 07859D84194909F100D04588 /* Images.xcassets */; }; 16 | 07859D94194909F100D04588 /* SwiftJsonTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07859D93194909F100D04588 /* SwiftJsonTests.swift */; }; 17 | 07859D9E19490A9A00D04588 /* ModelGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07859D9D19490A9A00D04588 /* ModelGenerator.swift */; }; 18 | 07859DA019490AAE00D04588 /* IndentableOutput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07859D9F19490AAE00D04588 /* IndentableOutput.swift */; }; 19 | 07859DA219491CD500D04588 /* MenuController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 07859DA119491CD500D04588 /* MenuController.swift */; }; 20 | 7E8A8D48194CB1790089D85D /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7E8A8D46194CB1790089D85D /* MainMenu.xib */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | 07859D8E194909F100D04588 /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 07859D71194909F000D04588 /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 07859D78194909F000D04588; 29 | remoteInfo = SwiftJson; 30 | }; 31 | /* End PBXContainerItemProxy section */ 32 | 33 | /* Begin PBXFileReference section */ 34 | 073B4B52196B7D5000A62AF4 /* SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSON.swift; sourceTree = ""; }; 35 | 07859D79194909F000D04588 /* SwiftJson.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftJson.app; sourceTree = BUILT_PRODUCTS_DIR; }; 36 | 07859D7D194909F100D04588 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 37 | 07859D7E194909F100D04588 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; 38 | 07859D80194909F100D04588 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 39 | 07859D82194909F100D04588 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 40 | 07859D84194909F100D04588 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 41 | 07859D8D194909F100D04588 /* SwiftJsonTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftJsonTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | 07859D92194909F100D04588 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 43 | 07859D93194909F100D04588 /* SwiftJsonTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftJsonTests.swift; sourceTree = ""; }; 44 | 07859D9D19490A9A00D04588 /* ModelGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ModelGenerator.swift; sourceTree = ""; }; 45 | 07859D9F19490AAE00D04588 /* IndentableOutput.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IndentableOutput.swift; sourceTree = ""; }; 46 | 07859DA119491CD500D04588 /* MenuController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuController.swift; sourceTree = ""; }; 47 | 7E8A8D47194CB1790089D85D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; 48 | /* End PBXFileReference section */ 49 | 50 | /* Begin PBXFrameworksBuildPhase section */ 51 | 07859D76194909F000D04588 /* Frameworks */ = { 52 | isa = PBXFrameworksBuildPhase; 53 | buildActionMask = 2147483647; 54 | files = ( 55 | ); 56 | runOnlyForDeploymentPostprocessing = 0; 57 | }; 58 | 07859D8A194909F100D04588 /* Frameworks */ = { 59 | isa = PBXFrameworksBuildPhase; 60 | buildActionMask = 2147483647; 61 | files = ( 62 | ); 63 | runOnlyForDeploymentPostprocessing = 0; 64 | }; 65 | /* End PBXFrameworksBuildPhase section */ 66 | 67 | /* Begin PBXGroup section */ 68 | 07859D70194909F000D04588 = { 69 | isa = PBXGroup; 70 | children = ( 71 | 07859D7B194909F000D04588 /* SwiftJson */, 72 | 07859D90194909F100D04588 /* SwiftJsonTests */, 73 | 07859D7A194909F000D04588 /* Products */, 74 | ); 75 | sourceTree = ""; 76 | }; 77 | 07859D7A194909F000D04588 /* Products */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | 07859D79194909F000D04588 /* SwiftJson.app */, 81 | 07859D8D194909F100D04588 /* SwiftJsonTests.xctest */, 82 | ); 83 | name = Products; 84 | sourceTree = ""; 85 | }; 86 | 07859D7B194909F000D04588 /* SwiftJson */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 073B4B52196B7D5000A62AF4 /* SwiftyJSON.swift */, 90 | 07859D80194909F100D04588 /* ViewController.swift */, 91 | 07859D82194909F100D04588 /* AppDelegate.swift */, 92 | 07859D84194909F100D04588 /* Images.xcassets */, 93 | 7E8A8D46194CB1790089D85D /* MainMenu.xib */, 94 | 07859D9D19490A9A00D04588 /* ModelGenerator.swift */, 95 | 07859D9F19490AAE00D04588 /* IndentableOutput.swift */, 96 | 07859DA119491CD500D04588 /* MenuController.swift */, 97 | 07859D7C194909F000D04588 /* Supporting Files */, 98 | ); 99 | path = SwiftJson; 100 | sourceTree = ""; 101 | }; 102 | 07859D7C194909F000D04588 /* Supporting Files */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | 07859D7D194909F100D04588 /* Info.plist */, 106 | 07859D7E194909F100D04588 /* main.swift */, 107 | ); 108 | name = "Supporting Files"; 109 | sourceTree = ""; 110 | }; 111 | 07859D90194909F100D04588 /* SwiftJsonTests */ = { 112 | isa = PBXGroup; 113 | children = ( 114 | 07859D93194909F100D04588 /* SwiftJsonTests.swift */, 115 | 07859D91194909F100D04588 /* Supporting Files */, 116 | ); 117 | path = SwiftJsonTests; 118 | sourceTree = ""; 119 | }; 120 | 07859D91194909F100D04588 /* Supporting Files */ = { 121 | isa = PBXGroup; 122 | children = ( 123 | 07859D92194909F100D04588 /* Info.plist */, 124 | ); 125 | name = "Supporting Files"; 126 | sourceTree = ""; 127 | }; 128 | /* End PBXGroup section */ 129 | 130 | /* Begin PBXNativeTarget section */ 131 | 07859D78194909F000D04588 /* SwiftJson */ = { 132 | isa = PBXNativeTarget; 133 | buildConfigurationList = 07859D97194909F100D04588 /* Build configuration list for PBXNativeTarget "SwiftJson" */; 134 | buildPhases = ( 135 | 07859D75194909F000D04588 /* Sources */, 136 | 07859D76194909F000D04588 /* Frameworks */, 137 | 07859D77194909F000D04588 /* Resources */, 138 | ); 139 | buildRules = ( 140 | ); 141 | dependencies = ( 142 | ); 143 | name = SwiftJson; 144 | productName = SwiftJson; 145 | productReference = 07859D79194909F000D04588 /* SwiftJson.app */; 146 | productType = "com.apple.product-type.application"; 147 | }; 148 | 07859D8C194909F100D04588 /* SwiftJsonTests */ = { 149 | isa = PBXNativeTarget; 150 | buildConfigurationList = 07859D9A194909F100D04588 /* Build configuration list for PBXNativeTarget "SwiftJsonTests" */; 151 | buildPhases = ( 152 | 07859D89194909F100D04588 /* Sources */, 153 | 07859D8A194909F100D04588 /* Frameworks */, 154 | 07859D8B194909F100D04588 /* Resources */, 155 | ); 156 | buildRules = ( 157 | ); 158 | dependencies = ( 159 | 07859D8F194909F100D04588 /* PBXTargetDependency */, 160 | ); 161 | name = SwiftJsonTests; 162 | productName = SwiftJsonTests; 163 | productReference = 07859D8D194909F100D04588 /* SwiftJsonTests.xctest */; 164 | productType = "com.apple.product-type.bundle.unit-test"; 165 | }; 166 | /* End PBXNativeTarget section */ 167 | 168 | /* Begin PBXProject section */ 169 | 07859D71194909F000D04588 /* Project object */ = { 170 | isa = PBXProject; 171 | attributes = { 172 | LastUpgradeCheck = 0600; 173 | ORGANIZATIONNAME = pvwoods; 174 | TargetAttributes = { 175 | 07859D78194909F000D04588 = { 176 | CreatedOnToolsVersion = 6.0; 177 | }; 178 | 07859D8C194909F100D04588 = { 179 | CreatedOnToolsVersion = 6.0; 180 | TestTargetID = 07859D78194909F000D04588; 181 | }; 182 | }; 183 | }; 184 | buildConfigurationList = 07859D74194909F000D04588 /* Build configuration list for PBXProject "SwiftJson" */; 185 | compatibilityVersion = "Xcode 3.2"; 186 | developmentRegion = English; 187 | hasScannedForEncodings = 0; 188 | knownRegions = ( 189 | en, 190 | Base, 191 | ); 192 | mainGroup = 07859D70194909F000D04588; 193 | productRefGroup = 07859D7A194909F000D04588 /* Products */; 194 | projectDirPath = ""; 195 | projectRoot = ""; 196 | targets = ( 197 | 07859D78194909F000D04588 /* SwiftJson */, 198 | 07859D8C194909F100D04588 /* SwiftJsonTests */, 199 | ); 200 | }; 201 | /* End PBXProject section */ 202 | 203 | /* Begin PBXResourcesBuildPhase section */ 204 | 07859D77194909F000D04588 /* Resources */ = { 205 | isa = PBXResourcesBuildPhase; 206 | buildActionMask = 2147483647; 207 | files = ( 208 | 07859D85194909F100D04588 /* Images.xcassets in Resources */, 209 | 7E8A8D48194CB1790089D85D /* MainMenu.xib in Resources */, 210 | ); 211 | runOnlyForDeploymentPostprocessing = 0; 212 | }; 213 | 07859D8B194909F100D04588 /* Resources */ = { 214 | isa = PBXResourcesBuildPhase; 215 | buildActionMask = 2147483647; 216 | files = ( 217 | ); 218 | runOnlyForDeploymentPostprocessing = 0; 219 | }; 220 | /* End PBXResourcesBuildPhase section */ 221 | 222 | /* Begin PBXSourcesBuildPhase section */ 223 | 07859D75194909F000D04588 /* Sources */ = { 224 | isa = PBXSourcesBuildPhase; 225 | buildActionMask = 2147483647; 226 | files = ( 227 | 07859D83194909F100D04588 /* AppDelegate.swift in Sources */, 228 | 07859D81194909F100D04588 /* ViewController.swift in Sources */, 229 | 07859D7F194909F100D04588 /* main.swift in Sources */, 230 | 07859DA019490AAE00D04588 /* IndentableOutput.swift in Sources */, 231 | 07859DA219491CD500D04588 /* MenuController.swift in Sources */, 232 | 073B4B53196B7D5000A62AF4 /* SwiftyJSON.swift in Sources */, 233 | 07859D9E19490A9A00D04588 /* ModelGenerator.swift in Sources */, 234 | ); 235 | runOnlyForDeploymentPostprocessing = 0; 236 | }; 237 | 07859D89194909F100D04588 /* Sources */ = { 238 | isa = PBXSourcesBuildPhase; 239 | buildActionMask = 2147483647; 240 | files = ( 241 | 07859D94194909F100D04588 /* SwiftJsonTests.swift in Sources */, 242 | 073B4B54196B7D5000A62AF4 /* SwiftyJSON.swift in Sources */, 243 | ); 244 | runOnlyForDeploymentPostprocessing = 0; 245 | }; 246 | /* End PBXSourcesBuildPhase section */ 247 | 248 | /* Begin PBXTargetDependency section */ 249 | 07859D8F194909F100D04588 /* PBXTargetDependency */ = { 250 | isa = PBXTargetDependency; 251 | target = 07859D78194909F000D04588 /* SwiftJson */; 252 | targetProxy = 07859D8E194909F100D04588 /* PBXContainerItemProxy */; 253 | }; 254 | /* End PBXTargetDependency section */ 255 | 256 | /* Begin PBXVariantGroup section */ 257 | 7E8A8D46194CB1790089D85D /* MainMenu.xib */ = { 258 | isa = PBXVariantGroup; 259 | children = ( 260 | 7E8A8D47194CB1790089D85D /* Base */, 261 | ); 262 | name = MainMenu.xib; 263 | sourceTree = ""; 264 | }; 265 | /* End PBXVariantGroup section */ 266 | 267 | /* Begin XCBuildConfiguration section */ 268 | 07859D95194909F100D04588 /* Debug */ = { 269 | isa = XCBuildConfiguration; 270 | buildSettings = { 271 | ALWAYS_SEARCH_USER_PATHS = NO; 272 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 273 | CLANG_CXX_LIBRARY = "libc++"; 274 | CLANG_ENABLE_MODULES = YES; 275 | CLANG_ENABLE_OBJC_ARC = YES; 276 | CLANG_WARN_BOOL_CONVERSION = YES; 277 | CLANG_WARN_CONSTANT_CONVERSION = YES; 278 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 279 | CLANG_WARN_EMPTY_BODY = YES; 280 | CLANG_WARN_ENUM_CONVERSION = YES; 281 | CLANG_WARN_INT_CONVERSION = YES; 282 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 283 | CLANG_WARN_UNREACHABLE_CODE = YES; 284 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 285 | CODE_SIGN_IDENTITY = "-"; 286 | COPY_PHASE_STRIP = NO; 287 | ENABLE_STRICT_OBJC_MSGSEND = YES; 288 | GCC_C_LANGUAGE_STANDARD = gnu99; 289 | GCC_DYNAMIC_NO_PIC = NO; 290 | GCC_OPTIMIZATION_LEVEL = 0; 291 | GCC_PREPROCESSOR_DEFINITIONS = ( 292 | "DEBUG=1", 293 | "$(inherited)", 294 | ); 295 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 296 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 297 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 298 | GCC_WARN_UNDECLARED_SELECTOR = YES; 299 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 300 | GCC_WARN_UNUSED_FUNCTION = YES; 301 | GCC_WARN_UNUSED_VARIABLE = YES; 302 | MACOSX_DEPLOYMENT_TARGET = 10.9; 303 | METAL_ENABLE_DEBUG_INFO = YES; 304 | ONLY_ACTIVE_ARCH = YES; 305 | SDKROOT = macosx; 306 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 307 | }; 308 | name = Debug; 309 | }; 310 | 07859D96194909F100D04588 /* Release */ = { 311 | isa = XCBuildConfiguration; 312 | buildSettings = { 313 | ALWAYS_SEARCH_USER_PATHS = NO; 314 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 315 | CLANG_CXX_LIBRARY = "libc++"; 316 | CLANG_ENABLE_MODULES = YES; 317 | CLANG_ENABLE_OBJC_ARC = YES; 318 | CLANG_WARN_BOOL_CONVERSION = YES; 319 | CLANG_WARN_CONSTANT_CONVERSION = YES; 320 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 321 | CLANG_WARN_EMPTY_BODY = YES; 322 | CLANG_WARN_ENUM_CONVERSION = YES; 323 | CLANG_WARN_INT_CONVERSION = YES; 324 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 325 | CLANG_WARN_UNREACHABLE_CODE = YES; 326 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 327 | CODE_SIGN_IDENTITY = "-"; 328 | COPY_PHASE_STRIP = YES; 329 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 330 | ENABLE_NS_ASSERTIONS = NO; 331 | ENABLE_STRICT_OBJC_MSGSEND = YES; 332 | GCC_C_LANGUAGE_STANDARD = gnu99; 333 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 334 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 335 | GCC_WARN_UNDECLARED_SELECTOR = YES; 336 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 337 | GCC_WARN_UNUSED_FUNCTION = YES; 338 | GCC_WARN_UNUSED_VARIABLE = YES; 339 | MACOSX_DEPLOYMENT_TARGET = 10.9; 340 | METAL_ENABLE_DEBUG_INFO = NO; 341 | SDKROOT = macosx; 342 | }; 343 | name = Release; 344 | }; 345 | 07859D98194909F100D04588 /* Debug */ = { 346 | isa = XCBuildConfiguration; 347 | buildSettings = { 348 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 349 | COMBINE_HIDPI_IMAGES = YES; 350 | INFOPLIST_FILE = SwiftJson/Info.plist; 351 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 352 | MACOSX_DEPLOYMENT_TARGET = 10.9; 353 | PRODUCT_NAME = "$(TARGET_NAME)"; 354 | }; 355 | name = Debug; 356 | }; 357 | 07859D99194909F100D04588 /* Release */ = { 358 | isa = XCBuildConfiguration; 359 | buildSettings = { 360 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 361 | COMBINE_HIDPI_IMAGES = YES; 362 | INFOPLIST_FILE = SwiftJson/Info.plist; 363 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 364 | MACOSX_DEPLOYMENT_TARGET = 10.9; 365 | PRODUCT_NAME = "$(TARGET_NAME)"; 366 | }; 367 | name = Release; 368 | }; 369 | 07859D9B194909F100D04588 /* Debug */ = { 370 | isa = XCBuildConfiguration; 371 | buildSettings = { 372 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/SwiftJson.app/Contents/MacOS/SwiftJson"; 373 | COMBINE_HIDPI_IMAGES = YES; 374 | FRAMEWORK_SEARCH_PATHS = ( 375 | "$(DEVELOPER_FRAMEWORKS_DIR)", 376 | "$(inherited)", 377 | ); 378 | GCC_PREPROCESSOR_DEFINITIONS = ( 379 | "DEBUG=1", 380 | "$(inherited)", 381 | ); 382 | INFOPLIST_FILE = SwiftJsonTests/Info.plist; 383 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 384 | METAL_ENABLE_DEBUG_INFO = YES; 385 | PRODUCT_NAME = "$(TARGET_NAME)"; 386 | TEST_HOST = "$(BUNDLE_LOADER)"; 387 | }; 388 | name = Debug; 389 | }; 390 | 07859D9C194909F100D04588 /* Release */ = { 391 | isa = XCBuildConfiguration; 392 | buildSettings = { 393 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/SwiftJson.app/Contents/MacOS/SwiftJson"; 394 | COMBINE_HIDPI_IMAGES = YES; 395 | FRAMEWORK_SEARCH_PATHS = ( 396 | "$(DEVELOPER_FRAMEWORKS_DIR)", 397 | "$(inherited)", 398 | ); 399 | INFOPLIST_FILE = SwiftJsonTests/Info.plist; 400 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; 401 | METAL_ENABLE_DEBUG_INFO = NO; 402 | PRODUCT_NAME = "$(TARGET_NAME)"; 403 | TEST_HOST = "$(BUNDLE_LOADER)"; 404 | }; 405 | name = Release; 406 | }; 407 | /* End XCBuildConfiguration section */ 408 | 409 | /* Begin XCConfigurationList section */ 410 | 07859D74194909F000D04588 /* Build configuration list for PBXProject "SwiftJson" */ = { 411 | isa = XCConfigurationList; 412 | buildConfigurations = ( 413 | 07859D95194909F100D04588 /* Debug */, 414 | 07859D96194909F100D04588 /* Release */, 415 | ); 416 | defaultConfigurationIsVisible = 0; 417 | defaultConfigurationName = Release; 418 | }; 419 | 07859D97194909F100D04588 /* Build configuration list for PBXNativeTarget "SwiftJson" */ = { 420 | isa = XCConfigurationList; 421 | buildConfigurations = ( 422 | 07859D98194909F100D04588 /* Debug */, 423 | 07859D99194909F100D04588 /* Release */, 424 | ); 425 | defaultConfigurationIsVisible = 0; 426 | defaultConfigurationName = Release; 427 | }; 428 | 07859D9A194909F100D04588 /* Build configuration list for PBXNativeTarget "SwiftJsonTests" */ = { 429 | isa = XCConfigurationList; 430 | buildConfigurations = ( 431 | 07859D9B194909F100D04588 /* Debug */, 432 | 07859D9C194909F100D04588 /* Release */, 433 | ); 434 | defaultConfigurationIsVisible = 0; 435 | defaultConfigurationName = Release; 436 | }; 437 | /* End XCConfigurationList section */ 438 | }; 439 | rootObject = 07859D71194909F000D04588 /* Project object */; 440 | } 441 | -------------------------------------------------------------------------------- /SwiftJson.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SwiftJson.xcodeproj/project.xcworkspace/xcshareddata/SwiftJson.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | E1D7F84A-E66D-4F58-8870-22A55ED624A7 9 | IDESourceControlProjectName 10 | SwiftJson 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 957C2411939784F97902D82EAC722A5A882F3E35 14 | https://github.com/swiftjson/SwiftJson 15 | 16 | IDESourceControlProjectPath 17 | SwiftJson.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 957C2411939784F97902D82EAC722A5A882F3E35 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/swiftjson/SwiftJson 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | 957C2411939784F97902D82EAC722A5A882F3E35 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 957C2411939784F97902D82EAC722A5A882F3E35 36 | IDESourceControlWCCName 37 | SwiftJson 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /SwiftJson/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SwiftJson 4 | // 5 | // Created by Philip Woods on 6/11/14. 6 | // Copyright (c) 2014 pvwoods. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | class AppDelegate: NSObject, NSApplicationDelegate { 12 | 13 | 14 | 15 | func applicationDidFinishLaunching(aNotification: NSNotification?) { 16 | // Insert code here to initialize your application 17 | } 18 | 19 | func applicationWillTerminate(aNotification: NSNotification?) { 20 | // Insert code here to tear down your application 21 | } 22 | 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /SwiftJson/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 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 88 | 89 | 90 | 91 | 92 | 93 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | Default 658 | 659 | 660 | 661 | 662 | 663 | 664 | Left to Right 665 | 666 | 667 | 668 | 669 | 670 | 671 | Right to Left 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | Default 683 | 684 | 685 | 686 | 687 | 688 | 689 | Left to Right 690 | 691 | 692 | 693 | 694 | 695 | 696 | Right to Left 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | -------------------------------------------------------------------------------- /SwiftJson/Base.lproj/MainMenu.xib: -------------------------------------------------------------------------------- 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 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 413 | 414 | 415 | 416 | 417 | 418 | 425 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | -------------------------------------------------------------------------------- /SwiftJson/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "sjLogo16.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "16x16", 11 | "idiom" : "mac", 12 | "filename" : "sjLogo32-1.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "32x32", 17 | "idiom" : "mac", 18 | "filename" : "sjLogo32.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "32x32", 23 | "idiom" : "mac", 24 | "filename" : "sjLogo64.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "128x128", 29 | "idiom" : "mac", 30 | "filename" : "sjLogo128.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "128x128", 35 | "idiom" : "mac", 36 | "filename" : "sjLogo256-1.png", 37 | "scale" : "2x" 38 | }, 39 | { 40 | "size" : "256x256", 41 | "idiom" : "mac", 42 | "filename" : "sjLogo256.png", 43 | "scale" : "1x" 44 | }, 45 | { 46 | "size" : "256x256", 47 | "idiom" : "mac", 48 | "filename" : "sjLogo512-1.png", 49 | "scale" : "2x" 50 | }, 51 | { 52 | "size" : "512x512", 53 | "idiom" : "mac", 54 | "filename" : "sjLogo512.png", 55 | "scale" : "1x" 56 | }, 57 | { 58 | "size" : "512x512", 59 | "idiom" : "mac", 60 | "filename" : "sjLogo1024.png", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiftjson/SwiftJson/9a78dd94e3a23233d8c6c75ba3fb32a2a5bb3166/SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo1024.png -------------------------------------------------------------------------------- /SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiftjson/SwiftJson/9a78dd94e3a23233d8c6c75ba3fb32a2a5bb3166/SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo128.png -------------------------------------------------------------------------------- /SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiftjson/SwiftJson/9a78dd94e3a23233d8c6c75ba3fb32a2a5bb3166/SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo16.png -------------------------------------------------------------------------------- /SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo256-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiftjson/SwiftJson/9a78dd94e3a23233d8c6c75ba3fb32a2a5bb3166/SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo256-1.png -------------------------------------------------------------------------------- /SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiftjson/SwiftJson/9a78dd94e3a23233d8c6c75ba3fb32a2a5bb3166/SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo256.png -------------------------------------------------------------------------------- /SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo32-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiftjson/SwiftJson/9a78dd94e3a23233d8c6c75ba3fb32a2a5bb3166/SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo32-1.png -------------------------------------------------------------------------------- /SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiftjson/SwiftJson/9a78dd94e3a23233d8c6c75ba3fb32a2a5bb3166/SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo32.png -------------------------------------------------------------------------------- /SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo512-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiftjson/SwiftJson/9a78dd94e3a23233d8c6c75ba3fb32a2a5bb3166/SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo512-1.png -------------------------------------------------------------------------------- /SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiftjson/SwiftJson/9a78dd94e3a23233d8c6c75ba3fb32a2a5bb3166/SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo512.png -------------------------------------------------------------------------------- /SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiftjson/SwiftJson/9a78dd94e3a23233d8c6c75ba3fb32a2a5bb3166/SwiftJson/Images.xcassets/AppIcon.appiconset/sjLogo64.png -------------------------------------------------------------------------------- /SwiftJson/IndentableOutput.swift: -------------------------------------------------------------------------------- 1 | // 2 | // IndentableOutput.swift 3 | // swiftin 4 | // 5 | // Created by Philip Woods on 6/11/14. 6 | // Copyright (c) 2014 pvwoods. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | enum OutputInstructionType:Int { 12 | case Indent 13 | case PrintLine 14 | } 15 | 16 | struct OutputInstruction { 17 | var type:OutputInstructionType 18 | var data:AnyObject 19 | 20 | init(iType:OutputInstructionType, iData:AnyObject) { 21 | self.type = iType 22 | self.data = iData 23 | } 24 | } 25 | 26 | class IndentableOutput { 27 | 28 | let spacesPerIndent:Int = 4 29 | 30 | var _indentation:Int = 0 31 | var indentation:Int { 32 | get { 33 | return _indentation 34 | } 35 | set { 36 | let i:Int = newValue - _indentation; 37 | _indentation = newValue 38 | rawOutput.append(OutputInstruction(iType: OutputInstructionType.Indent, iData: i)) 39 | } 40 | } 41 | var tabs:String { 42 | get { 43 | return " " * (indentation * spacesPerIndent) 44 | } 45 | } 46 | 47 | var output:String = "" 48 | var rawOutput:[OutputInstruction] = [] 49 | 50 | func addLineToOutput(l:String) -> IndentableOutput { 51 | rawOutput.append(OutputInstruction(iType: OutputInstructionType.PrintLine, iData: l)) 52 | output += tabs + l + "\n" 53 | return self 54 | } 55 | 56 | func indent() -> IndentableOutput { 57 | self.indentation++ 58 | return self 59 | } 60 | 61 | func dedent() -> IndentableOutput { 62 | self.indentation-- 63 | return self 64 | } 65 | 66 | } 67 | 68 | func + (left:IndentableOutput, right:IndentableOutput) -> IndentableOutput { 69 | 70 | for instruction in right.rawOutput { 71 | switch instruction.type { 72 | case OutputInstructionType.Indent: 73 | left.indentation += instruction.data as! Int 74 | case OutputInstructionType.PrintLine: 75 | left.addLineToOutput(instruction.data as! String) 76 | } 77 | } 78 | 79 | return left 80 | } 81 | 82 | func += (left:IndentableOutput, right:IndentableOutput) -> IndentableOutput { 83 | return left + right 84 | } 85 | 86 | func + (left:IndentableOutput, right:String) -> IndentableOutput { 87 | left.addLineToOutput(right) 88 | return left 89 | } 90 | 91 | func += (left:IndentableOutput, right:String) -> IndentableOutput { 92 | left.addLineToOutput(right) 93 | return left 94 | } 95 | 96 | func += (left:IndentableOutput, right:[IndentableOutput]) -> IndentableOutput { 97 | for io in right { 98 | left += io 99 | } 100 | return left 101 | } 102 | 103 | func * (left: String, right: Int) -> String { 104 | var output = left 105 | for i in 0...right { 106 | output += left 107 | } 108 | return output 109 | } 110 | -------------------------------------------------------------------------------- /SwiftJson/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.pvwoods.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0.1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSHumanReadableCopyright 28 | Copyright © 2014 pvwoods. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /SwiftJson/MenuController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MenuController.swift 3 | // SwiftJson 4 | // 5 | // Created by Philip Woods on 6/11/14. 6 | // Copyright (c) 2014 pvwoods. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Cocoa 11 | 12 | class MenuController : NSMenu { 13 | 14 | @IBAction func onSelectGenerate(e:NSEvent) { 15 | NSNotificationCenter.defaultCenter().postNotificationName("SELECTED_GENERATE", object: nil) 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /SwiftJson/ModelGenerator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ModelGenerator.swift 3 | // swiftin 4 | // 5 | // Created by Philip Woods on 6/11/14. 6 | // Copyright (c) 2014 pvwoods. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | import Cocoa 12 | 13 | 14 | class ModelGenerator { 15 | 16 | var modelOutput:IndentableOutput = IndentableOutput() 17 | var childModels:[ModelGenerator] = [] 18 | 19 | var output:String { 20 | get { 21 | return modelOutput.output 22 | } 23 | } 24 | 25 | init(json:JSON, className:String, inspectArrays:Bool) { 26 | 27 | // set up the init function 28 | var initOutput:IndentableOutput = IndentableOutput() 29 | (initOutput += "init(json:JSON) {").indent() 30 | 31 | // model set up 32 | (modelOutput += "class \(className) {").indent() 33 | 34 | // generate everything 35 | 36 | if let array = json.array { 37 | initOutput += "// initial element was array..." 38 | } 39 | else if let object = json.dictionary { 40 | for (key, value) in object { 41 | 42 | var type = "" 43 | 44 | var js : JSON = value as JSON 45 | 46 | if let val = js.string { 47 | type = "String" 48 | buildSetStatement(initOutput, key: key, type: type) 49 | } else if let val = js.number { 50 | type = "NSNumber" 51 | buildSetStatement(initOutput, key: key, type: type) 52 | } else if let val = js.bool { 53 | type = "Bool" 54 | buildSetStatement(initOutput, key: key, type: type) 55 | } else if let array = js.array { 56 | if(inspectArrays && array.count >= 1) { 57 | type = handleArray(array, key: key, className: className, inspectArrays: inspectArrays, io: initOutput) 58 | } else { 59 | initOutput += "\(key) = json[\"\(key)\"]" 60 | } 61 | } else if let object = (value as? JSON)?.object { 62 | var cn = self.buildClassName(className, suffix: key as String) 63 | childModels.append(ModelGenerator(json: value, className: cn, inspectArrays:inspectArrays)) 64 | type = cn 65 | initOutput += "\(key) = \(type)(json:json[\"\(key)\"])" 66 | 67 | } else { 68 | type = "AnyObject" 69 | } 70 | 71 | modelOutput += "var \(key):\(type)" 72 | } 73 | } 74 | 75 | 76 | // merge the init function and close everything up 77 | modelOutput += initOutput 78 | 79 | // close everything up 80 | (modelOutput.dedent() += "}").dedent() += "}" 81 | 82 | // append any child models 83 | for child in childModels { 84 | self.modelOutput += child.modelOutput 85 | } 86 | 87 | } 88 | 89 | func handleArray(array:Array, key:String, className:String, inspectArrays:Bool, io:IndentableOutput) -> String { 90 | 91 | var instantiation = "v" 92 | var type = "[AnyObject]" 93 | 94 | var js = (array[0] as JSON); 95 | 96 | if let val = js.string { 97 | type = "String" 98 | 99 | } else if let val = js.number { 100 | type = "NSNumber" 101 | 102 | } else if let val = js.bool { 103 | type = "Bool" 104 | } else if let array = js.array { 105 | type = "[JSON]" 106 | } else if let object = (array[0] as? JSON)?.object { 107 | var cn = buildClassName(className, suffix: key as String) 108 | childModels.append(ModelGenerator(json: array[0], className: cn, inspectArrays:inspectArrays)) 109 | type = "[" + cn + "]" 110 | instantiation = "\(cn)(json:v)" 111 | } else { 112 | type = "AnyObject" 113 | } 114 | 115 | io += "\(key) = []" 116 | (io += "if let xs = json[\"\(key)\"].array {").indent() 117 | (io += "for v in xs {").indent() 118 | (io += "\(key).append(\(instantiation))").dedent() + "}" 119 | io.dedent() += "}" 120 | 121 | return type 122 | } 123 | 124 | func buildSetStatement(io:IndentableOutput, key:String, type:String) { 125 | 126 | let optionTypeMap : [String: String] = [ 127 | "Bool": "bool", 128 | "NSNumber": "number", 129 | "String": "string" 130 | ] 131 | 132 | let optionDefaultValueMap : [String : String] = [ 133 | "Bool": "false", 134 | "NSNumber": "0", 135 | "String": "\"\"" 136 | ] 137 | 138 | let typeMap : String = (optionTypeMap[type] as! String?)!; 139 | let defaultValueMap : String = (optionDefaultValueMap[type] as! String?)!; 140 | 141 | 142 | (io += "if let value = json[\"\(key)\"].\(typeMap) {").indent() 143 | 144 | (((io += "\(key) = value").dedent()) += "} else {").indent() 145 | 146 | (io += "\(key) = \(defaultValueMap)").dedent() += "}" 147 | 148 | } 149 | 150 | func buildClassName(className:String, suffix:String) -> String { 151 | let index: String.Index = advance(suffix.startIndex, 1) 152 | var firstChar = (suffix as NSString).uppercaseString.substringToIndex(index) 153 | return className + firstChar + (suffix as NSString).substringFromIndex(1) 154 | } 155 | 156 | } 157 | -------------------------------------------------------------------------------- /SwiftJson/SwiftyJSON.swift: -------------------------------------------------------------------------------- 1 | // SwiftyJSON.swift 2 | // 3 | // Copyright (c) 2014 Ruoyu Fu, Pinglin Tang 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy 6 | // of this software and associated documentation files (the "Software"), to deal 7 | // in the Software without restriction, including without limitation the rights 8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | // copies of the Software, and to permit persons to whom the Software is 10 | // furnished to do so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in 13 | // all copies or substantial portions of the Software. 14 | // 15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | // THE SOFTWARE. 22 | 23 | import Foundation 24 | 25 | // MARK: - Error 26 | 27 | ///Error domain 28 | public let ErrorDomain: String! = "SwiftyJSONErrorDomain" 29 | 30 | ///Error code 31 | public let ErrorUnsupportedType: Int! = 999 32 | public let ErrorIndexOutOfBounds: Int! = 900 33 | public let ErrorWrongType: Int! = 901 34 | public let ErrorNotExist: Int! = 500 35 | 36 | // MARK: - JSON Type 37 | 38 | /** 39 | JSON's type definitions. 40 | 41 | See http://tools.ietf.org/html/rfc7231#section-4.3 42 | */ 43 | public enum Type :Int{ 44 | 45 | case Number 46 | case String 47 | case Bool 48 | case Array 49 | case Dictionary 50 | case Null 51 | case Unknown 52 | } 53 | 54 | // MARK: - JSON Base 55 | 56 | public struct JSON { 57 | 58 | /** 59 | Creates a JSON using the data. 60 | 61 | :param: data The NSData used to convert to json.Top level object in data is an NSArray or NSDictionary 62 | :param: opt The JSON serialization reading options. `.AllowFragments` by default. 63 | :param: error error The NSErrorPointer used to return the error. `nil` by default. 64 | 65 | :returns: The created JSON 66 | */ 67 | public init(data:NSData, options opt: NSJSONReadingOptions = .AllowFragments, error: NSErrorPointer = nil) { 68 | if let object: AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: opt, error: error) { 69 | self.init(object) 70 | } else { 71 | self.init(NSNull()) 72 | } 73 | } 74 | 75 | /** 76 | Creates a JSON using the object. 77 | 78 | :param: object The object must have the following properties: All objects are NSString/String, NSNumber/Int/Float/Double/Bool, NSArray/Array, NSDictionary/Dictionary, or NSNull; All dictionary keys are NSStrings/String; NSNumbers are not NaN or infinity. 79 | 80 | :returns: The created JSON 81 | */ 82 | public init(_ object: AnyObject) { 83 | self.object = object 84 | } 85 | 86 | /// Private object 87 | private var _object: AnyObject = NSNull() 88 | /// Private type 89 | private var _type: Type = .Null 90 | /// prviate error 91 | private var _error: NSError? 92 | 93 | /// Object in JSON 94 | public var object: AnyObject { 95 | get { 96 | return _object 97 | } 98 | set { 99 | _object = newValue 100 | switch newValue { 101 | case let number as NSNumber: 102 | if number.isBool { 103 | _type = .Bool 104 | } else { 105 | _type = .Number 106 | } 107 | case let string as NSString: 108 | _type = .String 109 | case let null as NSNull: 110 | _type = .Null 111 | case let array as [AnyObject]: 112 | _type = .Array 113 | case let dictionary as [String : AnyObject]: 114 | _type = .Dictionary 115 | default: 116 | _type = .Unknown 117 | _object = NSNull() 118 | _error = NSError(domain: ErrorDomain, code: ErrorUnsupportedType, userInfo: [NSLocalizedDescriptionKey: "It is a unsupported type"]) 119 | } 120 | } 121 | } 122 | 123 | /// json type 124 | public var type: Type { get { return _type } } 125 | 126 | /// Error in JSON 127 | public var error: NSError? { get { return self._error } } 128 | 129 | /// The static null json 130 | public static var nullJSON: JSON { get { return JSON(NSNull()) } } 131 | 132 | } 133 | 134 | // MARK: - SequenceType 135 | extension JSON: SequenceType{ 136 | 137 | /// If `type` is `.Array` or `.Dictionary`, return `array.empty` or `dictonary.empty` otherwise return `false`. 138 | public var isEmpty: Bool { 139 | get { 140 | switch self.type { 141 | case .Array: 142 | return (self.object as! [AnyObject]).isEmpty 143 | case .Dictionary: 144 | return (self.object as! [String : AnyObject]).isEmpty 145 | default: 146 | return false 147 | } 148 | } 149 | } 150 | 151 | /// If `type` is `.Array` or `.Dictionary`, return `array.count` or `dictonary.count` otherwise return `0`. 152 | public var count: Int { 153 | get { 154 | switch self.type { 155 | case .Array: 156 | return self.arrayValue.count 157 | case .Dictionary: 158 | return self.dictionaryValue.count 159 | default: 160 | return 0 161 | } 162 | } 163 | } 164 | 165 | /** 166 | If `type` is `.Array` or `.Dictionary`, return a generator over the elements like `Array` or `Dictionary`, otherwise return a generator over empty. 167 | 168 | :returns: Return a *generator* over the elements of this *sequence*. 169 | */ 170 | public func generate() -> GeneratorOf <(String, JSON)> { 171 | switch self.type { 172 | case .Array: 173 | let array_ = object as! [AnyObject] 174 | var generate_ = array_.generate() 175 | var index_: Int = 0 176 | return GeneratorOf<(String, JSON)> { 177 | if let element_: AnyObject = generate_.next() { 178 | return ("\(index_++)", JSON(element_)) 179 | } else { 180 | return nil 181 | } 182 | } 183 | case .Dictionary: 184 | let dictionary_ = object as! [String : AnyObject] 185 | var generate_ = dictionary_.generate() 186 | return GeneratorOf<(String, JSON)> { 187 | if let (key_: String, value_: AnyObject) = generate_.next() { 188 | return (key_, JSON(value_)) 189 | } else { 190 | return nil 191 | } 192 | } 193 | default: 194 | return GeneratorOf<(String, JSON)> { 195 | return nil 196 | } 197 | } 198 | } 199 | } 200 | 201 | // MARK: - Subscript 202 | 203 | /** 204 | * To mark both String and Int can be used in subscript. 205 | */ 206 | public protocol SubscriptType {} 207 | 208 | extension Int: SubscriptType {} 209 | 210 | extension String: SubscriptType {} 211 | 212 | extension JSON { 213 | 214 | /// If `type` is `.Array`, return json which's object is `array[index]`, otherwise return null json with error. 215 | private subscript(#index: Int) -> JSON { 216 | get { 217 | 218 | if self.type != .Array { 219 | var errorResult_ = JSON.nullJSON 220 | errorResult_._error = self._error ?? NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] failure, It is not an array"]) 221 | return errorResult_ 222 | } 223 | 224 | let array_ = self.object as! [AnyObject] 225 | 226 | if index >= 0 && index < array_.count { 227 | return JSON(array_[index]) 228 | } 229 | 230 | var errorResult_ = JSON.nullJSON 231 | errorResult_._error = NSError(domain: ErrorDomain, code:ErrorIndexOutOfBounds , userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] is out of bounds"]) 232 | return errorResult_ 233 | } 234 | set { 235 | if self.type == .Array { 236 | var array_ = self.object as! [AnyObject] 237 | if array_.count > index { 238 | array_[index] = newValue.object 239 | self.object = array_ 240 | } 241 | } 242 | } 243 | } 244 | 245 | /// If `type` is `.Dictionary`, return json which's object is `dictionary[key]` , otherwise return null json with error. 246 | private subscript(#key: String) -> JSON { 247 | get { 248 | var returnJSON = JSON.nullJSON 249 | if self.type == .Dictionary { 250 | if let object_: AnyObject = self.object[key] { 251 | returnJSON = JSON(object_) 252 | } else { 253 | returnJSON._error = NSError(domain: ErrorDomain, code: ErrorNotExist, userInfo: [NSLocalizedDescriptionKey: "Dictionary[\"\(key)\"] does not exist"]) 254 | } 255 | } else { 256 | returnJSON._error = self._error ?? NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Dictionary[\"\(key)\"] failure, It is not an dictionary"]) 257 | } 258 | return returnJSON 259 | } 260 | set { 261 | if self.type == .Dictionary { 262 | var dictionary_ = self.object as! [String : AnyObject] 263 | dictionary_[key] = newValue.object 264 | self.object = dictionary_ 265 | } 266 | } 267 | } 268 | 269 | /// If `sub` is `Int`, return `subscript(index:)`; If `sub` is `String`, return `subscript(key:)`. 270 | private subscript(#sub: SubscriptType) -> JSON { 271 | get { 272 | if sub is String { 273 | return self[key:sub as! String] 274 | } else { 275 | return self[index:sub as! Int] 276 | } 277 | } 278 | set { 279 | if sub is String { 280 | self[key:sub as! String] = newValue 281 | } else { 282 | self[index:sub as! Int] = newValue 283 | } 284 | } 285 | } 286 | 287 | /** 288 | Find a json in the complex data structuresby using the Int/String's array. 289 | 290 | :param: path The target json's path. Example: 291 | 292 | let json = JSON[data] 293 | let path = [9,"list","person","name"] 294 | let name = json[path] 295 | 296 | The same as: let name = json[9]["list"]["person"]["name"] 297 | 298 | :returns: Return a json found by the path or a null json with error 299 | */ 300 | public subscript(path: [SubscriptType]) -> JSON { 301 | get { 302 | if path.count == 0 { 303 | return JSON.nullJSON 304 | } 305 | 306 | var next = self 307 | for sub in path { 308 | next = next[sub:sub] 309 | } 310 | return next 311 | } 312 | set { 313 | 314 | switch path.count { 315 | case 0: return 316 | case 1: self[sub:path[0]] = newValue 317 | default: 318 | var last = newValue 319 | var newPath = path 320 | newPath.removeLast() 321 | for sub in path.reverse() { 322 | var previousLast = self[newPath] 323 | previousLast[sub:sub] = last 324 | last = previousLast 325 | if newPath.count <= 1 { 326 | break 327 | } 328 | newPath.removeLast() 329 | } 330 | self[sub:newPath[0]] = last 331 | } 332 | } 333 | } 334 | 335 | /** 336 | Find a json in the complex data structuresby using the Int/String's array. 337 | 338 | :param: path The target json's path. Example: 339 | 340 | let name = json[9,"list","person","name"] 341 | 342 | The same as: let name = json[9]["list"]["person"]["name"] 343 | 344 | :returns: Return a json found by the path or a null json with error 345 | */ 346 | public subscript(path: SubscriptType...) -> JSON { 347 | get { 348 | return self[path] 349 | } 350 | set { 351 | self[path] = newValue 352 | } 353 | } 354 | } 355 | 356 | // MARK: - LiteralConvertible 357 | 358 | extension JSON: StringLiteralConvertible { 359 | 360 | public init(stringLiteral value: StringLiteralType) { 361 | self.init(value) 362 | } 363 | 364 | public init(extendedGraphemeClusterLiteral value: StringLiteralType) { 365 | self.init(value) 366 | } 367 | 368 | public init(unicodeScalarLiteral value: StringLiteralType) { 369 | self.init(value) 370 | } 371 | } 372 | 373 | extension JSON: IntegerLiteralConvertible { 374 | 375 | public init(integerLiteral value: IntegerLiteralType) { 376 | self.init(value) 377 | } 378 | } 379 | 380 | extension JSON: BooleanLiteralConvertible { 381 | 382 | public init(booleanLiteral value: BooleanLiteralType) { 383 | self.init(value) 384 | } 385 | } 386 | 387 | extension JSON: FloatLiteralConvertible { 388 | 389 | public init(floatLiteral value: FloatLiteralType) { 390 | self.init(value) 391 | } 392 | } 393 | 394 | extension JSON: DictionaryLiteralConvertible { 395 | 396 | public init(dictionaryLiteral elements: (String, AnyObject)...) { 397 | var dictionary_ = [String : AnyObject]() 398 | for (key_, value) in elements { 399 | dictionary_[key_] = value 400 | } 401 | self.init(dictionary_) 402 | } 403 | } 404 | 405 | extension JSON: ArrayLiteralConvertible { 406 | 407 | public init(arrayLiteral elements: AnyObject...) { 408 | self.init(elements) 409 | } 410 | } 411 | 412 | extension JSON: NilLiteralConvertible { 413 | 414 | public init(nilLiteral: ()) { 415 | self.init(NSNull()) 416 | } 417 | } 418 | 419 | // MARK: - Raw 420 | 421 | extension JSON: RawRepresentable { 422 | 423 | public init?(rawValue: AnyObject) { 424 | if JSON(rawValue).type == .Unknown { 425 | return nil 426 | } else { 427 | self.init(rawValue) 428 | } 429 | } 430 | 431 | public var rawValue: AnyObject { 432 | return self.object 433 | } 434 | 435 | public func rawData(options opt: NSJSONWritingOptions = NSJSONWritingOptions(0), error: NSErrorPointer = nil) -> NSData? { 436 | return NSJSONSerialization.dataWithJSONObject(self.object, options: opt, error:error) 437 | } 438 | 439 | public func rawString(encoding: UInt = NSUTF8StringEncoding, options opt: NSJSONWritingOptions = .PrettyPrinted) -> String? { 440 | switch self.type { 441 | case .Array, .Dictionary: 442 | if let data = self.rawData(options: opt) { 443 | return NSString(data: data, encoding: encoding) as? String 444 | } else { 445 | return nil 446 | } 447 | case .String: 448 | return (self.object as! String) 449 | case .Number: 450 | return (self.object as! NSNumber).stringValue 451 | case .Bool: 452 | return (self.object as! Bool).description 453 | case .Null: 454 | return "null" 455 | default: 456 | return nil 457 | } 458 | } 459 | } 460 | 461 | // MARK: - Printable, DebugPrintable 462 | 463 | extension JSON: Printable, DebugPrintable { 464 | 465 | public var description: String { 466 | if let string = self.rawString(options:.PrettyPrinted) { 467 | return string 468 | } else { 469 | return "unknown" 470 | } 471 | } 472 | 473 | public var debugDescription: String { 474 | return description 475 | } 476 | } 477 | 478 | // MARK: - Array 479 | 480 | extension JSON { 481 | 482 | //Optional [JSON] 483 | public var array: [JSON]? { 484 | get { 485 | if self.type == .Array { 486 | return map(self.object as! [AnyObject]){ JSON($0) } 487 | } else { 488 | return nil 489 | } 490 | } 491 | } 492 | 493 | //Non-optional [JSON] 494 | public var arrayValue: [JSON] { 495 | get { 496 | return self.array ?? [] 497 | } 498 | } 499 | 500 | //Optional [AnyObject] 501 | public var arrayObject: [AnyObject]? { 502 | get { 503 | switch self.type { 504 | case .Array: 505 | return self.object as? [AnyObject] 506 | default: 507 | return nil 508 | } 509 | } 510 | set { 511 | if newValue != nil { 512 | self.object = NSMutableArray(array: newValue!, copyItems: true) 513 | } else { 514 | self.object = NSNull() 515 | } 516 | } 517 | } 518 | } 519 | 520 | // MARK: - Dictionary 521 | 522 | extension JSON { 523 | 524 | private func _map(source: [Key: Value], transform: Value -> NewValue) -> [Key: NewValue] { 525 | var result = [Key: NewValue](minimumCapacity:source.count) 526 | for (key,value) in source { 527 | result[key] = transform(value) 528 | } 529 | return result 530 | } 531 | 532 | //Optional [String : JSON] 533 | public var dictionary: [String : JSON]? { 534 | get { 535 | if self.type == .Dictionary { 536 | return _map(self.object as! [String : AnyObject]){ JSON($0) } 537 | } else { 538 | return nil 539 | } 540 | } 541 | } 542 | 543 | //Non-optional [String : JSON] 544 | public var dictionaryValue: [String : JSON] { 545 | get { 546 | return self.dictionary ?? [:] 547 | } 548 | } 549 | 550 | //Optional [String : AnyObject] 551 | public var dictionaryObject: [String : AnyObject]? { 552 | get { 553 | switch self.type { 554 | case .Dictionary: 555 | return self.object as? [String : AnyObject] 556 | default: 557 | return nil 558 | } 559 | } 560 | set { 561 | if newValue != nil { 562 | self.object = NSMutableDictionary(dictionary: newValue!, copyItems: true) 563 | } else { 564 | self.object = NSNull() 565 | } 566 | } 567 | } 568 | } 569 | 570 | // MARK: - Bool 571 | 572 | extension JSON: BooleanType { 573 | 574 | //Optional bool 575 | public var bool: Bool? { 576 | get { 577 | switch self.type { 578 | case .Bool: 579 | return self.object.boolValue 580 | default: 581 | return nil 582 | } 583 | } 584 | set { 585 | if newValue != nil { 586 | self.object = NSNumber(bool: newValue!) 587 | } else { 588 | self.object = NSNull() 589 | } 590 | } 591 | } 592 | 593 | //Non-optional bool 594 | public var boolValue: Bool { 595 | get { 596 | switch self.type { 597 | case .Bool, .Number, .String: 598 | return self.object.boolValue 599 | default: 600 | return false 601 | } 602 | } 603 | set { 604 | self.object = NSNumber(bool: newValue) 605 | } 606 | } 607 | } 608 | 609 | // MARK: - String 610 | 611 | extension JSON { 612 | 613 | //Optional string 614 | public var string: String? { 615 | get { 616 | switch self.type { 617 | case .String: 618 | return self.object as? String 619 | default: 620 | return nil 621 | } 622 | } 623 | set { 624 | if newValue != nil { 625 | self.object = NSString(string:newValue!) 626 | } else { 627 | self.object = NSNull() 628 | } 629 | } 630 | } 631 | 632 | //Non-optional string 633 | public var stringValue: String { 634 | get { 635 | switch self.type { 636 | case .String: 637 | return self.object as! String 638 | case .Number: 639 | return self.object.stringValue 640 | case .Bool: 641 | return (self.object as! Bool).description 642 | default: 643 | return "" 644 | } 645 | } 646 | set { 647 | self.object = NSString(string:newValue) 648 | } 649 | } 650 | } 651 | 652 | // MARK: - Number 653 | extension JSON { 654 | 655 | //Optional number 656 | public var number: NSNumber? { 657 | get { 658 | switch self.type { 659 | case .Number, .Bool: 660 | return self.object as? NSNumber 661 | default: 662 | return nil 663 | } 664 | } 665 | set { 666 | self.object = newValue?.copy() ?? NSNull() 667 | } 668 | } 669 | 670 | //Non-optional number 671 | public var numberValue: NSNumber { 672 | get { 673 | switch self.type { 674 | case .String: 675 | let scanner = NSScanner(string: self.object as! String) 676 | if scanner.scanDouble(nil){ 677 | if (scanner.atEnd) { 678 | return NSNumber(double:(self.object as! NSString).doubleValue) 679 | } 680 | } 681 | return NSNumber(double: 0.0) 682 | case .Number, .Bool: 683 | return self.object as! NSNumber 684 | default: 685 | return NSNumber(double: 0.0) 686 | } 687 | } 688 | set { 689 | self.object = newValue.copy() 690 | } 691 | } 692 | } 693 | 694 | //MARK: - Null 695 | extension JSON { 696 | 697 | public var null: NSNull? { 698 | get { 699 | switch self.type { 700 | case .Null: 701 | return NSNull() 702 | default: 703 | return nil 704 | } 705 | } 706 | set { 707 | self.object = NSNull() 708 | } 709 | } 710 | } 711 | 712 | //MARK: - URL 713 | extension JSON { 714 | 715 | //Optional URL 716 | public var URL: NSURL? { 717 | get { 718 | switch self.type { 719 | case .String: 720 | if let encodedString_ = self.object.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) { 721 | return NSURL(string: encodedString_) 722 | } else { 723 | return nil 724 | } 725 | default: 726 | return nil 727 | } 728 | } 729 | set { 730 | self.object = newValue?.absoluteString ?? NSNull() 731 | } 732 | } 733 | } 734 | 735 | // MARK: - Int, Double, Float, Int8, Int16, Int32, Int64 736 | 737 | extension JSON { 738 | 739 | public var double: Double? { 740 | get { 741 | return self.number?.doubleValue 742 | } 743 | set { 744 | if newValue != nil { 745 | self.object = NSNumber(double: newValue!) 746 | } else { 747 | self.object = NSNull() 748 | } 749 | } 750 | } 751 | 752 | public var doubleValue: Double { 753 | get { 754 | return self.numberValue.doubleValue 755 | } 756 | set { 757 | self.object = NSNumber(double: newValue) 758 | } 759 | } 760 | 761 | public var float: Float? { 762 | get { 763 | return self.number?.floatValue 764 | } 765 | set { 766 | if newValue != nil { 767 | self.object = NSNumber(float: newValue!) 768 | } else { 769 | self.object = NSNull() 770 | } 771 | } 772 | } 773 | 774 | public var floatValue: Float { 775 | get { 776 | return self.numberValue.floatValue 777 | } 778 | set { 779 | self.object = NSNumber(float: newValue) 780 | } 781 | } 782 | 783 | public var int: Int? { 784 | get { 785 | return self.number?.longValue 786 | } 787 | set { 788 | if newValue != nil { 789 | self.object = NSNumber(integer: newValue!) 790 | } else { 791 | self.object = NSNull() 792 | } 793 | } 794 | } 795 | 796 | public var intValue: Int { 797 | get { 798 | return self.numberValue.integerValue 799 | } 800 | set { 801 | self.object = NSNumber(integer: newValue) 802 | } 803 | } 804 | 805 | public var uInt: UInt? { 806 | get { 807 | return self.number?.unsignedLongValue 808 | } 809 | set { 810 | if newValue != nil { 811 | self.object = NSNumber(unsignedLong: newValue!) 812 | } else { 813 | self.object = NSNull() 814 | } 815 | } 816 | } 817 | 818 | public var uIntValue: UInt { 819 | get { 820 | return self.numberValue.unsignedLongValue 821 | } 822 | set { 823 | self.object = NSNumber(unsignedLong: newValue) 824 | } 825 | } 826 | 827 | public var int8: Int8? { 828 | get { 829 | return self.number?.charValue 830 | } 831 | set { 832 | if newValue != nil { 833 | self.object = NSNumber(char: newValue!) 834 | } else { 835 | self.object = NSNull() 836 | } 837 | } 838 | } 839 | 840 | public var int8Value: Int8 { 841 | get { 842 | return self.numberValue.charValue 843 | } 844 | set { 845 | self.object = NSNumber(char: newValue) 846 | } 847 | } 848 | 849 | public var uInt8: UInt8? { 850 | get { 851 | return self.number?.unsignedCharValue 852 | } 853 | set { 854 | if newValue != nil { 855 | self.object = NSNumber(unsignedChar: newValue!) 856 | } else { 857 | self.object = NSNull() 858 | } 859 | } 860 | } 861 | 862 | public var uInt8Value: UInt8 { 863 | get { 864 | return self.numberValue.unsignedCharValue 865 | } 866 | set { 867 | self.object = NSNumber(unsignedChar: newValue) 868 | } 869 | } 870 | 871 | public var int16: Int16? { 872 | get { 873 | return self.number?.shortValue 874 | } 875 | set { 876 | if newValue != nil { 877 | self.object = NSNumber(short: newValue!) 878 | } else { 879 | self.object = NSNull() 880 | } 881 | } 882 | } 883 | 884 | public var int16Value: Int16 { 885 | get { 886 | return self.numberValue.shortValue 887 | } 888 | set { 889 | self.object = NSNumber(short: newValue) 890 | } 891 | } 892 | 893 | public var uInt16: UInt16? { 894 | get { 895 | return self.number?.unsignedShortValue 896 | } 897 | set { 898 | if newValue != nil { 899 | self.object = NSNumber(unsignedShort: newValue!) 900 | } else { 901 | self.object = NSNull() 902 | } 903 | } 904 | } 905 | 906 | public var uInt16Value: UInt16 { 907 | get { 908 | return self.numberValue.unsignedShortValue 909 | } 910 | set { 911 | self.object = NSNumber(unsignedShort: newValue) 912 | } 913 | } 914 | 915 | public var int32: Int32? { 916 | get { 917 | return self.number?.intValue 918 | } 919 | set { 920 | if newValue != nil { 921 | self.object = NSNumber(int: newValue!) 922 | } else { 923 | self.object = NSNull() 924 | } 925 | } 926 | } 927 | 928 | public var int32Value: Int32 { 929 | get { 930 | return self.numberValue.intValue 931 | } 932 | set { 933 | self.object = NSNumber(int: newValue) 934 | } 935 | } 936 | 937 | public var uInt32: UInt32? { 938 | get { 939 | return self.number?.unsignedIntValue 940 | } 941 | set { 942 | if newValue != nil { 943 | self.object = NSNumber(unsignedInt: newValue!) 944 | } else { 945 | self.object = NSNull() 946 | } 947 | } 948 | } 949 | 950 | public var uInt32Value: UInt32 { 951 | get { 952 | return self.numberValue.unsignedIntValue 953 | } 954 | set { 955 | self.object = NSNumber(unsignedInt: newValue) 956 | } 957 | } 958 | 959 | public var int64: Int64? { 960 | get { 961 | return self.number?.longLongValue 962 | } 963 | set { 964 | if newValue != nil { 965 | self.object = NSNumber(longLong: newValue!) 966 | } else { 967 | self.object = NSNull() 968 | } 969 | } 970 | } 971 | 972 | public var int64Value: Int64 { 973 | get { 974 | return self.numberValue.longLongValue 975 | } 976 | set { 977 | self.object = NSNumber(longLong: newValue) 978 | } 979 | } 980 | 981 | public var uInt64: UInt64? { 982 | get { 983 | return self.number?.unsignedLongLongValue 984 | } 985 | set { 986 | if newValue != nil { 987 | self.object = NSNumber(unsignedLongLong: newValue!) 988 | } else { 989 | self.object = NSNull() 990 | } 991 | } 992 | } 993 | 994 | public var uInt64Value: UInt64 { 995 | get { 996 | return self.numberValue.unsignedLongLongValue 997 | } 998 | set { 999 | self.object = NSNumber(unsignedLongLong: newValue) 1000 | } 1001 | } 1002 | } 1003 | 1004 | //MARK: - Comparable 1005 | extension JSON: Comparable {} 1006 | 1007 | public func ==(lhs: JSON, rhs: JSON) -> Bool { 1008 | 1009 | switch (lhs.type, rhs.type) { 1010 | case (.Number, .Number): 1011 | return (lhs.object as! NSNumber) == (rhs.object as! NSNumber) 1012 | case (.String, .String): 1013 | return (lhs.object as! String) == (rhs.object as! String) 1014 | case (.Bool, .Bool): 1015 | return (lhs.object as! Bool) == (rhs.object as! Bool) 1016 | case (.Array, .Array): 1017 | return (lhs.object as! NSArray) == (rhs.object as! NSArray) 1018 | case (.Dictionary, .Dictionary): 1019 | return (lhs.object as! NSDictionary) == (rhs.object as! NSDictionary) 1020 | case (.Null, .Null): 1021 | return true 1022 | default: 1023 | return false 1024 | } 1025 | } 1026 | 1027 | public func <=(lhs: JSON, rhs: JSON) -> Bool { 1028 | 1029 | switch (lhs.type, rhs.type) { 1030 | case (.Number, .Number): 1031 | return (lhs.object as! NSNumber) <= (rhs.object as! NSNumber) 1032 | case (.String, .String): 1033 | return (lhs.object as! String) <= (rhs.object as! String) 1034 | case (.Bool, .Bool): 1035 | return (lhs.object as! Bool) == (rhs.object as! Bool) 1036 | case (.Array, .Array): 1037 | return (lhs.object as! NSArray) == (rhs.object as! NSArray) 1038 | case (.Dictionary, .Dictionary): 1039 | return (lhs.object as! NSDictionary) == (rhs.object as! NSDictionary) 1040 | case (.Null, .Null): 1041 | return true 1042 | default: 1043 | return false 1044 | } 1045 | } 1046 | 1047 | public func >=(lhs: JSON, rhs: JSON) -> Bool { 1048 | 1049 | switch (lhs.type, rhs.type) { 1050 | case (.Number, .Number): 1051 | return (lhs.object as! NSNumber) >= (rhs.object as! NSNumber) 1052 | case (.String, .String): 1053 | return (lhs.object as! String) >= (rhs.object as! String) 1054 | case (.Bool, .Bool): 1055 | return (lhs.object as! Bool) == (rhs.object as! Bool) 1056 | case (.Array, .Array): 1057 | return (lhs.object as! NSArray) == (rhs.object as! NSArray) 1058 | case (.Dictionary, .Dictionary): 1059 | return (lhs.object as! NSDictionary) == (rhs.object as! NSDictionary) 1060 | case (.Null, .Null): 1061 | return true 1062 | default: 1063 | return false 1064 | } 1065 | } 1066 | 1067 | public func >(lhs: JSON, rhs: JSON) -> Bool { 1068 | 1069 | switch (lhs.type, rhs.type) { 1070 | case (.Number, .Number): 1071 | return (lhs.object as! NSNumber) > (rhs.object as! NSNumber) 1072 | case (.String, .String): 1073 | return (lhs.object as! String) > (rhs.object as! String) 1074 | default: 1075 | return false 1076 | } 1077 | } 1078 | 1079 | public func <(lhs: JSON, rhs: JSON) -> Bool { 1080 | 1081 | switch (lhs.type, rhs.type) { 1082 | case (.Number, .Number): 1083 | return (lhs.object as! NSNumber) < (rhs.object as! NSNumber) 1084 | case (.String, .String): 1085 | return (lhs.object as! String) < (rhs.object as! String) 1086 | default: 1087 | return false 1088 | } 1089 | } 1090 | 1091 | private let trueNumber = NSNumber(bool: true) 1092 | private let falseNumber = NSNumber(bool: false) 1093 | private let trueObjCType = String.fromCString(trueNumber.objCType) 1094 | private let falseObjCType = String.fromCString(falseNumber.objCType) 1095 | 1096 | // MARK: - NSNumber: Comparable 1097 | 1098 | extension NSNumber: Comparable { 1099 | var isBool:Bool { 1100 | get { 1101 | let objCType = String.fromCString(self.objCType) 1102 | if (self.compare(trueNumber) == NSComparisonResult.OrderedSame && objCType == trueObjCType) || (self.compare(falseNumber) == NSComparisonResult.OrderedSame && objCType == falseObjCType){ 1103 | return true 1104 | } else { 1105 | return false 1106 | } 1107 | } 1108 | } 1109 | } 1110 | 1111 | public func ==(lhs: NSNumber, rhs: NSNumber) -> Bool { 1112 | switch (lhs.isBool, rhs.isBool) { 1113 | case (false, true): 1114 | return false 1115 | case (true, false): 1116 | return false 1117 | default: 1118 | return lhs.compare(rhs) == NSComparisonResult.OrderedSame 1119 | } 1120 | } 1121 | 1122 | public func !=(lhs: NSNumber, rhs: NSNumber) -> Bool { 1123 | return !(lhs == rhs) 1124 | } 1125 | 1126 | public func <(lhs: NSNumber, rhs: NSNumber) -> Bool { 1127 | 1128 | switch (lhs.isBool, rhs.isBool) { 1129 | case (false, true): 1130 | return false 1131 | case (true, false): 1132 | return false 1133 | default: 1134 | return lhs.compare(rhs) == NSComparisonResult.OrderedAscending 1135 | } 1136 | } 1137 | 1138 | public func >(lhs: NSNumber, rhs: NSNumber) -> Bool { 1139 | 1140 | switch (lhs.isBool, rhs.isBool) { 1141 | case (false, true): 1142 | return false 1143 | case (true, false): 1144 | return false 1145 | default: 1146 | return lhs.compare(rhs) == NSComparisonResult.OrderedDescending 1147 | } 1148 | } 1149 | 1150 | public func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { 1151 | 1152 | switch (lhs.isBool, rhs.isBool) { 1153 | case (false, true): 1154 | return false 1155 | case (true, false): 1156 | return false 1157 | default: 1158 | return lhs.compare(rhs) != NSComparisonResult.OrderedDescending 1159 | } 1160 | } 1161 | 1162 | public func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { 1163 | 1164 | switch (lhs.isBool, rhs.isBool) { 1165 | case (false, true): 1166 | return false 1167 | case (true, false): 1168 | return false 1169 | default: 1170 | return lhs.compare(rhs) != NSComparisonResult.OrderedAscending 1171 | } 1172 | } 1173 | 1174 | //MARK:- Unavailable 1175 | 1176 | @availability(*, unavailable, renamed="JSON") 1177 | public typealias JSONValue = JSON 1178 | 1179 | extension JSON { 1180 | 1181 | @availability(*, unavailable, message="use 'init(_ object:AnyObject)' instead") 1182 | public init(object: AnyObject) { 1183 | self = JSON(object) 1184 | } 1185 | 1186 | @availability(*, unavailable, renamed="dictionaryObject") 1187 | public var dictionaryObjects: [String : AnyObject]? { 1188 | get { return self.dictionaryObject } 1189 | } 1190 | 1191 | @availability(*, unavailable, renamed="arrayObject") 1192 | public var arrayObjects: [AnyObject]? { 1193 | get { return self.arrayObject } 1194 | } 1195 | 1196 | @availability(*, unavailable, renamed="int8") 1197 | public var char: Int8? { 1198 | get { 1199 | return self.number?.charValue 1200 | } 1201 | } 1202 | 1203 | @availability(*, unavailable, renamed="int8Value") 1204 | public var charValue: Int8 { 1205 | get { 1206 | return self.numberValue.charValue 1207 | } 1208 | } 1209 | 1210 | @availability(*, unavailable, renamed="uInt8") 1211 | public var unsignedChar: UInt8? { 1212 | get{ 1213 | return self.number?.unsignedCharValue 1214 | } 1215 | } 1216 | 1217 | @availability(*, unavailable, renamed="uInt8Value") 1218 | public var unsignedCharValue: UInt8 { 1219 | get{ 1220 | return self.numberValue.unsignedCharValue 1221 | } 1222 | } 1223 | 1224 | @availability(*, unavailable, renamed="int16") 1225 | public var short: Int16? { 1226 | get{ 1227 | return self.number?.shortValue 1228 | } 1229 | } 1230 | 1231 | @availability(*, unavailable, renamed="int16Value") 1232 | public var shortValue: Int16 { 1233 | get{ 1234 | return self.numberValue.shortValue 1235 | } 1236 | } 1237 | 1238 | @availability(*, unavailable, renamed="uInt16") 1239 | public var unsignedShort: UInt16? { 1240 | get{ 1241 | return self.number?.unsignedShortValue 1242 | } 1243 | } 1244 | 1245 | @availability(*, unavailable, renamed="uInt16Value") 1246 | public var unsignedShortValue: UInt16 { 1247 | get{ 1248 | return self.numberValue.unsignedShortValue 1249 | } 1250 | } 1251 | 1252 | @availability(*, unavailable, renamed="int") 1253 | public var long: Int? { 1254 | get{ 1255 | return self.number?.longValue 1256 | } 1257 | } 1258 | 1259 | @availability(*, unavailable, renamed="intValue") 1260 | public var longValue: Int { 1261 | get{ 1262 | return self.numberValue.longValue 1263 | } 1264 | } 1265 | 1266 | @availability(*, unavailable, renamed="uInt") 1267 | public var unsignedLong: UInt? { 1268 | get{ 1269 | return self.number?.unsignedLongValue 1270 | } 1271 | } 1272 | 1273 | @availability(*, unavailable, renamed="uIntValue") 1274 | public var unsignedLongValue: UInt { 1275 | get{ 1276 | return self.numberValue.unsignedLongValue 1277 | } 1278 | } 1279 | 1280 | @availability(*, unavailable, renamed="int64") 1281 | public var longLong: Int64? { 1282 | get{ 1283 | return self.number?.longLongValue 1284 | } 1285 | } 1286 | 1287 | @availability(*, unavailable, renamed="int64Value") 1288 | public var longLongValue: Int64 { 1289 | get{ 1290 | return self.numberValue.longLongValue 1291 | } 1292 | } 1293 | 1294 | @availability(*, unavailable, renamed="uInt64") 1295 | public var unsignedLongLong: UInt64? { 1296 | get{ 1297 | return self.number?.unsignedLongLongValue 1298 | } 1299 | } 1300 | 1301 | @availability(*, unavailable, renamed="uInt64Value") 1302 | public var unsignedLongLongValue: UInt64 { 1303 | get{ 1304 | return self.numberValue.unsignedLongLongValue 1305 | } 1306 | } 1307 | 1308 | @availability(*, unavailable, renamed="int") 1309 | public var integer: Int? { 1310 | get { 1311 | return self.number?.integerValue 1312 | } 1313 | } 1314 | 1315 | @availability(*, unavailable, renamed="intValue") 1316 | public var integerValue: Int { 1317 | get { 1318 | return self.numberValue.integerValue 1319 | } 1320 | } 1321 | 1322 | @availability(*, unavailable, renamed="uInt") 1323 | public var unsignedInteger: Int? { 1324 | get { 1325 | return self.number?.unsignedIntegerValue 1326 | } 1327 | } 1328 | 1329 | @availability(*, unavailable, renamed="uIntValue") 1330 | public var unsignedIntegerValue: Int { 1331 | get { 1332 | return self.numberValue.unsignedIntegerValue 1333 | } 1334 | } 1335 | } 1336 | -------------------------------------------------------------------------------- /SwiftJson/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // SwiftJson 4 | // 5 | // Created by Philip Woods on 6/11/14. 6 | // Copyright (c) 2014 pvwoods. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | class ViewController: NSViewController { 12 | 13 | @IBOutlet var jsonScrollView:NSScrollView! 14 | @IBOutlet var modelScrollView:NSScrollView! 15 | @IBOutlet var classNameTextField:NSTextField! 16 | @IBOutlet var inspectArrays:NSButton! 17 | 18 | var jsonTextView : NSTextView { 19 | get { 20 | return jsonScrollView.contentView.documentView as! NSTextView 21 | } 22 | } 23 | 24 | var modelTextView : NSTextView { 25 | get { 26 | return modelScrollView.contentView.documentView as! NSTextView 27 | } 28 | } 29 | 30 | override func awakeFromNib() { 31 | super.awakeFromNib() 32 | 33 | NSNotificationCenter.defaultCenter().addObserver(self, selector:"onSelectGenerate:", name: "SELECTED_GENERATE", object: nil) 34 | 35 | [jsonTextView, modelTextView].map { 36 | 37 | (tv:NSTextView) -> NSTextView in 38 | 39 | tv.richText = false 40 | tv.automaticQuoteSubstitutionEnabled = false; 41 | tv.automaticSpellingCorrectionEnabled = false; 42 | tv.automaticDashSubstitutionEnabled = false 43 | tv.enabledTextCheckingTypes = 0 44 | return tv 45 | 46 | } 47 | 48 | 49 | } 50 | 51 | @IBAction func onSelectGenerate(e:AnyObject) { 52 | 53 | var className = classNameTextField.stringValue.isEmpty ? "MyClass":classNameTextField.stringValue; 54 | 55 | var jsonText = jsonTextView.textStorage!.string 56 | var jsonData : NSData? = (jsonText as NSString).dataUsingEncoding(NSUTF8StringEncoding) 57 | var erro: NSError?; 58 | 59 | if jsonData != nil { 60 | if let dir : NSDictionary = NSJSONSerialization.JSONObjectWithData(jsonData!, options: nil, error: &erro) as? NSDictionary { 61 | 62 | let json = JSON(dir) 63 | 64 | // if json { 65 | 66 | let generator:ModelGenerator = ModelGenerator(json:json, className:className, inspectArrays:inspectArrays.state == 1) 67 | 68 | modelTextView.textStorage!.setAttributedString(NSAttributedString(string: generator.output)) 69 | 70 | // } else { 71 | // modelTextView.textStorage!.setAttributedString(NSAttributedString(string:"There was an issue parsing your JSON...")) 72 | // } 73 | } 74 | 75 | } else { 76 | modelTextView.textStorage!.setAttributedString(NSAttributedString(string:"Couldn't encode your data...")) 77 | } 78 | 79 | 80 | } 81 | 82 | 83 | } 84 | 85 | -------------------------------------------------------------------------------- /SwiftJson/main.swift: -------------------------------------------------------------------------------- 1 | // 2 | // main.swift 3 | // SwiftJson 4 | // 5 | // Created by Philip Woods on 6/11/14. 6 | // Copyright (c) 2014 pvwoods. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | NSApplicationMain(Process.argc, Process.unsafeArgv) 12 | -------------------------------------------------------------------------------- /SwiftJsonTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.pvwoods.${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 | -------------------------------------------------------------------------------- /SwiftJsonTests/SwiftJsonTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftJsonTests.swift 3 | // SwiftJsonTests 4 | // 5 | // Created by Philip Woods on 6/11/14. 6 | // Copyright (c) 2014 pvwoods. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class SwiftJsonTests: XCTestCase { 12 | 13 | override func setUp() { 14 | super.setUp() 15 | // Put setup code here. This method is called before the invocation of each test method in the class. 16 | } 17 | 18 | override func tearDown() { 19 | // Put teardown code here. This method is called after the invocation of each test method in the class. 20 | super.tearDown() 21 | } 22 | 23 | func testExample() { 24 | // This is an example of a functional test case. 25 | XCTAssert(true, "Pass") 26 | } 27 | 28 | func testPerformanceExample() { 29 | // This is an example of a performance test case. 30 | self.measureBlock() { 31 | // Put the code you want to measure the time of here. 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swiftjson/SwiftJson/9a78dd94e3a23233d8c6c75ba3fb32a2a5bb3166/screenshot.png --------------------------------------------------------------------------------