{"id":1851,"url":"https://github.com/CharlinFeng/Reflect","last_synced_at":"2025-08-02T05:32:51.262Z","repository":{"id":36715770,"uuid":"41022336","full_name":"CharlinFeng/Reflect","owner":"CharlinFeng","description":"Reflection, Dict2Model, Model2Dict, Archive","archived":false,"fork":false,"pushed_at":"2017-06-06T13:37:19.000Z","size":813,"stargazers_count":307,"open_issues_count":14,"forks_count":66,"subscribers_count":26,"default_branch":"master","last_synced_at":"2024-08-15T19:07:57.943Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"OCA/reporting-engine","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CharlinFeng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-19T08:27:19.000Z","updated_at":"2024-05-28T11:12:22.000Z","dependencies_parsed_at":"2022-08-24T22:30:24.326Z","dependency_job_id":null,"html_url":"https://github.com/CharlinFeng/Reflect","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CharlinFeng%2FReflect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CharlinFeng%2FReflect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CharlinFeng%2FReflect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CharlinFeng%2FReflect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CharlinFeng","download_url":"https://codeload.github.com/CharlinFeng/Reflect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228443612,"owners_count":17920758,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:15:57.291Z","updated_at":"2024-12-06T09:30:25.129Z","avatar_url":"https://github.com/CharlinFeng.png","language":"Swift","funding_links":[],"categories":["Reflection"],"sub_categories":["React-Like","Other free courses"],"readme":"![image](./Reflect/logo.jpg)\u003cbr /\u003e\n\u003cbr/\u003e\n\n##### 感谢小饭的翻译 [中文文档](https://github.com/nsdictionary/Reflect/blob/master/README_CN.md)\n\n\n\n###Selfless pay, just to make you faster to conquer swift！\n\n#### .Reflection\n#### .convert dictionary to model\n#### .convert model to dictionary\n#### .convert plist to model\n#### .One key archive\n\n\n\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\nReflect\n===============\n\u003cbr/\u003e\n### Reflec\n.iOS 7.0 \u003cbr/\u003e\n.Swift 2.0\u003cbr/\u003e\n.Xcode 7\u003cbr/\u003e\n.Reflection is available under the MIT license.\n\n\n\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\nInstallation\n===============\nyou can just drag the Reflect files into your own project, without any third-party library.\u003cbr/\u003e\u003cbr/\u003e\nStructure Details：\u003cbr/\u003e\n.Coding about archiving \u003cbr/\u003e\n.Reflect  reflection core package\u003cbr/\u003e\n.Dict2Model convert  dictionary to  custom object\u003cbr/\u003e\n.Model2Dict convert custom object to dictionary\u003cbr/\u003e\n\n#### Tips\nThis frame already prepares many examples for lazy guys and it’s easy to see the result when u just use the methord\nPerson1.Convert(),Studetn1.Parse(),Book1.Action()\u003cbr/\u003e\n1.Parse-Parse8: convert dictionary to model\u003cbr/\u003e\n2.Convert1-Convert4: convert model to dictionary\u003cbr/\u003e\n3.Archiver1-Archiver3: One key archive\u003cbr/\u003e\n\n\n\n\n\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\nCore theory\n===============\n1. If you wanna use all the functions, all your custom model must inherit from `Reflect` Class.\u003cbr/\u003e\n\n2. It’s better to use implicitly optional type for properties. Try not to use strange type like var v1: [string?]? , var v2: [string!]! and this frame has lots of assertion to help you use data type reasonably.\u003cbr/\u003e\n3. This frame is based on requirement : parse json data into dictionaries then to model.\nLimitation: reckon without complictated data like Core Data support; without consideration of Struct.\n\u003cbr/\u003e\n\n\n\n\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\nReflect\n===============\nCall the properties of object directly can get the reflection for enumerations:\n\n        p1.properties { (name, type, value) -\u003e Void in\n            println(\"\\(name),\\(type),\\(value)\")\n        }\n\nIn addition, you can call class methods without initiate object while the value has no meaning:\n\n        Person.properties { (name, type, _) -\u003e Void in\n            println(\"\\(name),\\(type)\")\n        }\n\nThe name is the property name of your model;\nType is the type of encapsulated ReflectType data;\nValue is the value of variable;\nYou can also see the detail of properties by seeing the reference of ReflectType encapsulation. For example, the specific data type, if it is basic data type, if it is array, if it is optional, if it is object transferred from OC and if it is custom class.：\u003cbr/\u003e\u003cbr/\u003e\n\n\n\n    var typeName: String!\n    \n    /**  analysis type from system  */\n    var typeClass: Any.Type!\n    \n    var disposition: MirrorDisposition!\n    \n    var dispositionDesc: String!\n    \n    /**  whether it is optional  */\n    var isOptional: Bool = false\n    \n    /**  whether it is array  */\n    var isArray: Bool = false\n    \n    /**  real type: optional + array  */\n    var realType: RealType = .None\n\nIn addition to above, I also add the function of  printing like OC so that you can directly print the object. For example, print Book1(book1 class is in Archiver1.swift of the projcet)\nprintln(book1):\n\n    println(book1)\n    \n\nthe result of console would be:\n\n    Reflect.Book1 \u003c0x7a09fb10\u003e: \n    {\n    name: tvb\n    price: 36.6\n    }\n\nignore the field and field reflection of the process of analyzing additional features, subclass needs only rewrite the method.\n\n    /**  property mapping  */\n    \n    //The model's property named 'userModel',get value width key 'user_model' from dictionay\n    func mappingDict() -\u003e [String: String]? {\n        return [\"userModel\":\"user_model\"]\n    }\n     \n     \n    /**  property ignore */\n    \n    //Ignore the 'info' property of the model.\n    func ignorePropertiesForParse() -\u003e [String]? {\n        return [\"info\"]\n    }\n\n\nYou also can use the method below to complete converting from string to class\n\n    let cls = ClassFromString(\"Reflect.Person\")\n  \nattention, the string here include the name space \n\n\n\n\n\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\nconvert dictionary to model\n===============\nit’s easy to convert dictionary to model, I already did the cascade im not going to repeat the details：\n\n    let stu1 = Student1.parse(dict: Student1Dict)\n    let stus = Student7.parses(arr: Student7DictArr)\n\nIf you property type is Bool, you may encounter UndefinedKey, which is due to Swift's own reasons, you just need to implement the following methods manually resolved:\n\n    override func setValue(value: AnyObject?, forUndefinedKey key: String) {\n        self.isVip = (value as! Int) != 0\n    }\n\n\nparse Plist file ,Please don't take the suffix\n\n    let author = Author.parsePlist(\"Author\")\n\n\n\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\nconvert model to dictionary\n===============\nit’s easy to convert model to dictionary, I already did the cascade im not going to repeat the details:\n\n    let dict = person3.toDict()\n\n\n\u003cbr/\u003e\u003cbr/\u003e\u003cbr/\u003e\nOne key archive\n===============\nArchive has done the cascade and easy for using. It also encapsulates the operation of Caches folder, directly save in Caches folder.\n\nArchive: the name of  single model could be empty, but the name of array can’t be empty. Back to the position of archiving.\n\n    let path1 =  Book2.save(obj: book2, name: nil)\n    let path2 =  Book3.save(obj: bookArr, name: \"book3\")\n\n\nRead data: please use the same key, if save name wich not used as nill, use nil for read data.\n\n    let arcBook2 = Book2.read(name: nil)\n    let arr = Book3.read(name: \"book3\")\n\ndelete data:\n\n    Book1.delete(name: nil)\n\n\nadditional function: ignore archive field\n\n    /**  ignore archive field  */\n    \n    //ignore archive property named 'icon'\n    func ignoreCodingPropertiesForCoding() -\u003e [String]? {\n        return [\"icon\"]\n    }\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCharlinFeng%2FReflect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCharlinFeng%2FReflect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCharlinFeng%2FReflect/lists"}