Skip to content

Commit

Permalink
차워원 배열 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
박길호 committed Mar 25, 2024
1 parent 341b90b commit 7de7744
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 11 deletions.
22 changes: 22 additions & 0 deletions Example-iOS/PKHParserTest/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ViewController: UIViewController {
}
},
"windowsDataList": [
[
{
"title": "Sample Konfabulator Widget",
"name": "main_window",
Expand All @@ -68,6 +69,27 @@ class ViewController: UIViewController {
"width": 500,
"height": 500
}
],
[
{
"title": "Sample Konfabulator Widget111111111",
"name": "main_window111111111",
"width": 500111111,
"height": 5001111111
},
{
"title": "Sample Konfabulator Widget1111111",
"name": "main_window1111111",
"width": 5001111111,
"height": 5001111111
},
{
"title": "Sample Konfabulator Widget1111111",
"name": "main_window1111111",
"width": 5001111111,
"height": 5001111111
}
]
],
"size": 36,
"style": "bold",
Expand Down
2 changes: 1 addition & 1 deletion Example-iOS/TestClass/Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
class Test : PKHParser {

var widgetData: Widget?
var windowsList = [WindowsDataListItem]()
var windowsList = [[WindowsDataListItem]]()
var style: String = ""
var onMouseUp: String = ""
var size: Int = 0
Expand Down
2 changes: 1 addition & 1 deletion Sources/PKHJsonParser/NSObjectExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class ObjectInfoMap {
}
}


public var Object_Info_Cache = NSCache<NSString, ObjectInfoMap>()

@inline(__always) public func swiftClassFromString(_ className: String, bundleName: String = "") -> AnyClass? {
Expand Down Expand Up @@ -143,6 +142,7 @@ public struct IvarInfo {
// print("label: \(label), class: \(classType.className) value: \(String(describing: type(of: value)))")
// }

let label = label.replace("$__lazy_storage_$_", "")
var className = String(describing: type(of: value))

if className.contains("Array<Any>") || className.contains(".Type") || className.contains("Dictionary<") || className.contains("Optional<Any>") || className.contains("Optional<AnyObject>") {
Expand Down
53 changes: 44 additions & 9 deletions Sources/PKHJsonParser/PKHJsonParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,41 @@ let ParserObjectConcurrentQueue = DispatchQueue(label: "ParserObjectConcurrentQu

if ivarItem.classType == .array {
guard let arrayValue = value as? [Any], arrayValue.count > 0 else { continue }
var array: [Any] = []
array.reserveCapacity(arrayValue.count)
if let nsobjAbleType = ivarItem.subClassType as? PKHParser.Type {
var array: [Any] = []
array.reserveCapacity(arrayValue.count)
for arraySubDic in arrayValue {
if let dic = arraySubDic as? [String:Any], dic.isEmpty == false {
if let dic = arraySubDic as? [String: Any], dic.isEmpty == false {
let addObj = nsobjAbleType.init(map: dic, anyData: anyData)
array.append(addObj)
}

else if let subArray = arraySubDic as? [Any], subArray.count > 0 {
var addSubarray: [Any] = []
addSubarray.reserveCapacity(subArray.count)
for ssDic in subArray {
if let dic = ssDic as? [String: Any], dic.isEmpty == false {
let addObj = nsobjAbleType.init(map: dic, anyData: anyData)
addSubarray.append(addObj)
}
}
if addSubarray.count > 0 {
array.append(addSubarray)
}
}
}
self.setValue(array, forKey: ivarItem.label)
}
else {
var array: [Any] = []
array.reserveCapacity(arrayValue.count)
for arraySub in arrayValue {
if let data = changeTypeValue(type: ivarItem.subValueType, value: arraySub) {
array.append(data)
}
}
self.setValue(array, forKey: ivarItem.label)
}
self.setValue(array, forKey: ivarItem.label)

}
else if ivarItem.classType == .dictionary {
guard let nsobjAbleType = ivarItem.subClassType as? PKHParser.Type else {
Expand All @@ -120,7 +136,7 @@ let ParserObjectConcurrentQueue = DispatchQueue(label: "ParserObjectConcurrentQu
}
}
else if let data = changeTypeValue(type: ivarItem.classType, value: value) {
self.setValue(data , forKey: ivarItem.label)
self.setValue(data, forKey: ivarItem.label)
}
else if ivarItem.classType == .any {
print("\n debug parser AnyType label: \(ivarItem.label) type: \(String(describing: type(of: value))), value: \(value)\n")
Expand All @@ -133,7 +149,7 @@ let ParserObjectConcurrentQueue = DispatchQueue(label: "ParserObjectConcurrentQu
print("""
🧨🧨🧨 파싱 오류입니다. 공통파트에 신고해 주세요 🧨🧨🧨
🧨🧨🧨 파싱 오류입니다. 🧨🧨🧨
lable: \(ivarItem.label)
value: \(value)
Expand Down Expand Up @@ -197,10 +213,29 @@ let ParserObjectConcurrentQueue = DispatchQueue(label: "ParserObjectConcurrentQu

for (label, value) in mirrored_object.children {
guard let label = label else { continue }

if value is String || value is Int || value is Float || value is CGFloat || value is Double || value is Bool {
result.append("\(label) : \(value)")
}
else if let objList = value as? [[PKHParser]] {
var strList = [String]()
if objList.count > 0 {
for (idx, obj) in objList.enumerated() {
strList.append("[\(idx)]")
for (idx, subObj) in obj.enumerated() {
strList.append("\t[\(idx)] \(subObj.getDescription(tapCount + 2, mirrored_object: Mirror(reflecting: subObj)))")
}
if idx == 0 {
result.append("\(label) : ⬇️ --- \(obj[safe: 0]?.className ?? "count = 0") ⬇️ ------")
}
}
result.append(contentsOf: strList)
result.append("------------------------------------------------------------")
}
else {
result.append("\(label) : ⬇️ --- count = 0 ⬇️ ------")
}

}
else if let objList = value as? [PKHParser] {
var strList = [String]()

Expand Down Expand Up @@ -230,7 +265,7 @@ let ParserObjectConcurrentQueue = DispatchQueue(label: "ParserObjectConcurrentQu
else if let obj = value as? PKHParser {
result.append("\(label) : ➡️ === \(obj.className) ======")
result.append("\t\(obj.getDescription(tapCount + 1, mirrored_object: Mirror(reflecting: obj)))")
result.append("======= \(obj.className) ===============================")
result.append("-------- \(obj.className) -----------------------------------")
}
else {
result.append("\(label) : \(value)")
Expand Down

0 comments on commit 7de7744

Please sign in to comment.