{"id":1043,"url":"https://github.com/jamesdouble/RandMyMod","last_synced_at":"2025-07-30T20:31:02.692Z","repository":{"id":62452517,"uuid":"121217782","full_name":"jamesdouble/RandMyMod","owner":"jamesdouble","description":"RandMyMod base on your own struct or class create one or a set of instance, which the variable's value in the instance is automatic randomized.","archived":false,"fork":false,"pushed_at":"2018-03-01T05:20:21.000Z","size":398,"stargazers_count":18,"open_issues_count":1,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-01T03:41:53.243Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamesdouble.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":"2018-02-12T08:05:06.000Z","updated_at":"2023-11-25T08:25:41.000Z","dependencies_parsed_at":"2022-11-01T23:46:24.571Z","dependency_job_id":null,"html_url":"https://github.com/jamesdouble/RandMyMod","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesdouble%2FRandMyMod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesdouble%2FRandMyMod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesdouble%2FRandMyMod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamesdouble%2FRandMyMod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamesdouble","download_url":"https://codeload.github.com/jamesdouble/RandMyMod/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228179151,"owners_count":17881137,"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:37.715Z","updated_at":"2024-12-04T19:32:43.299Z","avatar_url":"https://github.com/jamesdouble.png","language":"Swift","funding_links":[],"categories":["Data Structures / Algorithms"],"sub_categories":["Getting Started","Other free courses","Linter"],"readme":"![Alt text](https://raw.githubusercontent.com/jamesdouble/RandMyMod/master/Readme_img/logo.png)\n\n**RandMyMod** is an IOS Native Framework helps you generate one or a set of variable base on your own model.\n\nNo matter your model is Class / Struct.\n\n![Alt text](https://img.shields.io/badge/SwiftVersion-4.0-red.svg?link=http://left\u0026link=http://right)\n![Alt text](https://img.shields.io/badge/IOSVersion-8.0+-green.svg)\n![Alt text](https://img.shields.io/badge/BuildVersion-1.0.0-green.svg)\n![Alt text](https://img.shields.io/badge/Author-JamesDouble-blue.svg?link=http://https://jamesdouble.github.io/index.html\u0026link=http://https://jamesdouble.github.io/index.html)\n\n\n## Installation\n* Cocoapods\n\n```\npod 'RandMyMod'\n```\n\n# Basic Usage\n\n* ### Model must conform *Codable*\n\n```swift\nimport RandMyMod\n```\n\n* **Create a Random Model**\n\n\t```swift\n\tlet instance = MyStruct()\n\tRandMyMod\u003cMyStruct\u003e().randMe(baseOn: instance) { \n\t\t(newInstance) in\n    \tguard let newinstance = newInstance else { print(\"error\"); return }\n    }\n\t```\n\n* **Create a set of Random Model**\n\n\t```swift\n\tlet instance = MyStruct()\n\tRandMyMod\u003cMyStruct\u003e().randUs(baseOn: instance) { \n\t\t(newInstanceArr) in\n    \tfor newInstance in newInstanceArr {\n    \t\tguard let newinstance = newInstance else { print(\"error\"); return }\n    \t}\n    }\n\t```\n\t\n* **RandMyModDelegate**\n\n\t```swift\n\tpublic protocol RandMyModDelegate {\n    \tfunc countForArray(for key: String) -\u003e Int\n    \tfunc shouldIgnore(for key: String, in Container: String) -\u003e Bool\n    \tfunc catchError(with errorStr: String)\n    \tfunc specificRandType(for key: String, in Container: String, with seed: RandType) -\u003e (()-\u003eAny)?\n\t}\n\t```\n\n* **Swift fake data generator**\n\n \t*vadymmarkov/Fakery : https://github.com/vadymmarkov/Fakery*\n\t\n# Notice\n\n1. if the variable in class / stuct is Declared with **『 let 』** , rand mod will not change this variable's value.\n\n\t```swift \n\tstruct MyStruct {\n\t\tlet nochange: Int = 0\n\t}\n\tlet mystruct = MyStruct()\n\tRandMyMod\u003cMyStruct\u003e().randMe(baseOn: mystruct) { (newstruct) in \n\t\tnewstruct.nochange  // 0\n\t}\n\t```\n\t\n2. if the variable in class / stuct is Declared with **『 Optional 』** and ***have no initial Value*** , rand mod will ignore this variable's value and keep it nil.\t(Mirror may resolve this issue, may fix in the future)\n\n\t```swift \n\tstruct MyStruct {\n\t\tvar opt: Int? = 0\n\t\tvar opt2: Int?\n\t}\n\tlet mystruct = MyStruct()\n\tRandMyMod\u003cMyStruct\u003e().randMe(baseOn: mystruct) { (newstruct) in \n\t\tmystruct.opt  // 4242\n\t\tmystruct.opt2 // nil\n\t}\n\t```\n\t\n\t\n# Example\n\n### 1. Stuct / Class with native variable type and no special specific:\n\n```swift\n\tclass Man: Codable {\n    \tvar name: String = \"\"\n    \tvar address: String = \"\"\n    \tvar website: [String] = []\n   \t}\n   \t\n   \tlet man = Man()\n\tRandMyMod\u003cMan\u003e().randMe(baseOn: man) { (newMan) in\n    \tguard let new = newMan else { return }\n    \tprint(new.address) \t//mnxvpkalug\n    \tprint(new.name) \t//iivjohpggb\n    \tprint(new.website)\t//[\"pbmsualvei\", \"vlqhlwpajf\", \"npgtxdmfyt\"]\n\t}\n\t\n```\n\t\n### 2. Stuct / Class with native variable type and specific Rand Type:\n\n```swift\nstruct Man: Codable {\n    var name: String = \"\"\n    var age: Int = 40\n    var website: [String] = []\n}\n\nextension Man: RandMyModDelegate {\n    \n    func countForArray(for key: String) -\u003e Int {\n        switch key {\n        case \"website\":\n            return 3\n        default:\n            return 0\n        }\n    }\n    \n    func specificRandType(for key: String, in Container: String, with seed: RandType) -\u003e (() -\u003e Any)? {\n        switch key {\n        case \"name\":\n            return { return seed.name.name() }\n        case \"age\":\n            return { return seed.number.randomInt(min: 1, max: 60)}\n        case \"website\":\n            return { return seed.internet.url() }\n        default:\n            return nil\n        }   \n    }\n}\n\nlet man = Man()\nRandMyMod\u003cMan\u003e().randMe(baseOn: man) { (newMan) in\n    guard let new = newMan else { print(\"no\"); return }\n    print(new.age) \t\t//32\n    print(new.name) \t//Lavada Krajcik\n    print(new.website)\t//[\"https://littleohara.name/johathangleason6379\", \"https://kautzerwunsch.biz/karleejones8880\", \"https://purdy.net/olivercorkery\"]\n}\n```\n\n### 3. Stuct / Class with own defined variable type and specific Rand Type:\n\t \n```swift \nstruct Man: Codable {\n    var name: String = \"\"\n    var age: Int = 40\n    var website: [String] = []\n    var child: Child = Child()\n}\n\nstruct Child: Codable {\n    var name: String = \"Baby\" //Baby has no name yet.\n    var age: Int = 2\n    var toy: Toys = Toys()\n}\n\nclass Toys: Codable {\n    var weight: Double = 0.0\n}\n\nextension Man: RandMyModDelegate {\n    \n    func shouldIgnore(for key: String, in Container: String) -\u003e Bool {\n        switch (key, Container) {\n        case (\"name\",\"child\"):\n            return true\n        default:\n            return false\n        }\n    }\n  \n    func specificRandType(for key: String, in Container: String, with seed: RandType) -\u003e (() -\u003e Any)? {\n        switch (key, Container) {\n        case (\"age\",\"child\"):\n            return { return seed.number.randomInt(min: 1, max: 6)}\n        case (\"weight\",_):\n            return { return seed.number.randomFloat() }\n        default:\n            return nil\n        }\n    }\n}\n\nlet man = Man()\nRandMyMod\u003cMan\u003e().randMe(baseOn: man) { (newMan) in\n    guard let child = newMan?.child else { print(\"no\"); return }\n    print(child.name)\t//Baby\n    print(child.age)\t//3\n    print(child.toy.weight)\t//392.807067871094\n}\n\n\n```\n\n# Distribution\n\nFeel free to fork / pull request / open an issue.\n\t\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesdouble%2FRandMyMod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamesdouble%2FRandMyMod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamesdouble%2FRandMyMod/lists"}