-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
397 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
ZXKit-code/core | ||
|
||
Copyright 2021 ZXKit and contributors. | ||
All rights reserved. | ||
|
||
This product includes software developed at | ||
ZXKit (https://zxkit.com/). | ||
|
||
This distribution has a binary dependency on zxkit/core, which is available under the Apache-2.0 License. The source code of zxkit/core can be found at https://github.com/zxkit-code/core. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,61 @@ | ||
# ZXUserDefaultManager | ||
UserDefault Manager | ||
|
||
[中文文档](./README_zh.md) | ||
|
||
iOS UserDefault data management, iOS UserDefault数据管理 | ||
|
||
This project is a built-in function plug-in of [ZXKitSwift](https://github.com/ZXKitCode/ZXKitSwift), and it can also be integrated separately and used as an independent function. | ||
|
||
**If you have integrated `ZXKitSwift`, the file browser will be automatically displayed in the plug-in list, so there is no need to repeat the integration.** | ||
|
||
|
||
## Independent integration | ||
|
||
cocoapods | ||
|
||
```ruby | ||
pod 'ZXUserDefaultManager' | ||
``` | ||
|
||
### Use | ||
|
||
```swift | ||
ZXUserDefaultManager.shared.start() | ||
``` | ||
|
||
## Support `ZXKit` | ||
|
||
**If you have integrated `ZXKitSwift`, the file browser will be automatically displayed in the plug-in list, so there is no need to repeat the integration.** | ||
|
||
If you need to support `ZXKit`, you can use cocoapods to quickly integrate it | ||
|
||
```ruby | ||
pod 'ZXUserDefaultManager/zxkit' | ||
``` | ||
|
||
then register to `ZXKit` in `AppDelegate` | ||
|
||
```swift | ||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | ||
|
||
ZXKit.regist(plugin: ZXUserDefaultManager.shared) | ||
|
||
return true | ||
} | ||
``` | ||
|
||
## Preview | ||
|
||
|File List|File Type Icon| | ||
|----|----| | ||
|![](./preview/demo2.png)|![](./preview/demo1.png)| | ||
|
||
Function example | ||
|
||
![](./preview/preview.gif) | ||
|
||
## License | ||
|
||
![](https://camo.githubusercontent.com/eb9066a6d8e0950066f3757c420e3a607c0929583b48ebda6fd9a6f50ccfc8f1/68747470733a2f2f7777772e6170616368652e6f72672f696d672f41534632307468416e6e69766572736172792e6a7067) | ||
|
||
Base on Apache-2.0 License |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# ZXUserDefaultManager | ||
|
||
iOS UserDefault data management, iOS UserDefault数据管理 | ||
|
||
该项目是[ZXKitSwift](https://github.com/ZXKitCode/ZXKitSwift)的内置功能插件,也可以单独集成当做独立功能使用。 | ||
|
||
**如果您已经集成了`ZXKitSwift`,插件列表中会自动显示该数据管理浏览器,不需要再重复集成。** | ||
|
||
|
||
## 独立集成 | ||
|
||
cocoapods快速集成 | ||
|
||
```ruby | ||
pod 'ZXUserDefaultManager' | ||
``` | ||
|
||
### 使用 | ||
|
||
```swift | ||
//显示管理器 | ||
ZXUserDefaultManager.shared.start() | ||
``` | ||
|
||
## `ZXKit`个性化集成 | ||
|
||
**如果您已经集成了`ZXKitSwift`,插件列表中会自动显示该文件浏览器,不需要再重复集成。** | ||
|
||
如果需要支持`ZXKit`,可以使用cocoapods快速集成 | ||
|
||
```ruby | ||
pod 'ZXUserDefaultManager/zxkit' | ||
``` | ||
|
||
之后可在`AppDelegate`的启动函数中注册到`ZXKit`即可 | ||
|
||
```swift | ||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | ||
|
||
//ZXKit注册 | ||
ZXKit.regist(plugin: ZXUserDefaultManager.shared) | ||
|
||
return true | ||
} | ||
|
||
``` | ||
|
||
## 预览 | ||
|
||
|
||
|文件列表|文件类型| | ||
|----|----| | ||
|![](./preview/demo2.png)|![](./preview/demo1.png)| | ||
|
||
功能示例 | ||
|
||
![](./preview/preview.gif) | ||
|
||
|
||
## License | ||
|
||
![](https://camo.githubusercontent.com/eb9066a6d8e0950066f3757c420e3a607c0929583b48ebda6fd9a6f50ccfc8f1/68747470733a2f2f7777772e6170616368652e6f72672f696d672f41534632307468416e6e69766572736172792e6a7067) | ||
|
||
Base on Apache-2.0 License |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Pod::Spec.new do |s| | ||
s.name = 'ZXUserDefaultManager' | ||
s.swift_version = '5.0' | ||
s.version = '0.0.1' | ||
s.license= { :type => "Apache-2.0", :file => "LICENSE" } | ||
s.summary = 'iOS UserDefault data management, iOS UserDefault数据管理' | ||
s.homepage = 'https://github.com/ZXKitCode/ZXUserDefaultManager' | ||
s.authors = { 'ZXKitCode' => '[email protected]' } | ||
s.source = { :git => "https://github.com/ZXKitCode/ZXUserDefaultManager.git", :tag => s.version} | ||
s.requires_arc = true | ||
s.ios.deployment_target = '11.0' | ||
s.subspec 'core' do |cs| | ||
cs.resource_bundles = { | ||
'ZXUserDefaultManager' => ['pod/assets/**/*'] | ||
} | ||
cs.source_files = "pod/*.swift", "pod/view/*.swift", "pod/vc/*.swift", "pod/model/*.swift" | ||
cs.dependency 'ZXKitUtil' | ||
cs.dependency 'SnapKit' | ||
end | ||
s.subspec 'zxkit' do |cs| | ||
cs.dependency 'ZXUserDefaultManager/core' | ||
cs.dependency 'ZXKitCore/core' | ||
cs.source_files = "pod/zxkit/*.swift" | ||
end | ||
s.default_subspecs = "core" | ||
s.documentation_url = 'https://blog.hudongdong.com/ios/1169.html' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+13.4 KB
(140%)
...serDefaultManager.xcworkspace/xcuserdata/damon.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
6 changes: 6 additions & 0 deletions
6
...aultManager.xcworkspace/xcuserdata/damon.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Bucket | ||
uuid = "446E0044-AD46-45DD-8583-8AF7C7C70535" | ||
type = "0" | ||
version = "2.0"> | ||
</Bucket> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,6 @@ | |
import UIKit | ||
|
||
class ZXDataCellModel: NSObject { | ||
|
||
var key = "" | ||
var value: Any = "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
// | ||
// ZXUserDefaultEditVC.swift | ||
// ZXUserDefaultManager | ||
// | ||
// Created by Damon on 2021/7/16. | ||
// | ||
|
||
import UIKit | ||
|
||
class ZXUserDefaultEditVC: UIViewController { | ||
private var model: ZXDataCellModel | ||
|
||
init(model: ZXDataCellModel) { | ||
self.model = model | ||
super.init(nibName: nil, bundle: nil) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
let rightBarItem = UIBarButtonItem(title: "save".ZXLocaleString, style: .plain, target: self, action: #selector(_rightBarItemClick)) | ||
self.navigationItem.rightBarButtonItem = rightBarItem | ||
self._createUI() | ||
self._loadData() | ||
} | ||
|
||
//MARK: UI | ||
lazy var mTitleLabel: UILabel = { | ||
let tLabel = UILabel() | ||
tLabel.textAlignment = .center | ||
tLabel.numberOfLines = 2 | ||
tLabel.font = .systemFont(ofSize: 16, weight: .medium) | ||
tLabel.textColor = UIColor.zx.color(hexValue: 0x333333) | ||
return tLabel | ||
}() | ||
|
||
lazy var mSegment: UISegmentedControl = { | ||
let segment = UISegmentedControl(items: ["Bool", "Number", "String", "Object"]) | ||
segment.addTarget(self, action: #selector(_changeType), for: .valueChanged) | ||
return segment | ||
}() | ||
lazy var mTextView: UITextView = { | ||
let textView = UITextView() | ||
textView.font = .systemFont(ofSize: 14) | ||
textView.layer.cornerRadius = 10 | ||
textView.layer.borderWidth = 1.0 | ||
textView.layer.borderColor = UIColor.zx.color(hexValue: 0xeeeeee).cgColor | ||
return textView | ||
}() | ||
} | ||
|
||
extension ZXUserDefaultEditVC { | ||
|
||
@objc func _rightBarItemClick() { | ||
switch self.mSegment.selectedSegmentIndex { | ||
case 0: | ||
UserDefaults.standard.set(mTextView.text.boolValue, forKey: model.key) | ||
case 1: | ||
UserDefaults.standard.set(Double(String(mTextView.text)) ?? 0, forKey: model.key) | ||
case 2: | ||
UserDefaults.standard.set(mTextView.text, forKey: model.key) | ||
default: | ||
if let jsonData = mTextView.text.data(using: .utf8), let object = try? JSONSerialization.jsonObject(with: jsonData, options: .mutableContainers) { | ||
UserDefaults.standard.set(object, forKey: model.key) | ||
} else { | ||
UserDefaults.standard.set(mTextView.text, forKey: model.key) | ||
} | ||
} | ||
self.navigationController?.popViewController(animated: true) | ||
} | ||
|
||
func _createUI() { | ||
self.view.backgroundColor = UIColor.zx.color(hexValue: 0xffffff) | ||
self.view.addSubview(mTitleLabel) | ||
mTitleLabel.snp.makeConstraints { make in | ||
make.left.equalToSuperview().offset(10) | ||
make.right.equalToSuperview().offset(-10) | ||
make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top).offset(20) | ||
} | ||
|
||
self.view.addSubview(mSegment) | ||
mSegment.snp.makeConstraints { make in | ||
make.left.right.equalTo(self.mTitleLabel) | ||
make.top.equalTo(mTitleLabel.snp.bottom).offset(30) | ||
make.height.equalTo(34) | ||
} | ||
|
||
self.view.addSubview(mTextView) | ||
mTextView.snp.makeConstraints { make in | ||
make.left.equalToSuperview().offset(10) | ||
make.right.equalToSuperview().offset(-10) | ||
make.top.equalTo(mSegment.snp.bottom).offset(10) | ||
make.bottom.equalTo(self.view.safeAreaLayoutGuide.snp.bottom).offset(-20) | ||
} | ||
} | ||
|
||
func _loadData() { | ||
mTitleLabel.text = model.key | ||
if model.value is Bool { | ||
mSegment.selectedSegmentIndex = 0 | ||
} else if model.value is NSNumber { | ||
mSegment.selectedSegmentIndex = 1 | ||
} else if model.value is String { | ||
mSegment.selectedSegmentIndex = 2 | ||
} else if (model.value is NSArray || model.value is NSDictionary) { | ||
mSegment.selectedSegmentIndex = 3 | ||
} | ||
if JSONSerialization.isValidJSONObject(model.value), let jsonData = try? JSONSerialization.data(withJSONObject: model.value, options: .prettyPrinted) { | ||
mTextView.text = String(data: jsonData, encoding: .utf8) | ||
} else { | ||
mTextView.text = "\(model.value)" | ||
} | ||
} | ||
|
||
@objc func _changeType() { | ||
switch self.mSegment.selectedSegmentIndex { | ||
case 0: | ||
mTextView.text = "\(model.value)".boolValue ? "true" : "false" | ||
case 1: | ||
if model.value is NSNumber { | ||
mTextView.text = "\(model.value)" | ||
} else { | ||
mTextView.text = "\(Double("\(model.value)") ?? 0)" | ||
} | ||
default: | ||
if JSONSerialization.isValidJSONObject(model.value), let jsonData = try? JSONSerialization.data(withJSONObject: model.value, options: .prettyPrinted) { | ||
mTextView.text = String(data: jsonData, encoding: .utf8) | ||
} else { | ||
mTextView.text = "\(model.value)" | ||
} | ||
} | ||
} | ||
} | ||
|
||
extension String { | ||
var boolValue: Bool { | ||
switch self.lowercased() { | ||
case "false", "no", "0": | ||
return false | ||
default: | ||
return !self.isEmpty | ||
} | ||
} | ||
} |
Oops, something went wrong.