diff --git a/JSONConverter.xcodeproj/project.pbxproj b/JSONConverter.xcodeproj/project.pbxproj index d1188a6..f6944c6 100644 --- a/JSONConverter.xcodeproj/project.pbxproj +++ b/JSONConverter.xcodeproj/project.pbxproj @@ -11,8 +11,6 @@ 7B45DAFF202A95BF007E8D56 /* MainViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7B45DAED202A95BE007E8D56 /* MainViewController.xib */; }; 7B45DB00202A95BF007E8D56 /* MainWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B45DAEE202A95BE007E8D56 /* MainWindowController.swift */; }; 7B45DB01202A95BF007E8D56 /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B45DAEF202A95BE007E8D56 /* MainViewController.swift */; }; - 7B45DB02202A95BF007E8D56 /* YWPropertyStrUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B45DAF0202A95BE007E8D56 /* YWPropertyStrUtils.swift */; }; - 7B45DB03202A95BF007E8D56 /* YWCommon.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B45DAF1202A95BE007E8D56 /* YWCommon.swift */; }; 7B45DB04202A95BF007E8D56 /* MainWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7B45DAF2202A95BE007E8D56 /* MainWindowController.xib */; }; 7B45DB05202A95BF007E8D56 /* Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B45DAF4202A95BE007E8D56 /* Extension.swift */; }; 7B45DB06202A95BF007E8D56 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7B45DAF6202A95BE007E8D56 /* Assets.xcassets */; }; @@ -24,17 +22,24 @@ 7BD7FED8202AC1E80003AE80 /* NoodleLineNumberMarker.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BD7FED6202AC1E80003AE80 /* NoodleLineNumberMarker.m */; }; 7BD7FEDA202AC7C10003AE80 /* YWContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BD7FED9202AC7C10003AE80 /* YWContent.swift */; }; 7BD7FEDC202AC7EB0003AE80 /* YWProperty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BD7FEDB202AC7EB0003AE80 /* YWProperty.swift */; }; - 7BD7FEE0202AD1470003AE80 /* YWAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BD7FEDF202AD1470003AE80 /* YWAlertView.swift */; }; - 7BD7FEE3202AD8A90003AE80 /* YWConstructor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BD7FEE2202AD8A90003AE80 /* YWConstructor.swift */; }; + 7BDF2972202BDB7D00B7E2F5 /* JSONConverterUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BDF2971202BDB7D00B7E2F5 /* JSONConverterUITests.swift */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + 7BDF2974202BDB7D00B7E2F5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 7B4B5EA2201B87A10098712B /* Project object */; + proxyType = 1; + remoteGlobalIDString = 7B4B5EA9201B87A10098712B; + remoteInfo = JSONConverter; + }; +/* End PBXContainerItemProxy section */ + /* Begin PBXFileReference section */ 7B45DAEC202A95BE007E8D56 /* YWJsonParserUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YWJsonParserUtils.swift; sourceTree = ""; }; 7B45DAED202A95BE007E8D56 /* MainViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainViewController.xib; sourceTree = ""; }; 7B45DAEE202A95BE007E8D56 /* MainWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainWindowController.swift; sourceTree = ""; }; 7B45DAEF202A95BE007E8D56 /* MainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = ""; }; - 7B45DAF0202A95BE007E8D56 /* YWPropertyStrUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YWPropertyStrUtils.swift; sourceTree = ""; }; - 7B45DAF1202A95BE007E8D56 /* YWCommon.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YWCommon.swift; sourceTree = ""; }; 7B45DAF2202A95BE007E8D56 /* MainWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainWindowController.xib; sourceTree = ""; }; 7B45DAF4202A95BE007E8D56 /* Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extension.swift; sourceTree = ""; }; 7B45DAF5202A95BE007E8D56 /* JSONConverter.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = JSONConverter.entitlements; sourceTree = ""; }; @@ -51,8 +56,9 @@ 7BD7FED6202AC1E80003AE80 /* NoodleLineNumberMarker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NoodleLineNumberMarker.m; sourceTree = ""; }; 7BD7FED9202AC7C10003AE80 /* YWContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YWContent.swift; sourceTree = ""; }; 7BD7FEDB202AC7EB0003AE80 /* YWProperty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YWProperty.swift; sourceTree = ""; }; - 7BD7FEDF202AD1470003AE80 /* YWAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YWAlertView.swift; sourceTree = ""; }; - 7BD7FEE2202AD8A90003AE80 /* YWConstructor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YWConstructor.swift; sourceTree = ""; }; + 7BDF296F202BDB7C00B7E2F5 /* JSONConverterUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JSONConverterUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 7BDF2971202BDB7D00B7E2F5 /* JSONConverterUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONConverterUITests.swift; sourceTree = ""; }; + 7BDF2973202BDB7D00B7E2F5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -63,6 +69,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 7BDF296C202BDB7C00B7E2F5 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -95,9 +108,6 @@ 7BD7FEE1202AD1F30003AE80 /* MainView */, 7BD7FEDE202AC85B0003AE80 /* FileContent */, 7B45DAEC202A95BE007E8D56 /* YWJsonParserUtils.swift */, - 7B45DAF0202A95BE007E8D56 /* YWPropertyStrUtils.swift */, - 7B45DAF1202A95BE007E8D56 /* YWCommon.swift */, - 7BD7FEDF202AD1470003AE80 /* YWAlertView.swift */, ); path = Main; sourceTree = ""; @@ -115,6 +125,7 @@ isa = PBXGroup; children = ( 7B45DAE9202A95BE007E8D56 /* JSONConverter */, + 7BDF2970202BDB7D00B7E2F5 /* JSONConverterUITests */, 7B4B5EAB201B87A10098712B /* Products */, ); sourceTree = ""; @@ -123,6 +134,7 @@ isa = PBXGroup; children = ( 7B4B5EAA201B87A10098712B /* JSONConverter.app */, + 7BDF296F202BDB7C00B7E2F5 /* JSONConverterUITests.xctest */, ); name = Products; sourceTree = ""; @@ -144,7 +156,6 @@ 7B45DB0E202AA572007E8D56 /* YWFile.swift */, 7BD7FED9202AC7C10003AE80 /* YWContent.swift */, 7BD7FEDB202AC7EB0003AE80 /* YWProperty.swift */, - 7BD7FEE2202AD8A90003AE80 /* YWConstructor.swift */, ); path = FileContent; sourceTree = ""; @@ -160,6 +171,15 @@ path = MainView; sourceTree = ""; }; + 7BDF2970202BDB7D00B7E2F5 /* JSONConverterUITests */ = { + isa = PBXGroup; + children = ( + 7BDF2971202BDB7D00B7E2F5 /* JSONConverterUITests.swift */, + 7BDF2973202BDB7D00B7E2F5 /* Info.plist */, + ); + path = JSONConverterUITests; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -180,6 +200,24 @@ productReference = 7B4B5EAA201B87A10098712B /* JSONConverter.app */; productType = "com.apple.product-type.application"; }; + 7BDF296E202BDB7C00B7E2F5 /* JSONConverterUITests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 7BDF2978202BDB7D00B7E2F5 /* Build configuration list for PBXNativeTarget "JSONConverterUITests" */; + buildPhases = ( + 7BDF296B202BDB7C00B7E2F5 /* Sources */, + 7BDF296C202BDB7C00B7E2F5 /* Frameworks */, + 7BDF296D202BDB7C00B7E2F5 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 7BDF2975202BDB7D00B7E2F5 /* PBXTargetDependency */, + ); + name = JSONConverterUITests; + productName = JSONConverterUITests; + productReference = 7BDF296F202BDB7C00B7E2F5 /* JSONConverterUITests.xctest */; + productType = "com.apple.product-type.bundle.ui-testing"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -201,6 +239,11 @@ }; }; }; + 7BDF296E202BDB7C00B7E2F5 = { + CreatedOnToolsVersion = 9.2; + ProvisioningStyle = Automatic; + TestTargetID = 7B4B5EA9201B87A10098712B; + }; }; }; buildConfigurationList = 7B4B5EA5201B87A10098712B /* Build configuration list for PBXProject "JSONConverter" */; @@ -217,6 +260,7 @@ projectRoot = ""; targets = ( 7B4B5EA9201B87A10098712B /* JSONConverter */, + 7BDF296E202BDB7C00B7E2F5 /* JSONConverterUITests */, ); }; /* End PBXProject section */ @@ -234,6 +278,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 7BDF296D202BDB7C00B7E2F5 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -241,15 +292,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 7B45DB03202A95BF007E8D56 /* YWCommon.swift in Sources */, 7B45DB01202A95BF007E8D56 /* MainViewController.swift in Sources */, 7B45DB00202A95BF007E8D56 /* MainWindowController.swift in Sources */, - 7B45DB02202A95BF007E8D56 /* YWPropertyStrUtils.swift in Sources */, 7B45DB08202A95BF007E8D56 /* AppDelegate.swift in Sources */, 7BD7FEDA202AC7C10003AE80 /* YWContent.swift in Sources */, - 7BD7FEE0202AD1470003AE80 /* YWAlertView.swift in Sources */, 7BD7FED8202AC1E80003AE80 /* NoodleLineNumberMarker.m in Sources */, - 7BD7FEE3202AD8A90003AE80 /* YWConstructor.swift in Sources */, 7B45DB0F202AA572007E8D56 /* YWFile.swift in Sources */, 7BD7FEDC202AC7EB0003AE80 /* YWProperty.swift in Sources */, 7BD7FED7202AC1E80003AE80 /* NoodleLineNumberView.m in Sources */, @@ -258,8 +305,24 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 7BDF296B202BDB7C00B7E2F5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 7BDF2972202BDB7D00B7E2F5 /* JSONConverterUITests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + 7BDF2975202BDB7D00B7E2F5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 7B4B5EA9201B87A10098712B /* JSONConverter */; + targetProxy = 7BDF2974202BDB7D00B7E2F5 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + /* Begin PBXVariantGroup section */ 7B45DAF7202A95BE007E8D56 /* MainMenu.xib */ = { isa = PBXVariantGroup; @@ -417,6 +480,36 @@ }; name = Release; }; + 7BDF2976202BDB7D00B7E2F5 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = JSONConverterUITests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.tanmo.JSONConverterUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 4.0; + TEST_TARGET_NAME = JSONConverter; + }; + name = Debug; + }; + 7BDF2977202BDB7D00B7E2F5 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = JSONConverterUITests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = com.tanmo.JSONConverterUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 4.0; + TEST_TARGET_NAME = JSONConverter; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -438,6 +531,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 7BDF2978202BDB7D00B7E2F5 /* Build configuration list for PBXNativeTarget "JSONConverterUITests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7BDF2976202BDB7D00B7E2F5 /* Debug */, + 7BDF2977202BDB7D00B7E2F5 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ }; rootObject = 7B4B5EA2201B87A10098712B /* Project object */; diff --git a/JSONConverter/Classes/Main/FileContent/YWConstructor.swift b/JSONConverter/Classes/Main/FileContent/YWConstructor.swift deleted file mode 100644 index a534154..0000000 --- a/JSONConverter/Classes/Main/FileContent/YWConstructor.swift +++ /dev/null @@ -1,12 +0,0 @@ -// -// YWConstructor.swift -// JSONConverter -// -// Created by 姚巍 on 2018/2/7. -// Copyright © 2018年 姚巍. All rights reserved. -// - -import Foundation -class YWConstructor { - -} diff --git a/JSONConverter/Classes/Main/FileContent/YWContent.swift b/JSONConverter/Classes/Main/FileContent/YWContent.swift index 7379076..a6bbf97 100644 --- a/JSONConverter/Classes/Main/FileContent/YWContent.swift +++ b/JSONConverter/Classes/Main/FileContent/YWContent.swift @@ -10,13 +10,94 @@ import Foundation class YWContent { var properties = [YWProperty]() + var propertyKey: String + var langStruct: LangStruct - init(langStruct: LangStruct) { + var superClass: String + + var prefixStr: String + + init(propertyKey: String, langStruct: LangStruct, superClass: String, prefixStr: String) { + self.propertyKey = propertyKey self.langStruct = langStruct + self.superClass = superClass + self.prefixStr = prefixStr } func toString() -> String { - return "" + let className = propertyKey.className(withPrefix: prefixStr) + var contentStr = "" + + switch langStruct.langType { + case .ObjC: + contentStr = "\n@interface \(className)\(superClassNamePart())\n\(propertyTotalPart())\n@end\n" + case .Swift: + if langStruct.structType == .class { + contentStr = "\nclass \(className)\(superClassNamePart()) {\n\(propertyTotalPart())\n}\n" + }else if langStruct.structType == .struct { + contentStr = "\nstruct \(className)\(superClassNamePart()) {\n\(propertyTotalPart())\n}\n" + } + case .HandyJSON: + if langStruct.structType == .class { + contentStr = "\nclass \(className)\(superClassNamePart()) {\n\(propertyTotalPart())\n\trequired init() {}\n}\n" + }else if langStruct.structType == .struct { + contentStr = "\nstruct \(className)\(superClassNamePart()) {\n\(propertyTotalPart())\n}\n" + } + case .SwiftyJSON: + if langStruct.structType == .class { + contentStr = "\nclass \(className)\(superClassNamePart()) {\n\(propertyTotalPart())\n\tinit(json: JSON) {\n\(initSwiftTotalPart())\t}\n}\n" + }else if langStruct.structType == .struct { + contentStr = "\nstruct \(className)\(superClassNamePart()) {\n\(propertyTotalPart())\n\tinit(json: JSON) {\n\(initSwiftTotalPart())\t}\n}\n" + } + + case .ObjectMapper: + if langStruct.structType == .class { + contentStr = "\nclass \(className)\(superClassNamePart()) {\n\(propertyTotalPart())\n\trequired init?(map: Map) {}\n\n\tfunc mapping(map: Map) {\n\(initSwiftTotalPart())\t}\n}\n" + }else if langStruct.structType == .struct { + contentStr = "\nstruct \(className)\(superClassNamePart()) {\n\(propertyTotalPart())\n\tinit?(map: Map) {}\n\n\tmutating func mapping(map: Map) {\n\(initSwiftTotalPart())\t}\n}\n" + } + } + + return contentStr + } + + + private func propertyTotalPart() -> String { + var propertyStr = "" + + properties.forEach({ (property) in + propertyStr += property.toString().0 + }) + + return propertyStr + } + + private func initSwiftTotalPart() -> String { + var initSwiftStr = "" + properties.forEach({ (property) in + initSwiftStr += property.toString().1 + }) + + return initSwiftStr + } + + + private func superClassNamePart() -> String { + var superClassPart: String = "" + + switch langStruct.langType { + case .HandyJSON: + superClassPart = superClass.isEmpty ? ": HandyJSON" : ": \(superClass)" + case .Swift, .SwiftyJSON: + superClassPart = superClass.isEmpty ? "" : ": \(superClass)" + case .ObjC: + superClassPart = superClass.isEmpty ? ": NSObject" : ": \(superClass)" + case .ObjectMapper: + superClassPart = superClass.isEmpty ? ": Mappable" : ": \(superClass)" + break + } + + return superClassPart } } diff --git a/JSONConverter/Classes/Main/FileContent/YWFile.swift b/JSONConverter/Classes/Main/FileContent/YWFile.swift index 90a0078..7f9e745 100644 --- a/JSONConverter/Classes/Main/FileContent/YWFile.swift +++ b/JSONConverter/Classes/Main/FileContent/YWFile.swift @@ -15,23 +15,31 @@ class YWFile { var prefix: String = "" + var superName: String = "" + var langStruct = LangStruct(langType: .Swift, structType: .struct) var header: String = "" var contents = [YWContent]() - class func file(withName name: String, prefix: String, langStruct: LangStruct) -> YWFile { + class func file(withName name: String, prefix: String, langStruct: LangStruct, superName: String) -> YWFile { let file = YWFile() file.name = name file.prefix = prefix file.langStruct = langStruct + file.superName = superName return file } func toString() -> String { - return "" + var totalStr = "" + contents.forEach { (content) in + totalStr += content.toString() + } + + return totalStr } } diff --git a/JSONConverter/Classes/Main/FileContent/YWProperty.swift b/JSONConverter/Classes/Main/FileContent/YWProperty.swift index fdc3a27..1dcb860 100644 --- a/JSONConverter/Classes/Main/FileContent/YWProperty.swift +++ b/JSONConverter/Classes/Main/FileContent/YWProperty.swift @@ -32,13 +32,179 @@ class YWProperty { var langStruct: LangStruct - init(propertyKey: String, type: YWPropertyType, langStruct: LangStruct) { + var prefixStr: String + + init(propertyKey: String, type: YWPropertyType, langStruct: LangStruct, prefixStr: String) { self.propertyKey = propertyKey self.type = type self.langStruct = langStruct + self.prefixStr = prefixStr } - func toString() -> String { - return "" + + func toString() -> (String, String){ + var propertyStr = "" + var swiftInitStr = "" + switch type { + case .String: + switch langStruct.langType{ + case .ObjC: + propertyStr = "@property (nonatomic, copy) NSString *\(propertyKey);\n" + case .Swift,.HandyJSON: + propertyStr = "\tvar \(propertyKey): String?\n" + case .SwiftyJSON: + propertyStr = "\tvar \(propertyKey): String?\n" + swiftInitStr = "\t\t\(propertyKey) = json[\"\(propertyKey)\"].stringValue\n" + case .ObjectMapper: + propertyStr = "\tvar \(propertyKey): String?\n" + swiftInitStr = "\t\t\(propertyKey) <- map[\"\(propertyKey)\"]\n" + } + case .Int: + switch langStruct.langType{ + case .ObjC: + propertyStr = "@property (nonatomic, assign) Int \(propertyKey);\n" + case .Swift, .HandyJSON: + propertyStr = "\tvar \(propertyKey): Int = 0\n" + case .SwiftyJSON: + propertyStr = "\tvar \(propertyKey): Int = 0\n" + swiftInitStr = "\t\t\(propertyKey) = json[\"\(propertyKey)\"].intValue\n" + case .ObjectMapper: + propertyStr = "\tvar \(propertyKey): Int = 0\n" + swiftInitStr = "\t\t\(propertyKey) <- map[\"\(propertyKey)\"]\n" + } + case .Float: + switch langStruct.langType{ + case .ObjC: + propertyStr = "@property (nonatomic, assign) Float \(propertyKey);\n" + case .Swift, .HandyJSON: + propertyStr = "\tvar \(propertyKey): Float = 0.0\n" + case .SwiftyJSON: + propertyStr = "\tvar \(propertyKey): Float = 0.0\n" + swiftInitStr = "\t\t\(propertyKey) = json[\"\(propertyKey)\"].floatValue\n" + case .ObjectMapper: + propertyStr = "\tvar \(propertyKey): Float = 0.0\n" + swiftInitStr = "\t\t\(propertyKey) <- map[\"\(propertyKey)\"]\n" + } + case .Double: + switch langStruct.langType{ + case .ObjC: + propertyStr = "@property (nonatomic, assign) Double \(propertyKey);\n" + case .Swift, .HandyJSON: + propertyStr = "\tvar \(propertyKey): Double = 0.0\n" + case .SwiftyJSON: + propertyStr = "\tvar \(propertyKey): Double = 0.0\n" + swiftInitStr = "\t\t\(propertyKey) = json[\"\(propertyKey)\"].doubleValue\n" + case .ObjectMapper: + propertyStr = "\tvar \(propertyKey): Double = 0.0\n" + swiftInitStr = "\t\t\(propertyKey) <- map[\"\(propertyKey)\"]\n" + } + case .Bool: + switch langStruct.langType{ + case .ObjC: + propertyStr = "@property (nonatomic, assign) BOOL \(propertyKey);\n" + case .Swift, .HandyJSON: + propertyStr = "\tvar \(propertyKey): Bool = false\n" + case .SwiftyJSON: + propertyStr = "\tvar \(propertyKey): Bool = false\n" + swiftInitStr = "\t\t\(propertyKey) = json[\"\(propertyKey)\"].boolValue\n" + case .ObjectMapper: + propertyStr = "\tvar \(propertyKey): Bool = false\n" + swiftInitStr = "\t\t\(propertyKey) <- map[\"\(propertyKey)\"]\n" + } + case .Dictionary: + switch langStruct.langType{ + case .ObjC: + propertyStr = "@property (nonatomic, strong) \(propertyKey.className(withPrefix: prefixStr)) \(propertyKey);\n" + case .Swift, .HandyJSON: + propertyStr = "\tvar \(propertyKey): \(propertyKey.className(withPrefix: prefixStr))?\n" + case .SwiftyJSON: + propertyStr = "\tvar \(propertyKey): \(propertyKey.className(withPrefix: prefixStr))?\n" + swiftInitStr = "\t\t\(propertyKey) = \(propertyKey.className(withPrefix: prefixStr))(json: json[\"\(propertyKey)\"])\n" + case .ObjectMapper: + propertyStr = "\tvar \(propertyKey): \(propertyKey.className(withPrefix: prefixStr))?\n" + swiftInitStr = "\t\t\(propertyKey) <- map[\"\(propertyKey)\"]\n" + } + case .ArrayString: + switch langStruct.langType{ + case .ObjC: + propertyStr = "@@property (nonatomic, strong) NSArray *\(propertyKey);\n" + case .Swift, .HandyJSON: + propertyStr = "\tvar \(propertyKey) = [String]()\n" + case .SwiftyJSON: + propertyStr = "\tvar \(propertyKey) = [String]()\n" + swiftInitStr = "\t\t\(propertyKey) = json[\"\(propertyKey)\"].arrayValue.flatMap({$0.stringValue})\n" + case .ObjectMapper: + propertyStr = "\tvar \(propertyKey) = [String]()\n" + swiftInitStr = "\t\t\(propertyKey) <- map[\"\(propertyKey)\"]\n" + } + case .ArrayInt: + switch langStruct.langType{ + case .ObjC: + propertyStr = "@@property (nonatomic, strong) NSArray *\(propertyKey);\n" + case .Swift, .HandyJSON: + propertyStr = "\tvar \(propertyKey) = [Int]()\n" + case .SwiftyJSON: + propertyStr = "\tvar \(propertyKey) = [Int]()\n" + swiftInitStr = "\t\t\(propertyKey) = json[\"\(propertyKey)\"].arrayValue.flatMap({$0.intValue})\n" + case .ObjectMapper: + propertyStr = "\tvar \(propertyKey) = [Int]()\n" + swiftInitStr = "\t\t\(propertyKey) <- map[\"\(propertyKey)\"]\n" + } + case .ArrayFloat: + switch langStruct.langType{ + case .ObjC: + propertyStr = "@@property (nonatomic, strong) NSArray *\(propertyKey);\n" + case .Swift, .HandyJSON: + propertyStr = "\tvar \(propertyKey) = [Float]()\n" + case .SwiftyJSON: + propertyStr = "\tvar \(propertyKey) = [Float]()\n" + swiftInitStr = "\t\t\(propertyKey) = json[\"\(propertyKey)\"].arrayValue.flatMap({$0.floatValue})\n" + case .ObjectMapper: + propertyStr = "\tvar \(propertyKey) = [Float]()\n" + swiftInitStr = "\t\t\(propertyKey) <- map[\"\(propertyKey)\"]\n" + } + case .ArrayDouble: + switch langStruct.langType{ + case .ObjC: + propertyStr = "@@property (nonatomic, strong) NSArray *\(propertyKey);\n" + case .Swift, .HandyJSON: + propertyStr = "\tvar \(propertyKey) = [Double]()\n" + case .SwiftyJSON: + propertyStr = "\tvar \(propertyKey) = [Double]()\n" + swiftInitStr = "\t\t\(propertyKey) = json[\"\(propertyKey)\"].arrayValue.flatMap({$0.doubleValue})\n" + case .ObjectMapper: + propertyStr = "\tvar \(propertyKey) = [Double]()\n" + swiftInitStr = "\t\t\(propertyKey) <- map[\"\(propertyKey)\"]\n" + } + case .ArrayBool: + switch langStruct.langType{ + case .ObjC: + propertyStr = "@@property (nonatomic, strong) NSArray *\(propertyKey);\n" + case .Swift, .HandyJSON: + propertyStr = "\tvar \(propertyKey) = [Bool]()\n" + case .SwiftyJSON: + propertyStr = "\tvar \(propertyKey) = [Bool]()\n" + swiftInitStr = "\t\t\(propertyKey) = json[\"\(propertyKey)\"].arrayValue.flatMap({$0.boolValue})\n" + case .ObjectMapper: + propertyStr = "\tvar \(propertyKey) = [Bool]()\n" + swiftInitStr = "\t\t\(propertyKey) <- map[\"\(propertyKey)\"]\n" + } + case .ArrayDictionary: + switch langStruct.langType{ + case .ObjC: + propertyStr = "@@property (nonatomic, strong) NSArray<\(propertyKey.className(withPrefix: prefixStr)) *> *\(propertyKey);\n" + case .Swift, .HandyJSON: + propertyStr = "\tvar \(propertyKey) = [\(propertyKey.className(withPrefix: prefixStr))]()\n" + case .SwiftyJSON: + propertyStr = "\tvar \(propertyKey) = [\(propertyKey.className(withPrefix: prefixStr))]()\n" + swiftInitStr = "\t\t\(propertyKey) = json[\"\(propertyKey)\"].arrayValue.flatMap({$0.boolValue})\n" + case .ObjectMapper: + propertyStr = "\tvar \(propertyKey) = [\(propertyKey.className(withPrefix: prefixStr))]()\n" + swiftInitStr = "\t\t\(propertyKey) <- map[\"\(propertyKey)\"]\n" + } + } + + return (propertyStr, swiftInitStr) } + } diff --git a/JSONConverter/Classes/Main/MainView/MainViewController.swift b/JSONConverter/Classes/Main/MainView/MainViewController.swift index f4f8181..157e127 100644 --- a/JSONConverter/Classes/Main/MainView/MainViewController.swift +++ b/JSONConverter/Classes/Main/MainView/MainViewController.swift @@ -119,7 +119,6 @@ class MainViewController: NSViewController { } let transStructModel = LangStruct(langType: langTypeType, structType: structType) -// let classString = YWJsonParserUtils.shared.handleObjEngine(from: json, transModel: transStructModel, prefix: prefixName, rootClassName: rootClassName, superClassName: superClassField.stringValue) let classStr = YWJsonParserUtils.shared.handleEngine(frome: json, langStruct: transStructModel, prefix: prefixName, rootName: rootClassName, superName: superClassField.stringValue) diff --git a/JSONConverter/Classes/Main/YWAlertView.swift b/JSONConverter/Classes/Main/YWAlertView.swift deleted file mode 100644 index 23bf2d6..0000000 --- a/JSONConverter/Classes/Main/YWAlertView.swift +++ /dev/null @@ -1,14 +0,0 @@ -// -// YWAlertView.swift -// JSONConverter -// -// Created by 姚巍 on 2018/2/7. -// Copyright © 2018年 姚巍. All rights reserved. -// - -import Foundation -class YWAlertView { - func alertView() { - - } -} diff --git a/JSONConverter/Classes/Main/YWCommon.swift b/JSONConverter/Classes/Main/YWCommon.swift deleted file mode 100644 index 7c4b7ee..0000000 --- a/JSONConverter/Classes/Main/YWCommon.swift +++ /dev/null @@ -1,11 +0,0 @@ -// -// YWCommon.swift -// JSONConverter -// -// Created by 姚巍 on 2018/1/28. -// Copyright © 2018年 姚巍. All rights reserved. -// - -import Foundation - - diff --git a/JSONConverter/Classes/Main/YWJsonParserUtils.swift b/JSONConverter/Classes/Main/YWJsonParserUtils.swift index ef827c0..ff6930d 100644 --- a/JSONConverter/Classes/Main/YWJsonParserUtils.swift +++ b/JSONConverter/Classes/Main/YWJsonParserUtils.swift @@ -12,44 +12,35 @@ typealias YWstructTypeContent = (propertyStr: String, SwiftyJSONInitStr: String) class YWJsonParserUtils { - static let shared: YWJsonParserUtils = { - let manager = YWJsonParserUtils() - return manager - }() - - var allSubClassStr = "" - - var prefixStr = "" - - var superClassStr: String = "" - - var transStructModelType: LangStruct = LangStruct(langType: .Swift, structType: .struct) - - - ///------------------------------------------------------------------------------/// + static let shared: YWJsonParserUtils = { + let manager = YWJsonParserUtils() + return manager + }() private var file = YWFile() func handleEngine(frome obj: Any, langStruct: LangStruct, prefix: String, rootName: String, superName: String) -> String { - file = YWFile.file(withName: rootName, prefix: prefix, langStruct: langStruct) + file = YWFile.file(withName: rootName, prefix: prefix, langStruct: langStruct, superName: superName) + var content : YWContent? let propertyKey = rootName.propertyName() - switch obj { case let dic as [String: Any]: - let content = handleDic(propertyKey: propertyKey, dic: dic) - file.contents.append(content) + content = handleDic(propertyKey: propertyKey, dic: dic) case let arr as [Any]: - _ = handleArr(itemKey: propertyKey, arr: arr) - break + _ = handleArr(itemKey: propertyKey, arr: arr) default: assert(true, "对象类型不识别") } + if let content = content { + file.contents.append(content) + } + return file.toString() } private func handleDic(propertyKey: String, dic: [String: Any]) -> YWContent { - let content = YWContent(langStruct: file.langStruct) + let content = YWContent(propertyKey: propertyKey, langStruct: file.langStruct, superClass: file.superName, prefixStr: file.prefix) dic.forEach { (item) in let itemKey = item.key @@ -57,18 +48,19 @@ class YWJsonParserUtils { switch item.value { case _ as String: - propertyModel = YWProperty(propertyKey: itemKey, type: .String, langStruct: file.langStruct) + propertyModel = YWProperty(propertyKey: itemKey, type: .String, langStruct: file.langStruct, prefixStr: file.prefix) case let num as NSNumber: - propertyModel = YWProperty(propertyKey: itemKey, type: num.valueType(), langStruct: file.langStruct) + propertyModel = YWProperty(propertyKey: itemKey, type: num.valueType(), langStruct: file.langStruct, prefixStr: file.prefix) case let dic as [String: Any]: - propertyModel = YWProperty(propertyKey: itemKey, type: .Dictionary, langStruct: file.langStruct) + propertyModel = YWProperty(propertyKey: itemKey, type: .Dictionary, langStruct: file.langStruct, prefixStr: file.prefix) let content = handleDic(propertyKey: itemKey, dic: dic) file.contents.append(content) case let arr as [Any]: propertyModel = handleArr(itemKey: itemKey, arr: arr) + case _ as NSNull: + break default: assertionFailure("解析出现不识别类型") - break } if let propertyModel = propertyModel { @@ -84,12 +76,12 @@ class YWJsonParserUtils { var propertyModel: YWProperty? switch first { case _ as String: - propertyModel = YWProperty(propertyKey: itemKey, type: .ArrayString, langStruct: file.langStruct) + propertyModel = YWProperty(propertyKey: itemKey, type: .ArrayString, langStruct: file.langStruct, prefixStr: file.prefix) case let num as NSNumber: let type = YWPropertyType(rawValue: num.valueType().hashValue + 6)! - propertyModel = YWProperty(propertyKey: itemKey, type: type, langStruct: file.langStruct) + propertyModel = YWProperty(propertyKey: itemKey, type: type, langStruct: file.langStruct, prefixStr: file.prefix) case let dic as [String: Any]: - propertyModel = YWProperty(propertyKey: itemKey, type: .ArrayDictionary, langStruct: file.langStruct) + propertyModel = YWProperty(propertyKey: itemKey, type: .ArrayDictionary, langStruct: file.langStruct, prefixStr: file.prefix) let content = handleDic(propertyKey: itemKey, dic: dic) file.contents.append(content) default: @@ -103,143 +95,11 @@ class YWJsonParserUtils { return nil } - - - - ///------------------------------------------------------------------------------/// - - // func handleObjEngine(from obj: Any, transModel: LangStruct, prefix: String, rootClassName: String, superClassName: String) -> String{ - // allSubClassStr = "" - // prefixStr = prefix - // superClassStr = superClassName - // transStructModelType = transModel - // - // let key = handlePropertyName(propertyKey: rootClassName) - // - // switch obj { - // case let dic as Dictionary: - // _ = handleDictionary(from: dic, key: key, isArr: false) - // case let arr as Array: - // _ = handleArray(from: arr, key: key) - // default: - // assert(true, "对象类型不识别") - // } - // - // return allSubClassStr - // } - // - // private func handleNumber(from num: NSNumber, key: String, isArr: Bool) -> (String, String){ - // var numProStr = "" - // var swiftyJsonInitStr = "" - // if num.stringValue.contains(".") { - // numProStr = YWPropertyStrUtils.getCGFloatPropertyStr(transModel: transStructModelType, key: key, isArr: isArr) - // swiftyJsonInitStr = YWSwifyJSONInitUtils.getFloatInitStr(transModel: transStructModelType, key: key, isArr: isArr) - // }else{ - // numProStr = YWPropertyStrUtils.getIntPropertyStr(transModel: transStructModelType, key: key, isArr: isArr) - // swiftyJsonInitStr = YWSwifyJSONInitUtils.getIntInitStr(transModel: transStructModelType, key: key, isArr: isArr) - // } - // - // return (numProStr, swiftyJsonInitStr) - // } - // - // private func handleString(from str: String, key: String, isArr: Bool) -> (String, String){ - // let strProStr = YWPropertyStrUtils.getStringPropertyStr(transModel: transStructModelType, key: key, isArr: isArr) - // let swiftyJosnInitStr = YWSwifyJSONInitUtils.getStringInitStr(transModel: transStructModelType, key: key, isArr: isArr) - // return (strProStr, swiftyJosnInitStr) - // } - // - // private func handleBool(from str: Bool, key: String, isArr: Bool) -> (String, String){ - // let strProStr = YWPropertyStrUtils.getBoolPropertyStr(transModel: transStructModelType, key: key, isArr: isArr) - // let swiftyJosnInitStr = YWSwifyJSONInitUtils.getBoolInitStr(transModel: transStructModelType, key: key, isArr: isArr) - // return (strProStr, swiftyJosnInitStr) - // } - // - // private func handleDictionary(from dic: [String: Any], key: String, isArr: Bool) -> (String, String){ - // var propertyStr = "" - // var swiftyJsonInitStr = "" - // - // dic.forEach { (tuple) in - // let key = handlePropertyName(propertyKey: tuple.key) - // - // switch tuple.value { - // case let bool as Bool: - // let tupResult = handleBool(from: bool, key: key, isArr: false) - // propertyStr += tupResult.0 - // swiftyJsonInitStr += tupResult.1 - // case let num as NSNumber: - // let tupResult = handleNumber(from: num, key: key, isArr: false) - // propertyStr += tupResult.0 - // swiftyJsonInitStr += tupResult.1 - // case let str as String: - // let tupResult = handleString(from: str, key: key, isArr: false) - // propertyStr += tupResult.0 - // swiftyJsonInitStr += tupResult.1 - // case let dic as Dictionary: - // let tupResult = handleDictionary(from: dic, key: key, isArr: false) - // propertyStr += tupResult.0 - // swiftyJsonInitStr += tupResult.1 - // case let arr as Array: - // let tupResult = handleArray(from: arr, key: key) - // propertyStr += tupResult.0 - // swiftyJsonInitStr += tupResult.1 - // default: - // assert(true, "对象类型不识别") - // } - // - // } - // - // let subClassName = handleClassName(Key: key) - // let subClassStr = YWPropertyStrUtils.getClassStr(transModel: transStructModelType, className: subClassName, propertyStr: propertyStr, superClassName: superClassStr, swiftyJsonInitStr: swiftyJsonInitStr) - // allSubClassStr += subClassStr - // - // propertyStr = YWPropertyStrUtils.getObjectPropertyStr(transModel: transStructModelType, key: key, className: subClassName, isArr: isArr) - // - // swiftyJsonInitStr = YWSwifyJSONInitUtils.getObjInitStr(transModel: transStructModelType, key: key, className: subClassName, isArr: isArr) - // - // return (propertyStr, swiftyJsonInitStr) - // } - // - // private func handleArray(from arr: [Any], key: String) ->(String, String){ - // if let obj = arr.first { - // switch obj { - // case let num as NSNumber: - // return handleNumber(from: num, key: key, isArr: true) - // case let str as String: - // return handleString(from: str, key: key, isArr: true) - // case let dic as Dictionary: - // return handleDictionary(from: dic, key: key, isArr: true) - // default: - // assert(true, "数组对象类型不识别") - // return ("", "") - // } - // } - // return ("", "") - // } } - -extension YWJsonParserUtils { - private func handleClassName(Key: String) -> String { - let Name = Key as NSString - if Name.length > 0 { - let first = Name.substring(to: 1) - let other = Name.substring(from: 1) - return String(format: "%@%@%@", prefixStr, first.uppercased(), other) - } - - return Name as String - } - private func handlePropertyName(propertyKey: String) -> String { - let propertyName = propertyKey as NSString - if propertyName.length > 0 { - let first = propertyName.substring(to: 1) - let other = propertyName.substring(from: 1) - return String(format: "%@%@", first.lowercased(), other) - } - - return propertyName as String - } -} + + + diff --git a/JSONConverter/Classes/Main/YWPropertyStrUtils.swift b/JSONConverter/Classes/Main/YWPropertyStrUtils.swift deleted file mode 100644 index 05499cc..0000000 --- a/JSONConverter/Classes/Main/YWPropertyStrUtils.swift +++ /dev/null @@ -1,271 +0,0 @@ -// -// YWCommonStrUtils.swift -// JSONConverter -// -// Created by 姚巍 on 2018/2/4. -// Copyright © 2018年 姚巍. All rights reserved. -// - -import Foundation - -class YWPropertyStrUtils { - class func getCGFloatPropertyStr(transModel: LangStruct, key: String, isArr: Bool) -> String { - var str = "" - switch transModel.langType { - case .ObjC: - if isArr { - str = "@property (nonatomic, strong) NSArray *\(key);\n" - }else{ - str = "@property (nonatomic, assign) CGFloat \(key);\n" - } - case .Swift, .HandyJSON, .SwiftyJSON, .ObjectMapper: - if isArr { - str = "\tvar \(key) = [CGFloat]()\n" - }else { - str = "\tvar \(key): CGFloat = 0.0\n" - } - } - - return str - } - - class func getIntPropertyStr(transModel: LangStruct, key: String, isArr: Bool) -> String { - var str = "" - switch transModel.langType { - case .ObjC: - if isArr { - str = "@property (nonatomic, strong) NSArray *\(key);\n" - }else{ - str = "@property (nonatomic, assign) Int \(key);\n" - } - case .Swift, .HandyJSON, .SwiftyJSON, .ObjectMapper: - if isArr { - str = "\tvar \(key) = [Int]()\n" - }else { - str = "\tvar \(key): Int = 0\n" - } - - } - - return str - } - - - class func getStringPropertyStr(transModel: LangStruct, key: String, isArr: Bool) -> String { - var str = "" - switch transModel.langType { - case .ObjC: - if isArr { - str = "@property (nonatomic, strong) NSArray *\(key);\n" - }else{ - str = "@property (nonatomic, copy) NSString *\(key);\n" - } - case .Swift, .HandyJSON, .SwiftyJSON, .ObjectMapper: - if isArr { - str = "\tvar \(key) = [String]()\n" - }else{ - str = "\tvar \(key): String?\n" - } - - } - - return str - } - - class func getBoolPropertyStr(transModel: LangStruct, key: String, isArr: Bool) -> String { - var str = "" - switch transModel.langType { - case .ObjC: - if isArr { - str = "@property (nonatomic, strong) NSArray *\(key);\n" - }else{ - str = "@property (nonatomic, assign) BOOL \(key);\n" - } - case .Swift, .HandyJSON, .SwiftyJSON, .ObjectMapper: - if isArr { - str = "\tvar \(key) = [Bool]()\n" - }else{ - str = "\tvar \(key): Bool = false\n" - } - - } - - return str - } - - class func getObjectPropertyStr(transModel: LangStruct, key: String, className: String, isArr: Bool) -> String { - var str = "" - switch transModel.langType { - case .ObjC: - if isArr { - str = "@property (nonatomic, strong) NSArray<\(className) *> *\(key);\n" - }else{ - str = "@property (nonatomic, strong) \(className) *\(key);\n" - } - case .Swift, .HandyJSON, .SwiftyJSON, .ObjectMapper: - if isArr { - str = "\tvar \(key) = [\(className)]()\n" - }else{ - str = "\tvar \(key): \(className)?\n" - } - - } - - return str - } - - - class func getClassStr(transModel: LangStruct, className: String, propertyStr: String, superClassName: String, swiftyJsonInitStr: String) -> String { - var str = "" - - let superClassStr = getSuperClassStr(transModel: transModel, superClassStr: superClassName) - - if transModel.langType == .ObjC { - str = "\n@interface \(className)\(superClassStr)\n\(propertyStr)\n@end\n" - }else { - switch transModel.structType { - case .class: - switch transModel.langType { - case .Swift: - str = "\nclass \(className)\(superClassStr) {\n\(propertyStr)\n}\n" - case .HandyJSON: - str = "\nclass \(className)\(superClassStr) {\n\(propertyStr)\n\trequired init() {}\n}\n" - case .SwiftyJSON: - str = "\nclass \(className)\(superClassStr) {\n\(propertyStr)\n\tinit(json: JSON) {\n\(swiftyJsonInitStr)\t}\n}\n" - case .ObjectMapper: - str = "\nclass \(className)\(superClassStr) {\n\(propertyStr)\n\trequired init?(map: Map) {}\n\n\tfunc mapping(map: Map) {\n\(swiftyJsonInitStr)\t}\n}\n" - default: - break - } - case .struct: - switch transModel.langType { - case .Swift, .HandyJSON: - str = "\nstruct \(className)\(superClassStr) {\n\(propertyStr)\n}\n" - case .SwiftyJSON: - str = "\nstruct \(className)\(superClassStr) {\n\(propertyStr)\n\tinit(json: JSON) {\n\(swiftyJsonInitStr)\t}\n}\n" - case .ObjectMapper: - str = "\nstruct \(className)\(superClassStr) {\n\(propertyStr)\n\tinit?(map: Map) {}\n\n\tmutating func mapping(map: Map) {\n\(swiftyJsonInitStr)\t}\n}\n" - default: - break - } - } - } - - return str - } - - private class func getSuperClassStr(transModel: LangStruct, superClassStr: String) -> String { - var superClassPart: String = "" - - switch transModel.langType { - case .HandyJSON: - superClassPart = superClassStr.isEmpty ? ": HandyJSON" : ": \(superClassStr)" - case .Swift, .SwiftyJSON: - superClassPart = superClassStr.isEmpty ? "" : ": \(superClassStr)" - case .ObjC: - superClassPart = superClassStr.isEmpty ? ": NSObject" : ": \(superClassStr)" - case .ObjectMapper: - superClassPart = superClassStr.isEmpty ? ": Mappable" : ": \(superClassStr)" - break - } - - return superClassPart - } -} - - -class YWSwifyJSONInitUtils { - class func getFloatInitStr(transModel: LangStruct, key: String, isArr: Bool) -> String { - var str = "" - switch transModel.langType { - case .SwiftyJSON: - if isArr { - str = "\t\t\(key) = json[\"\(key)\"].arrayValue.flatMap({$0.doubleValue})\n" - }else { - str = "\t\t\(key) = json[\"\(key)\"].floatValue\n" - } - case .ObjectMapper: - str = "\t\t\(key) <- map[\"\(key)\"]\n" - default: - break - } - - return str - } - - class func getStringInitStr(transModel: LangStruct, key: String, isArr: Bool) -> String { - var str = "" - switch transModel.langType { - case .SwiftyJSON: - if isArr { - str = "\t\t\(key) = json[\"\(key)\"].arrayValue.flatMap({$0.stringValue})\n" - }else { - str = "\t\t\(key) = json[\"\(key)\"].stringValue\n" - } - case .ObjectMapper: - str = "\t\t\(key) <- map[\"\(key)\"]\n" - default: - break - } - - return str - } - - class func getIntInitStr(transModel: LangStruct, key: String, isArr: Bool) -> String { - var str = "" - switch transModel.langType { - case .SwiftyJSON: - if isArr { - str = "\t\t\(key) = json[\"\(key)\"].arrayValue.flatMap({$0.intValue})\n" - }else { - str = "\t\t\(key) = json[\"\(key)\"].intValue\n" - } - case .ObjectMapper: - str = "\t\t\(key) <- map[\"\(key)\"]\n" - default: - break - } - - return str - } - - class func getBoolInitStr(transModel: LangStruct, key: String, isArr: Bool) -> String { - var str = "" - switch transModel.langType { - case .SwiftyJSON: - if isArr { - str = "\t\t\(key) = json[\"\(key)\"].arrayValue.flatMap({$0.boolValue})\n" - }else { - str = "\t\t\(key) = json[\"\(key)\"].boolValue\n" - } - case .ObjectMapper: - str = "\t\t\(key) <- map[\"\(key)\"]\n" - default: - break - } - - return str - } - - - class func getObjInitStr(transModel: LangStruct, key: String, className: String, isArr: Bool) -> String { - var str = "" - switch transModel.langType { - case .SwiftyJSON: - if isArr { - str = "\t\t\(key) = json[\"\(key)\"].arrayValue.flatMap({\(className)(json: $0)})\n" - }else { - str = "\t\t\(key) = \(className)(json: json[\"\(key)\"])\n" - } - case .ObjectMapper: - str = "\t\t\(key) <- map[\"\(key)\"]\n" - default: - break - } - - return str - } - - -} - diff --git a/JSONConverter/Classes/Vendor/Extension.swift b/JSONConverter/Classes/Vendor/Extension.swift index 32f4bd9..4d993df 100644 --- a/JSONConverter/Classes/Vendor/Extension.swift +++ b/JSONConverter/Classes/Vendor/Extension.swift @@ -14,7 +14,7 @@ extension String { } func className(withPrefix prefix: String) -> String { - return (prefix + self).uppercaseFirstChar() + return prefix + self.uppercaseFirstChar() } func lowercaseFirstChar() -> String { diff --git a/JSONConverterUITests/Info.plist b/JSONConverterUITests/Info.plist new file mode 100644 index 0000000..6c40a6c --- /dev/null +++ b/JSONConverterUITests/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/JSONConverterUITests/JSONConverterUITests.swift b/JSONConverterUITests/JSONConverterUITests.swift new file mode 100644 index 0000000..e481ca2 --- /dev/null +++ b/JSONConverterUITests/JSONConverterUITests.swift @@ -0,0 +1,36 @@ +// +// JSONConverterUITests.swift +// JSONConverterUITests +// +// Created by 姚巍 on 2018/2/8. +// Copyright © 2018年 姚巍. All rights reserved. +// + +import XCTest + +class JSONConverterUITests: XCTestCase { + + override func setUp() { + super.setUp() + + // Put setup code here. This method is called before the invocation of each test method in the class. + + // In UI tests it is usually best to stop immediately when a failure occurs. + continueAfterFailure = false + // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method. + XCUIApplication().launch() + + // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testExample() { + // Use recording to get started writing UI tests. + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + +}