From 8fdaaa6278db8ec9abda722cfaa09913a7f884e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=80=E1=85=B5=E1=86=AF?= =?UTF-8?q?=E1=84=92=E1=85=A9?= Date: Tue, 16 Aug 2022 17:24:01 +0900 Subject: [PATCH] spm spm --- .gitignore | 9 + .../PKHParserTest.xcodeproj}/project.pbxproj | 53 ++- .../contents.xcworkspacedata | 0 .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../PKHParserTest}/AppDelegate.swift | 0 .../AccentColor.colorset/Contents.json | 0 .../AppIcon.appiconset/Contents.json | 0 .../Assets.xcassets/Contents.json | 0 .../Base.lproj/LaunchScreen.storyboard | 0 .../PKHParserTest}/Base.lproj/Main.storyboard | 0 .../PKHParserTest}/Info.plist | 0 .../PKHParserTest}/SceneDelegate.swift | 0 .../PKHParserTest}/ViewController.swift | 0 .../PKHParserTestTests}/Info.plist | 0 .../PKHParserTestTests.swift | 0 .../PKHParserTestUITests}/Info.plist | 0 .../PKHParserTestUITests.swift | 0 .../TestClass}/Test.swift | 0 .../TestClass}/TestImage.swift | 0 .../TestClass}/TestText.swift | 0 .../TestClass}/Widget.swift | 0 .../TestClass}/WindowT.swift | 0 .../TestClass}/WindowsDataListItem.swift | 0 Package.swift | 28 ++ README.md | 381 ++++++++++++++++++ .../PKHJsonParser}/NSObjectExtensions.swift | 0 .../PKHJsonParser/PKHJsonParser.swift | 0 .../PKHJsonParser}/StringExtensions.swift | 0 .../PKHJsonParserTests.swift | 11 + 29 files changed, 470 insertions(+), 20 deletions(-) create mode 100644 .gitignore rename {PKHParserTest.xcodeproj => Example-iOS/PKHParserTest.xcodeproj}/project.pbxproj (93%) rename {PKHParserTest.xcodeproj => Example-iOS/PKHParserTest.xcodeproj}/project.xcworkspace/contents.xcworkspacedata (100%) create mode 100644 Example-iOS/PKHParserTest.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename {PKHParserTest => Example-iOS/PKHParserTest}/AppDelegate.swift (100%) rename {PKHParserTest => Example-iOS/PKHParserTest}/Assets.xcassets/AccentColor.colorset/Contents.json (100%) rename {PKHParserTest => Example-iOS/PKHParserTest}/Assets.xcassets/AppIcon.appiconset/Contents.json (100%) rename {PKHParserTest => Example-iOS/PKHParserTest}/Assets.xcassets/Contents.json (100%) rename {PKHParserTest => Example-iOS/PKHParserTest}/Base.lproj/LaunchScreen.storyboard (100%) rename {PKHParserTest => Example-iOS/PKHParserTest}/Base.lproj/Main.storyboard (100%) rename {PKHParserTest => Example-iOS/PKHParserTest}/Info.plist (100%) rename {PKHParserTest => Example-iOS/PKHParserTest}/SceneDelegate.swift (100%) rename {PKHParserTest => Example-iOS/PKHParserTest}/ViewController.swift (100%) rename {PKHParserTestTests => Example-iOS/PKHParserTestTests}/Info.plist (100%) rename {PKHParserTestTests => Example-iOS/PKHParserTestTests}/PKHParserTestTests.swift (100%) rename {PKHParserTestUITests => Example-iOS/PKHParserTestUITests}/Info.plist (100%) rename {PKHParserTestUITests => Example-iOS/PKHParserTestUITests}/PKHParserTestUITests.swift (100%) rename {TestClass => Example-iOS/TestClass}/Test.swift (100%) rename {TestClass => Example-iOS/TestClass}/TestImage.swift (100%) rename {TestClass => Example-iOS/TestClass}/TestText.swift (100%) rename {TestClass => Example-iOS/TestClass}/Widget.swift (100%) rename {TestClass => Example-iOS/TestClass}/WindowT.swift (100%) rename {TestClass => Example-iOS/TestClass}/WindowsDataListItem.swift (100%) create mode 100644 Package.swift create mode 100644 README.md rename {PKHParser => Sources/PKHJsonParser}/NSObjectExtensions.swift (100%) rename PKHParser/PKHParser.swift => Sources/PKHJsonParser/PKHJsonParser.swift (100%) rename {PKHParser => Sources/PKHJsonParser}/StringExtensions.swift (100%) create mode 100644 Tests/PKHJsonParserTests/PKHJsonParserTests.swift diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3b29812 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj +xcuserdata/ +DerivedData/ +.swiftpm/config/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/PKHParserTest.xcodeproj/project.pbxproj b/Example-iOS/PKHParserTest.xcodeproj/project.pbxproj similarity index 93% rename from PKHParserTest.xcodeproj/project.pbxproj rename to Example-iOS/PKHParserTest.xcodeproj/project.pbxproj index 71c1654..7bed9fb 100644 --- a/PKHParserTest.xcodeproj/project.pbxproj +++ b/Example-iOS/PKHParserTest.xcodeproj/project.pbxproj @@ -7,6 +7,10 @@ objects = { /* Begin PBXBuildFile section */ + 20AE480628AB897100EFBC9A /* PKHJsonParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20AE480328AB897100EFBC9A /* PKHJsonParser.swift */; }; + 20AE480728AB897100EFBC9A /* StringExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20AE480428AB897100EFBC9A /* StringExtensions.swift */; }; + 20AE480828AB897100EFBC9A /* NSObjectExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 20AE480528AB897100EFBC9A /* NSObjectExtensions.swift */; }; + 20AE480A28AB8B5C00EFBC9A /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 20AE480928AB8B5C00EFBC9A /* README.md */; }; 52C9905A26C0B2FD009F3453 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52C9905926C0B2FD009F3453 /* AppDelegate.swift */; }; 52C9905C26C0B2FD009F3453 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52C9905B26C0B2FD009F3453 /* SceneDelegate.swift */; }; 52C9905E26C0B2FD009F3453 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52C9905D26C0B2FD009F3453 /* ViewController.swift */; }; @@ -15,9 +19,6 @@ 52C9906626C0B2FE009F3453 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 52C9906426C0B2FE009F3453 /* LaunchScreen.storyboard */; }; 52C9907126C0B2FE009F3453 /* PKHParserTestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52C9907026C0B2FE009F3453 /* PKHParserTestTests.swift */; }; 52C9907C26C0B2FE009F3453 /* PKHParserTestUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52C9907B26C0B2FE009F3453 /* PKHParserTestUITests.swift */; }; - 52C9908D26C0B354009F3453 /* StringExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52C9908A26C0B354009F3453 /* StringExtensions.swift */; }; - 52C9908E26C0B354009F3453 /* PKHParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52C9908B26C0B354009F3453 /* PKHParser.swift */; }; - 52C9908F26C0B354009F3453 /* NSObjectExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52C9908C26C0B354009F3453 /* NSObjectExtensions.swift */; }; 52C9909726C0B390009F3453 /* Test.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52C9909126C0B390009F3453 /* Test.swift */; }; 52C9909826C0B390009F3453 /* TestImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52C9909226C0B390009F3453 /* TestImage.swift */; }; 52C9909926C0B390009F3453 /* WindowsDataListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52C9909326C0B390009F3453 /* WindowsDataListItem.swift */; }; @@ -44,6 +45,10 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 20AE480328AB897100EFBC9A /* PKHJsonParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHJsonParser.swift; sourceTree = ""; }; + 20AE480428AB897100EFBC9A /* StringExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtensions.swift; sourceTree = ""; }; + 20AE480528AB897100EFBC9A /* NSObjectExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSObjectExtensions.swift; sourceTree = ""; }; + 20AE480928AB8B5C00EFBC9A /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; 52C9905626C0B2FD009F3453 /* PKHParserTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = PKHParserTest.app; sourceTree = BUILT_PRODUCTS_DIR; }; 52C9905926C0B2FD009F3453 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 52C9905B26C0B2FD009F3453 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -58,9 +63,6 @@ 52C9907726C0B2FE009F3453 /* PKHParserTestUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PKHParserTestUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 52C9907B26C0B2FE009F3453 /* PKHParserTestUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PKHParserTestUITests.swift; sourceTree = ""; }; 52C9907D26C0B2FE009F3453 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 52C9908A26C0B354009F3453 /* StringExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtensions.swift; sourceTree = ""; }; - 52C9908B26C0B354009F3453 /* PKHParser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKHParser.swift; sourceTree = ""; }; - 52C9908C26C0B354009F3453 /* NSObjectExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSObjectExtensions.swift; sourceTree = ""; }; 52C9909126C0B390009F3453 /* Test.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Test.swift; sourceTree = ""; }; 52C9909226C0B390009F3453 /* TestImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestImage.swift; sourceTree = ""; }; 52C9909326C0B390009F3453 /* WindowsDataListItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WindowsDataListItem.swift; sourceTree = ""; }; @@ -94,11 +96,31 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 20AE480128AB897100EFBC9A /* Sources */ = { + isa = PBXGroup; + children = ( + 20AE480228AB897100EFBC9A /* PKHJsonParser */, + ); + name = Sources; + path = ../Sources; + sourceTree = ""; + }; + 20AE480228AB897100EFBC9A /* PKHJsonParser */ = { + isa = PBXGroup; + children = ( + 20AE480328AB897100EFBC9A /* PKHJsonParser.swift */, + 20AE480428AB897100EFBC9A /* StringExtensions.swift */, + 20AE480528AB897100EFBC9A /* NSObjectExtensions.swift */, + ); + path = PKHJsonParser; + sourceTree = ""; + }; 52C9904D26C0B2FD009F3453 = { isa = PBXGroup; children = ( + 20AE480928AB8B5C00EFBC9A /* README.md */, + 20AE480128AB897100EFBC9A /* Sources */, 52C9909026C0B390009F3453 /* TestClass */, - 52C9908926C0B354009F3453 /* PKHParser */, 52C9905826C0B2FD009F3453 /* PKHParserTest */, 52C9906F26C0B2FE009F3453 /* PKHParserTestTests */, 52C9907A26C0B2FE009F3453 /* PKHParserTestUITests */, @@ -148,16 +170,6 @@ path = PKHParserTestUITests; sourceTree = ""; }; - 52C9908926C0B354009F3453 /* PKHParser */ = { - isa = PBXGroup; - children = ( - 52C9908A26C0B354009F3453 /* StringExtensions.swift */, - 52C9908B26C0B354009F3453 /* PKHParser.swift */, - 52C9908C26C0B354009F3453 /* NSObjectExtensions.swift */, - ); - path = PKHParser; - sourceTree = ""; - }; 52C9909026C0B390009F3453 /* TestClass */ = { isa = PBXGroup; children = ( @@ -276,6 +288,7 @@ files = ( 52C9906626C0B2FE009F3453 /* LaunchScreen.storyboard in Resources */, 52C9906326C0B2FE009F3453 /* Assets.xcassets in Resources */, + 20AE480A28AB8B5C00EFBC9A /* README.md in Resources */, 52C9906126C0B2FD009F3453 /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -302,17 +315,17 @@ buildActionMask = 2147483647; files = ( 52C9909A26C0B390009F3453 /* WindowT.swift in Sources */, - 52C9908D26C0B354009F3453 /* StringExtensions.swift in Sources */, 52C9905E26C0B2FD009F3453 /* ViewController.swift in Sources */, + 20AE480628AB897100EFBC9A /* PKHJsonParser.swift in Sources */, 52C9905A26C0B2FD009F3453 /* AppDelegate.swift in Sources */, 52C9909B26C0B390009F3453 /* TestText.swift in Sources */, 52C9909726C0B390009F3453 /* Test.swift in Sources */, - 52C9908E26C0B354009F3453 /* PKHParser.swift in Sources */, + 20AE480728AB897100EFBC9A /* StringExtensions.swift in Sources */, 52C9909826C0B390009F3453 /* TestImage.swift in Sources */, 52C9905C26C0B2FD009F3453 /* SceneDelegate.swift in Sources */, - 52C9908F26C0B354009F3453 /* NSObjectExtensions.swift in Sources */, 52C9909926C0B390009F3453 /* WindowsDataListItem.swift in Sources */, 52C9909C26C0B390009F3453 /* Widget.swift in Sources */, + 20AE480828AB897100EFBC9A /* NSObjectExtensions.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/PKHParserTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Example-iOS/PKHParserTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata similarity index 100% rename from PKHParserTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename to Example-iOS/PKHParserTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/Example-iOS/PKHParserTest.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Example-iOS/PKHParserTest.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Example-iOS/PKHParserTest.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/PKHParserTest/AppDelegate.swift b/Example-iOS/PKHParserTest/AppDelegate.swift similarity index 100% rename from PKHParserTest/AppDelegate.swift rename to Example-iOS/PKHParserTest/AppDelegate.swift diff --git a/PKHParserTest/Assets.xcassets/AccentColor.colorset/Contents.json b/Example-iOS/PKHParserTest/Assets.xcassets/AccentColor.colorset/Contents.json similarity index 100% rename from PKHParserTest/Assets.xcassets/AccentColor.colorset/Contents.json rename to Example-iOS/PKHParserTest/Assets.xcassets/AccentColor.colorset/Contents.json diff --git a/PKHParserTest/Assets.xcassets/AppIcon.appiconset/Contents.json b/Example-iOS/PKHParserTest/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from PKHParserTest/Assets.xcassets/AppIcon.appiconset/Contents.json rename to Example-iOS/PKHParserTest/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/PKHParserTest/Assets.xcassets/Contents.json b/Example-iOS/PKHParserTest/Assets.xcassets/Contents.json similarity index 100% rename from PKHParserTest/Assets.xcassets/Contents.json rename to Example-iOS/PKHParserTest/Assets.xcassets/Contents.json diff --git a/PKHParserTest/Base.lproj/LaunchScreen.storyboard b/Example-iOS/PKHParserTest/Base.lproj/LaunchScreen.storyboard similarity index 100% rename from PKHParserTest/Base.lproj/LaunchScreen.storyboard rename to Example-iOS/PKHParserTest/Base.lproj/LaunchScreen.storyboard diff --git a/PKHParserTest/Base.lproj/Main.storyboard b/Example-iOS/PKHParserTest/Base.lproj/Main.storyboard similarity index 100% rename from PKHParserTest/Base.lproj/Main.storyboard rename to Example-iOS/PKHParserTest/Base.lproj/Main.storyboard diff --git a/PKHParserTest/Info.plist b/Example-iOS/PKHParserTest/Info.plist similarity index 100% rename from PKHParserTest/Info.plist rename to Example-iOS/PKHParserTest/Info.plist diff --git a/PKHParserTest/SceneDelegate.swift b/Example-iOS/PKHParserTest/SceneDelegate.swift similarity index 100% rename from PKHParserTest/SceneDelegate.swift rename to Example-iOS/PKHParserTest/SceneDelegate.swift diff --git a/PKHParserTest/ViewController.swift b/Example-iOS/PKHParserTest/ViewController.swift similarity index 100% rename from PKHParserTest/ViewController.swift rename to Example-iOS/PKHParserTest/ViewController.swift diff --git a/PKHParserTestTests/Info.plist b/Example-iOS/PKHParserTestTests/Info.plist similarity index 100% rename from PKHParserTestTests/Info.plist rename to Example-iOS/PKHParserTestTests/Info.plist diff --git a/PKHParserTestTests/PKHParserTestTests.swift b/Example-iOS/PKHParserTestTests/PKHParserTestTests.swift similarity index 100% rename from PKHParserTestTests/PKHParserTestTests.swift rename to Example-iOS/PKHParserTestTests/PKHParserTestTests.swift diff --git a/PKHParserTestUITests/Info.plist b/Example-iOS/PKHParserTestUITests/Info.plist similarity index 100% rename from PKHParserTestUITests/Info.plist rename to Example-iOS/PKHParserTestUITests/Info.plist diff --git a/PKHParserTestUITests/PKHParserTestUITests.swift b/Example-iOS/PKHParserTestUITests/PKHParserTestUITests.swift similarity index 100% rename from PKHParserTestUITests/PKHParserTestUITests.swift rename to Example-iOS/PKHParserTestUITests/PKHParserTestUITests.swift diff --git a/TestClass/Test.swift b/Example-iOS/TestClass/Test.swift similarity index 100% rename from TestClass/Test.swift rename to Example-iOS/TestClass/Test.swift diff --git a/TestClass/TestImage.swift b/Example-iOS/TestClass/TestImage.swift similarity index 100% rename from TestClass/TestImage.swift rename to Example-iOS/TestClass/TestImage.swift diff --git a/TestClass/TestText.swift b/Example-iOS/TestClass/TestText.swift similarity index 100% rename from TestClass/TestText.swift rename to Example-iOS/TestClass/TestText.swift diff --git a/TestClass/Widget.swift b/Example-iOS/TestClass/Widget.swift similarity index 100% rename from TestClass/Widget.swift rename to Example-iOS/TestClass/Widget.swift diff --git a/TestClass/WindowT.swift b/Example-iOS/TestClass/WindowT.swift similarity index 100% rename from TestClass/WindowT.swift rename to Example-iOS/TestClass/WindowT.swift diff --git a/TestClass/WindowsDataListItem.swift b/Example-iOS/TestClass/WindowsDataListItem.swift similarity index 100% rename from TestClass/WindowsDataListItem.swift rename to Example-iOS/TestClass/WindowsDataListItem.swift diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..9f51ff4 --- /dev/null +++ b/Package.swift @@ -0,0 +1,28 @@ +// swift-tools-version: 5.6 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "PKHJsonParser", + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "PKHJsonParser", + targets: ["PKHJsonParser"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "PKHJsonParser", + dependencies: []), + .testTarget( + name: "PKHJsonParserTests", + dependencies: ["PKHJsonParser"]), + ] +) diff --git a/README.md b/README.md new file mode 100644 index 0000000..64db31e --- /dev/null +++ b/README.md @@ -0,0 +1,381 @@ +# PKHParser + +πŸ‘» Easy Parsing JSON to Swift + +## λͺ©ν‘œ +> ν΄λΌμ΄μ–ΈνŠΈ 개발 μ‹œ json νŒŒμ‹± κ³Όμ •μ—μ„œ μƒκΈ°λŠ” μ‹€μˆ˜λ₯Ό λ°©μ§€ν•˜κ³  λΆˆν•„μš”ν•œ 반볡 μž‘μ—…μ„ 쀄여 νŒŒμ‹± 과정을 μžλ™ν™” + + + + +
+ +## Test +``` +let jsonString = """ +{"widget": { + "testDebug": "on", + "stringArray": ["a","b","c"], + "windowT": { + "title": "Sample Konfabulator Widget", + "name": "main_window", + "width": 500, + "height": 500 + }, + "testImage": { + "src": "Images/Sun.png", + "name": "sun1", + "hOffset": 250, + "vOffset": 250, + "alignment": "center" + }, + "testText": { + "data": "Click Here", + "size": 36, + "style": "bold", + "name": "text1", + "hOffset": 250, + "vOffset": 100, + "alignment": "center", + "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" + } +}, +"windowsDataList": [{ + "title": "Sample Konfabulator Widget", + "name": "main_window", + "width": 500, + "height": 500 + }, + { + "title": "Sample Konfabulator Widget", + "name": "main_window", + "width": 500, + "height": 500 + }, + { + "title": "Sample Konfabulator Widget", + "name": "main_window", + "width": 500, + "height": 500 + }], +"size": 36, +"style": "bold", +"name": "text1", +"hOffset": 250, +"vOffset": 100, +"alignment": "center", +"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" +} +""" + let dic = jsonString.toDictionary() + let obj = Test(map: dic) + print(obj) + + Test.parser(map: dic!) { (obj: Test) in + print(obj) + } + +πŸŽƒ RESULT +======== Test ======== + windowsList: ---- Array(3) ---- + [0] ======== WindowsDataListItem ======== + name: main_window + title: Sample Konfabulator Widget + height: 500 + width: 500 + ======================================= + [1] ======== WindowsDataListItem ======== + name: main_window + title: Sample Konfabulator Widget + height: 500 + width: 500 + ======================================= + [2] ======== WindowsDataListItem ======== + name: main_window + title: Sample Konfabulator Widget + height: 500 + width: 500 + ======================================= + --------------------------- + widgetData: ======== Widget ======== + stringArray: ---- Array(3) ---- + [0] a + [1] b + [2] c + --------------------------- + windowT: ======== WindowT ======== + name: main_window + title: Sample Konfabulator Widget + height: 500 + width: 500 + ======================================= + testImage: ======== TestImage ======== + alignment: center + name: sun1 + src: Images/Sun.png + hOffset: 250 + vOffset: 250 + ======================================= + testText: ======== TestText ======== + name: text1 + data: Click Here + onMouseUp: sun1.opacity = (sun1.opacity / 100) * 90; + alignment: center + size: 36 + style: bold + hOffset: 250 + vOffset: 100 + ======================================= + testDebug: on + ======================================= + onMouseUp: sun1.opacity = (sun1.opacity / 100) * 90; + name: text1 + alignment: center + size: 36 + style: bold + hOffset: 250 + vOffset: 100 + ======================================= + +``` + +## Core Functions + + +``` + +class Test : PKHParser { + + var widgetData: Widget? + var windowsList = [WindowsDataListItem]() + var style: String = "" + var onMouseUp: String = "" + var size: Int = 0 + var hOffset: Int = 0 + var vOffset: Int = 0 + var alignment: String = "" + var name: String = "" + + // json key ans ivar Different + override func getDataMap() -> [ParserMap]? { + return [ParserMap(ivar: "windowsList", jsonKey: "windowsDataList"), + ParserMap(ivar: "widgetData", jsonKey: "widget")] + } + + override func beforeParsed(dic: [String : Any], anyData: Any?) { + super.beforeParsed(dic: dic, anyData: anyData) + + // Parsering before + + } + + override func afterParsed(_ dic: [String : Any]) { + super.afterParsed(dic) + + // Parsering after + + } +} + +@objcMembers open class PKHParser: NSObject { + + public override init() { + super.init() + } + + required public init(map dic: [String: Any]?, anyData: Any? = nil, serializeKey: String? = nil) { + super.init() + guard let dic = dic else { return } + self.beforeParsed(dic:dic, anyData:anyData) + if let key = serializeKey, let dataDic = dic[key] as? [String: Any] { + self.setSerialize(map: dataDic, anyData: anyData) + self.afterParsed(dataDic) + } + else { + self.setSerialize(map: dic, anyData: anyData) + self.afterParsed(dic) + } + + + } + + open func getDataMap() -> [ParserMap]? { return nil } + open func beforeParsed(dic: [String: Any], anyData: Any?) {} + open func afterParsed(_ dic: [String: Any]) {} + open func setSerialize(map dic: [String: Any], anyData: Any?) { + + let maps = self.getDataMap() + let ivarList = self.ivarInfoList() + for ivarItem in ivarList { + var changeKey = ivarItem.label + var parserMap: ParserMap? + if let maps = maps { + for pm in maps { + if pm.ivar == ivarItem.label { + parserMap = pm + break; + } + } + } + if parserMap != nil && parserMap!.jsonKey != "" { + changeKey = parserMap!.jsonKey + } + +// print(changeKey) + guard let value = dic[changeKey] else { continue } + guard value is NSNull == false else { continue } + + if ivarItem.classType == .array { + guard let arrayValue = value as? [Any], arrayValue.count > 0 else { continue } + guard let nsobjAbleType = ivarItem.subClassType as? PKHParser.Type else { + fatalError("self : [\(String(describing: self))] label : \(ivarItem.label) \(String(describing: ivarItem.subClassType)) not NSObject" ) + continue + } + var array: [Any] = [] + array.reserveCapacity(arrayValue.count) + for arraySubDic in arrayValue { + if let dic = arraySubDic as? [String:Any] { + let addObj = nsobjAbleType.init(map: dic, anyData: anyData) + array.append(addObj) + } + + } + self.setValue(array, forKey: ivarItem.label) + } + else if ivarItem.classType == .dictionary { + guard let nsobjAbleType = ivarItem.subClassType as? PKHParser.Type else { + fatalError("self : [\(String(describing: self))] label : \(ivarItem.label) \(String(describing: ivarItem.subClassType)) not NSObject" ) + continue + } + if let dic = value as? [String:Any], dic.keys.count > 0 { + let addObj = nsobjAbleType.init(map: dic, anyData: anyData) + self.setValue(addObj, forKey: ivarItem.label) + } + } + else if ivarItem.classType == .string { + if value is String { + self.setValue(value, forKey: ivarItem.label) + } + else { + self.setValue("\(value)", forKey: ivarItem.label) + } + + } + else if ivarItem.classType == .int { + if value is Int { + self.setValue(value, forKey: ivarItem.label) + } + else { + let text = "\(value)" + self.setValue(text.toInt(), forKey: ivarItem.label) + } + } + else if ivarItem.classType == .float { + if value is Float { + self.setValue(value, forKey: ivarItem.label) + } + else { + let text = "\(value)" + self.setValue(text.toFloat(), forKey: ivarItem.label) + } + } + else if ivarItem.classType == .bool { + if value is Bool { + self.setValue(value, forKey: ivarItem.label) + } + else { + let text = "\(value)" + self.setValue(text.toBool(), forKey: ivarItem.label) + } + } + else { + self.setValue(value, forKey: ivarItem.label) + } + + + } + + + } + + open override var description: String { + return getDescription() + } + + private enum descriptionType { + case `default` + case array + case subInstance + } + + private func getDescription(_ tapCount: UInt = 0, _ addType: descriptionType = .default) -> String { + var tap = "" + for _ in 0...tapCount { tap += "\t" } + var result: [String] = [] + let ivarList = self.toDictionary() + result.reserveCapacity(ivarList.count) + switch addType { + case .default: + result.append("\n\(tap)✏️ ======== \(self.className) ✏️ ========") + case .array: + result.append("⬇️ --- \(self.className) ⬇️ ---") + case .subInstance: + result.append("➑️ --- \(self.className) ➑️ ---") + } + + for (key, value) in ivarList { + // print("label: \(key), class: \(self.className) value: \(value)") + + + if let arrayValue = value as? [Any] { + result.append("\(key): ---- Array(\(arrayValue.count)) -------------------------------") + for (idx,obj) in arrayValue.enumerated() { + if checkObjectClass(obj) { + result.append("[\(idx)] \(obj)") + } + else { + if let subArray = obj as? [Any] { + result.append("[\(idx)]---- SubArray(\(subArray.count)) ----") + for case let (subIdx,subItem as PKHParser) in subArray.enumerated() { + result.append("\t[\(subIdx)] \(subItem.getDescription(tapCount + 1, .array))") + } + result.append("---------------------------") + } + else if let objClass = obj as? PKHParser { + result.append("[\(idx)] \(objClass.getDescription(tapCount + 1, .array))") + } + else { + result.append("[\(idx)] \(String(describing: type(of: value))) ????????") + // assertionFailure("\(String(describing: value)) not NSObject" ) + } + } + } + if arrayValue.count > 0 { + result.append("------------------------------------------------------") + } + + } + else if checkObjectClass(value as AnyObject) { + result.append("\(key): \(value)") + } + else { + if let objClass = value as? PKHParser { + result.append("\(key): \(objClass.getDescription(tapCount + 1, .subInstance))") + } + else { + result.append("\(key): \(String(describing: type(of: value))) ????????") + // assertionFailure("\(String(describing: value)) not NSObject" ) + } + } + } + switch addType { + case .default: + result.append("✏️ ================== \(self.className) ===================== ✏️") + case .array, .subInstance: + result.append("----------- \(self.className) -----------") + } + return result.joined(separator: "\n\(tap)") + } + +} +``` diff --git a/PKHParser/NSObjectExtensions.swift b/Sources/PKHJsonParser/NSObjectExtensions.swift similarity index 100% rename from PKHParser/NSObjectExtensions.swift rename to Sources/PKHJsonParser/NSObjectExtensions.swift diff --git a/PKHParser/PKHParser.swift b/Sources/PKHJsonParser/PKHJsonParser.swift similarity index 100% rename from PKHParser/PKHParser.swift rename to Sources/PKHJsonParser/PKHJsonParser.swift diff --git a/PKHParser/StringExtensions.swift b/Sources/PKHJsonParser/StringExtensions.swift similarity index 100% rename from PKHParser/StringExtensions.swift rename to Sources/PKHJsonParser/StringExtensions.swift diff --git a/Tests/PKHJsonParserTests/PKHJsonParserTests.swift b/Tests/PKHJsonParserTests/PKHJsonParserTests.swift new file mode 100644 index 0000000..56362f3 --- /dev/null +++ b/Tests/PKHJsonParserTests/PKHJsonParserTests.swift @@ -0,0 +1,11 @@ +import XCTest +@testable import PKHJsonParser + +final class PKHJsonParserTests: XCTestCase { + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct + // results. + XCTAssertEqual(PKHJsonParser().text, "Hello, World!") + } +}