Skip to content

Commit

Permalink
新增plist文件的解析能力
Browse files Browse the repository at this point in the history
  • Loading branch information
Mccc committed Sep 3, 2024
1 parent 7c111c3 commit 4ab6cef
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Example/SmartCodable.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
996760482B3EC930006C83EC /* DateDecodingStrategyViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 996760112B3EC930006C83EC /* DateDecodingStrategyViewController.swift */; };
9967604A2B3EC930006C83EC /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 996760152B3EC930006C83EC /* BaseViewController.swift */; };
9967604C2B3EC930006C83EC /* CaseSixViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 996760182B3EC930006C83EC /* CaseSixViewController.swift */; };
996928DD2C8707DD002FAA61 /* SpecialData_data.plist in Resources */ = {isa = PBXBuildFile; fileRef = 996928DC2C8707DD002FAA61 /* SpecialData_data.plist */; };
996928DF2C870899002FAA61 /* ReplaceHandyJSON_7ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 996928DE2C870899002FAA61 /* ReplaceHandyJSON_7ViewController.swift */; };
998567092C1044060021B7FD /* ConcurrenceLogViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 998567082C1044060021B7FD /* ConcurrenceLogViewController.swift */; };
9985670E2C11B9810021B7FD /* TestEncodeCaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9985670D2C11B9810021B7FD /* TestEncodeCaseViewController.swift */; };
998567112C11BCD60021B7FD /* Encode_BaseData_BoolViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 998567102C11BCD60021B7FD /* Encode_BaseData_BoolViewController.swift */; };
Expand Down Expand Up @@ -216,6 +218,8 @@
996760112B3EC930006C83EC /* DateDecodingStrategyViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateDecodingStrategyViewController.swift; sourceTree = "<group>"; };
996760152B3EC930006C83EC /* BaseViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = "<group>"; };
996760182B3EC930006C83EC /* CaseSixViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaseSixViewController.swift; sourceTree = "<group>"; };
996928DC2C8707DD002FAA61 /* SpecialData_data.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = SpecialData_data.plist; sourceTree = "<group>"; };
996928DE2C870899002FAA61 /* ReplaceHandyJSON_7ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReplaceHandyJSON_7ViewController.swift; sourceTree = "<group>"; };
998567082C1044060021B7FD /* ConcurrenceLogViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConcurrenceLogViewController.swift; sourceTree = "<group>"; };
9985670D2C11B9810021B7FD /* TestEncodeCaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestEncodeCaseViewController.swift; sourceTree = "<group>"; };
998567102C11BCD60021B7FD /* Encode_BaseData_BoolViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Encode_BaseData_BoolViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -407,6 +411,7 @@
9902B4D72BB2FF0500310E69 /* ReplaceHandyJSON_4ViewController.swift */,
9902B4D92BB3010C00310E69 /* ReplaceHandyJSON_5ViewController.swift */,
9902B4DB2BB304B400310E69 /* ReplaceHandyJSON_6ViewController.swift */,
996928DE2C870899002FAA61 /* ReplaceHandyJSON_7ViewController.swift */,
9902B4D52BB2F8F800310E69 /* ReplaceHandyJSONViewController.swift */,
);
path = "平替HandyJSON";
Expand Down Expand Up @@ -719,6 +724,7 @@
children = (
99D945892B91C75600CC6470 /* SpecialData_dateViewController.swift */,
99D9458B2B91C80300CC6470 /* SpecialData_dataViewController.swift */,
996928DC2C8707DD002FAA61 /* SpecialData_data.plist */,
99D9458D2B91C80C00CC6470 /* SpecialData_FloatViewController.swift */,
9993D6932B91ED9B0089CA68 /* SpecialData_URLViewController.swift */,
9957743A2BFD95E4003613C5 /* SpecialData_ColorViewController.swift */,
Expand Down Expand Up @@ -845,6 +851,7 @@
99675FD12B3EC822006C83EC /* airports1000.json in Resources */,
99C1E70D2B99A55E0090E8FD /* 说明信息 in Resources */,
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */,
996928DD2C8707DD002FAA61 /* SpecialData_data.plist in Resources */,
99675FD52B3EC866006C83EC /* airports1.json in Resources */,
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */,
99328D9A2B513A300074036A /* area.json in Resources */,
Expand Down Expand Up @@ -992,6 +999,7 @@
99D945842B9182C800CC6470 /* Container_ArrayNestDictViewController.swift in Sources */,
9905129F2C08299200A2C5D8 /* Decoding_keyIgnoreViewController.swift in Sources */,
99D945852B9182C800CC6470 /* Container_DictNestDictViewController.swift in Sources */,
996928DF2C870899002FAA61 /* ReplaceHandyJSON_7ViewController.swift in Sources */,
9955AC502C32B08700D25466 /* Container_keyedViewController.swift in Sources */,
996760212B3EC930006C83EC /* ArraySafe.swift in Sources */,
99CE4D5D2BC699D10006D435 /* BeforeDecodingViewController.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ extension ReplaceHandyJSONViewController {

["name": "6.枚举的解析", "vc": "ReplaceHandyJSON_6ViewController"],

["name": "7.plist文件的解析", "vc": "ReplaceHandyJSON_7ViewController"],

]
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// ReplaceHandyJSON_7ViewController.swift
// SmartCodable_Example
//
// Created by qixin on 2024/9/3.
// Copyright © 2024 CocoaPods. All rights reserved.
//

import Foundation
import SmartCodable

class ReplaceHandyJSON_7ViewController: BaseViewController {

override func viewDidLoad() {
super.viewDidLoad()

guard let data = readPlistData() else { return }

if let model = Model.deserializePlist(from: data) {
smartPrint(value: model)
}

}

func readPlistData() -> Data? {
// 获取plist文件的路径
if let path = Bundle.main.path(forResource: "SpecialData_data", ofType: "plist") {
// 将plist文件的内容加载到Data对象中
if let data = FileManager.default.contents(atPath: path) {
return data
} else {
print("无法读取plist文件内容")
}
} else {
print("找不到plist文件")
}
return nil
}

struct Model: SmartCodable {
var name: String?
var age: Int?
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>age</key>
<integer>20</integer>
<key>name</key>
<string>Mccc</string>
</dict>
</plist>

0 comments on commit 4ab6cef

Please sign in to comment.