Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate README to Chinese #1

Closed
nmdias opened this issue Aug 28, 2017 · 8 comments
Closed

Translate README to Chinese #1

nmdias opened this issue Aug 28, 2017 · 8 comments

Comments

@nmdias
Copy link
Owner

nmdias commented Aug 28, 2017

Create a README.CN.md in Chinese.

Chinese is the #1 spoken language in the world and I'd love to have DefaultsKit be more inclusive, unfortunately I don't speak Chinese. If you know Chinese, and would like to help out, I'd be eternally grateful.

Thank you 🙏

@linbx08
Copy link

linbx08 commented Aug 28, 2017

什么是DefaultsKit
DefaultsKit 是利用Swift4强大的Codable,在UserDefaults基础上提供一层简单且强大的封装。它仅使用少于70行代码来实现这些功能。

使用说明
第一步:
实例化或者使用单例来初始化

let defaults = Defaults() 
// 或者使用 let defaults = Defaults.shared

第二步:

// 定义一个键(key)
let key = Key<String>("someKey")

// 设置值(value)
defaults.set("Codable FTW 😃", for: key)

// 通过设置的key来查看返回的value结果值
defaults.get(for: key) // 输出: Codable FTW 😃

判断某个键(key)是否含有某个值(value)
if defaults.has(key) {
// 书写你自己的代码
}

如果你只需要知道该键值队(key,value)是否存在,而不需要使用该key使用的返回值(value),使用has()这个方法代替这个可选的get(for:key)方法。对于一些复杂的对象,它可以减少避免一些不必要的转换

复杂的对象存储
一个遵循Codable协议的复杂对象需要存储

struct Person: Codable {
    let name: String
    let age: Int
}

// 然后创建一个键(key)
let key = Key<Person>("personKey")

// 获取一个实例符合Codable协议的枚举,结构体或者类
let person = Person(name: "Bonnie Greenwell", age: 80)

// 赋值
defaults.set(person, for: key)

// 最后查看key返回值的value
let person = defaults.get(for: key)
person?.name // Bonnie Greenwell
person?.age  // 80

嵌套对象的存储
只要是遵循Codable协议,你也可以使用嵌套对象

enum Pet: String, Codable {
    case cat
    case dog
}

struct Person: Codable {
    let name: String
    let pets: [Pet]
}

// 获取一个遵循Codable协议的实例
let person = Person(name: "Claire", pets: [.cat])

// 赋值
defaults.set(person, for: key)

// 查看key返回值的value
let person = defaults.get(for: key)
person?.name        // Claire
person?.pets.first  // cat

@linbx08
Copy link

linbx08 commented Aug 28, 2017

hello, That was my understanding. hope can help you. thanks.

@nmdias
Copy link
Owner Author

nmdias commented Aug 28, 2017

Ah Fantastic! Thank you so much 🙏

@dadpp
Copy link

dadpp commented Aug 28, 2017

厉害了 大佬

@nmdias
Copy link
Owner Author

nmdias commented Aug 28, 2017

I've added the Chinese translations kindly provided by @linbx08 to the README.zh-CN.md file. Thank you again!

@hewigovens
Copy link
Contributor

hewigovens commented Aug 29, 2017

I made some refinements and here is the pull request: #3

@asd8855
Copy link

asd8855 commented Dec 6, 2017

cool

@Marcello168
Copy link

It`s very nice

@nmdias nmdias closed this as completed Jan 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants