{"id":1344,"url":"https://github.com/mattcomi/ReflectedStringConvertible","last_synced_at":"2025-08-02T04:30:52.499Z","repository":{"id":62452728,"uuid":"56566334","full_name":"mattcomi/ReflectedStringConvertible","owner":"mattcomi","description":"A protocol that allows any class to be printed as if it were a struct or a JSON object.","archived":false,"fork":false,"pushed_at":"2022-11-08T04:34:20.000Z","size":44,"stargazers_count":65,"open_issues_count":2,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-06-13T17:53:33.770Z","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/mattcomi.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":"2016-04-19T05:10:19.000Z","updated_at":"2024-05-06T03:40:55.000Z","dependencies_parsed_at":"2022-11-01T23:46:20.446Z","dependency_job_id":null,"html_url":"https://github.com/mattcomi/ReflectedStringConvertible","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/mattcomi/ReflectedStringConvertible","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattcomi%2FReflectedStringConvertible","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattcomi%2FReflectedStringConvertible/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattcomi%2FReflectedStringConvertible/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattcomi%2FReflectedStringConvertible/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mattcomi","download_url":"https://codeload.github.com/mattcomi/ReflectedStringConvertible/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mattcomi%2FReflectedStringConvertible/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268334607,"owners_count":24233793,"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","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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:44.286Z","updated_at":"2025-08-02T04:30:52.197Z","avatar_url":"https://github.com/mattcomi.png","language":"Swift","funding_links":[],"categories":["Logging"],"sub_categories":["Other Hardware","Other free courses"],"readme":"[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![](https://img.shields.io/cocoapods/v/ReflectedStringConvertible.svg?style=flat)](https://cocoapods.org/pods/ReflectedStringConvertible)\n[![Platform](https://img.shields.io/cocoapods/p/ReflectedStringConvertible.svg?style=flat)](http://cocoadocs.org/docsets/ReflectedStringConvertible)\n\n# ReflectedStringConvertible\nA protocol that extends `CustomStringConvertible` and uses reflection to add a\ndetailed textual representation to any class. Two styles are supported:\n\n1. `normal`: Similar to Swift's default textual representation of structs.\n2. `json`: Pretty JSON representation.\n\n## Installation\n\n### Cocoapods\n\nAdd the following to your Podfile:\n\n```\npod 'ReflectedStringConvertible'\n```\n\n### Carthage\n\nAdd the following to your Cartfile:\n\n```\ngithub \"mattcomi/ReflectedStringConvertible\"\n```\n\n## Usage\n\nSimply import `ReflectedStringConvertible` and conform to the\n`ReflectedStringConvertible` protocol:\n\n```swift\nimport ReflectedStringConvertible\n\nclass YourClass: ReflectedStringConvertible {\n  // that's all.\n}\n```\n\nFor example:\n\n```swift\nclass Person: ReflectedStringConvertible {\n  var name: String\n  var age: Int\n\n  init(name: String, age: Int) {\n    self.name = name\n    self.age = age\n  }\n}\n```\n\n`print(Person(name: \"Matt\", age: 33))` outputs:\n\n```\nPerson(name: \"Matt\", age: 33)\n```\n\nA style may be specified with `reflectedDescription(style:)`. The default style is `normal`. That is, calling `description` is the same as calling `reflectedDescription(.normal)`.\n\nFor example, `print(Person(name: \"Matt\", age: 33).reflectedDescription(.json))` outputs:\n\n```\n{\n  \"age\" : 33,\n  \"name\" : \"Matt\"\n}\n```\n\nRefer to the  [API Documentation](http://cocoadocs.org/docsets/ReflectedStringConvertible) for further information.\n\n## Features\n\n### `ReflectedStringConvertible` stored properties\n\n`ReflectedStringConvertible` objects with `ReflectedStringConvertible` stored properties are handled correctly:\n\n```swift\nclass Movie: ReflectedStringConvertible {\n  var title: String\n  var year: Int\n\n  // another ReflectedStringConvertible\n  var director: Person\n\n  init(title: String, year: Int, director: Person) {\n    self.title = title\n    self.year = year\n    self.director = director\n  }\n}\n\nlet george = Person(name: \"George Miller\", age: 71)\nlet movie = Movie(title: \"Mad Max\", year: 2015, director: george)\n```\n\n`print(movie.reflectedDescription(.normal))` (or just `print(movie)`) outputs:\n\n```\nMovie(title: \"Mad Max\", year: 2015, director: Person(name: \"George Miller\", age: 71))\n```\n\nAnd `print(movie.reflectedDescription(.json))` outputs:\n\n```\n{\n  \"title\" : \"Mad Max\",\n  \"year\" : 2015,\n  \"director\" : {\n    \"age\" : 71,\n    \"name\" : \"George Miller\"\n  }\n}\n```\n\n### Collections\n\n`ReflectedStringConvertible` objects within `Array`, `Dictionary` and `Set` collections are handled correctly:\n\n```swift\nclass Series: ReflectedStringConvertible {\n  var title: String\n  var cast: [Person]\n\n  init(title: String, cast: [Person]) {\n    self.cast = cast\n  }\n}\n\nvar cast = [Person]()\n\ncast.append(Person(name: \"Justin Theroux\", age: 44))\ncast.append(Person(name: \"Carrie Coon\", age: 35))\n\nlet series = Series(title: \"The Leftovers\", cast: cast)\n```\n\n`print(series)` outputs:\n\n```\nTVShow(title: \"The Leftovers\", cast: [Person(name: \"Justin Theroux\", age: 44), Person(name: \"Carrie Coon\", age: 35)])\n```\n\n`print(series.reflectedDescription(.json))` outputs:\n\n```\n{\n  \"title\" : \"The Leftovers\",\n  \"cast\" : [\n    {\n      \"age\" : 44,\n      \"name\" : \"Justin Theroux\"\n    },\n    {\n      \"age\" : 35,\n      \"name\" : \"Carrie Coon\"\n    }\n  ]\n}\n```\n\n## Credits\n\nDeveloped by Matt Comi ([@mattcomi](http://twitter.com/mattcomi))\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattcomi%2FReflectedStringConvertible","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmattcomi%2FReflectedStringConvertible","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmattcomi%2FReflectedStringConvertible/lists"}