Skip to content

Commit

Permalink
code optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
vvkeep committed Feb 8, 2018
1 parent 7f62239 commit edb445c
Show file tree
Hide file tree
Showing 13 changed files with 463 additions and 497 deletions.
134 changes: 118 additions & 16 deletions JSONConverter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 = "<group>"; };
7B45DAED202A95BE007E8D56 /* MainViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainViewController.xib; sourceTree = "<group>"; };
7B45DAEE202A95BE007E8D56 /* MainWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainWindowController.swift; sourceTree = "<group>"; };
7B45DAEF202A95BE007E8D56 /* MainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = "<group>"; };
7B45DAF0202A95BE007E8D56 /* YWPropertyStrUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YWPropertyStrUtils.swift; sourceTree = "<group>"; };
7B45DAF1202A95BE007E8D56 /* YWCommon.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = YWCommon.swift; sourceTree = "<group>"; };
7B45DAF2202A95BE007E8D56 /* MainWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainWindowController.xib; sourceTree = "<group>"; };
7B45DAF4202A95BE007E8D56 /* Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extension.swift; sourceTree = "<group>"; };
7B45DAF5202A95BE007E8D56 /* JSONConverter.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = JSONConverter.entitlements; sourceTree = "<group>"; };
Expand All @@ -51,8 +56,9 @@
7BD7FED6202AC1E80003AE80 /* NoodleLineNumberMarker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NoodleLineNumberMarker.m; sourceTree = "<group>"; };
7BD7FED9202AC7C10003AE80 /* YWContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YWContent.swift; sourceTree = "<group>"; };
7BD7FEDB202AC7EB0003AE80 /* YWProperty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YWProperty.swift; sourceTree = "<group>"; };
7BD7FEDF202AD1470003AE80 /* YWAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YWAlertView.swift; sourceTree = "<group>"; };
7BD7FEE2202AD8A90003AE80 /* YWConstructor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YWConstructor.swift; sourceTree = "<group>"; };
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 = "<group>"; };
7BDF2973202BDB7D00B7E2F5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -63,6 +69,13 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
7BDF296C202BDB7C00B7E2F5 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
Expand Down Expand Up @@ -95,9 +108,6 @@
7BD7FEE1202AD1F30003AE80 /* MainView */,
7BD7FEDE202AC85B0003AE80 /* FileContent */,
7B45DAEC202A95BE007E8D56 /* YWJsonParserUtils.swift */,
7B45DAF0202A95BE007E8D56 /* YWPropertyStrUtils.swift */,
7B45DAF1202A95BE007E8D56 /* YWCommon.swift */,
7BD7FEDF202AD1470003AE80 /* YWAlertView.swift */,
);
path = Main;
sourceTree = "<group>";
Expand All @@ -115,6 +125,7 @@
isa = PBXGroup;
children = (
7B45DAE9202A95BE007E8D56 /* JSONConverter */,
7BDF2970202BDB7D00B7E2F5 /* JSONConverterUITests */,
7B4B5EAB201B87A10098712B /* Products */,
);
sourceTree = "<group>";
Expand All @@ -123,6 +134,7 @@
isa = PBXGroup;
children = (
7B4B5EAA201B87A10098712B /* JSONConverter.app */,
7BDF296F202BDB7C00B7E2F5 /* JSONConverterUITests.xctest */,
);
name = Products;
sourceTree = "<group>";
Expand All @@ -144,7 +156,6 @@
7B45DB0E202AA572007E8D56 /* YWFile.swift */,
7BD7FED9202AC7C10003AE80 /* YWContent.swift */,
7BD7FEDB202AC7EB0003AE80 /* YWProperty.swift */,
7BD7FEE2202AD8A90003AE80 /* YWConstructor.swift */,
);
path = FileContent;
sourceTree = "<group>";
Expand All @@ -160,6 +171,15 @@
path = MainView;
sourceTree = "<group>";
};
7BDF2970202BDB7D00B7E2F5 /* JSONConverterUITests */ = {
isa = PBXGroup;
children = (
7BDF2971202BDB7D00B7E2F5 /* JSONConverterUITests.swift */,
7BDF2973202BDB7D00B7E2F5 /* Info.plist */,
);
path = JSONConverterUITests;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand All @@ -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 */
Expand All @@ -201,6 +239,11 @@
};
};
};
7BDF296E202BDB7C00B7E2F5 = {
CreatedOnToolsVersion = 9.2;
ProvisioningStyle = Automatic;
TestTargetID = 7B4B5EA9201B87A10098712B;
};
};
};
buildConfigurationList = 7B4B5EA5201B87A10098712B /* Build configuration list for PBXProject "JSONConverter" */;
Expand All @@ -217,6 +260,7 @@
projectRoot = "";
targets = (
7B4B5EA9201B87A10098712B /* JSONConverter */,
7BDF296E202BDB7C00B7E2F5 /* JSONConverterUITests */,
);
};
/* End PBXProject section */
Expand All @@ -234,22 +278,25 @@
);
runOnlyForDeploymentPostprocessing = 0;
};
7BDF296D202BDB7C00B7E2F5 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
7B4B5EA6201B87A10098712B /* Sources */ = {
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 */,
Expand All @@ -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;
Expand Down Expand Up @@ -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 */
Expand All @@ -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 */;
Expand Down
12 changes: 0 additions & 12 deletions JSONConverter/Classes/Main/FileContent/YWConstructor.swift

This file was deleted.

85 changes: 83 additions & 2 deletions JSONConverter/Classes/Main/FileContent/YWContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Loading

0 comments on commit edb445c

Please sign in to comment.