{"id":15481584,"url":"https://github.com/arturdev/structify","last_synced_at":"2025-08-19T14:15:04.704Z","repository":{"id":62456162,"uuid":"169139599","full_name":"arturdev/Structify","owner":"arturdev","description":"Convert Swift structs to Objc Classes on the fly!","archived":false,"fork":false,"pushed_at":"2019-06-09T11:08:33.000Z","size":27616,"stargazers_count":52,"open_issues_count":1,"forks_count":5,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-16T04:47:02.029Z","etag":null,"topics":["class","objective-c","realm","struct","struct-to-class","structs","swift"],"latest_commit_sha":null,"homepage":null,"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/arturdev.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":"2019-02-04T19:56:16.000Z","updated_at":"2024-03-14T21:11:44.000Z","dependencies_parsed_at":"2022-11-01T23:04:19.652Z","dependency_job_id":null,"html_url":"https://github.com/arturdev/Structify","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturdev%2FStructify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturdev%2FStructify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturdev%2FStructify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arturdev%2FStructify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arturdev","download_url":"https://codeload.github.com/arturdev/Structify/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250269899,"owners_count":21402958,"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":["class","objective-c","realm","struct","struct-to-class","structs","swift"],"created_at":"2024-10-02T05:05:00.731Z","updated_at":"2025-04-22T15:41:11.534Z","avatar_url":"https://github.com/arturdev.png","language":"Swift","readme":"# Structify\n\n[![Version](https://img.shields.io/cocoapods/v/Structify.svg?style=flat)](https://cocoapods.org/pods/Structify)\n[![License](https://img.shields.io/cocoapods/l/Structify.svg?style=flat)](https://cocoapods.org/pods/Structify)\n[![Platform](https://img.shields.io/cocoapods/p/Structify.svg?style=flat)](https://cocoapods.org/pods/Structify)\n\nStructify is designed to make your life much easier especially when you want to deal with Swift structs rather than Objective-C classes and you have to manually convert your structs to classes and vice-a-versa to acheive that.\u003cbr\u003e\nThe most obvious example is `Realm`.\u003cbr\u003e\n\nFor example, assume you have a struct named `User` and you want to save it to `Realm`'s db.\u003cbr\u003e\nAs you already know `Realm` doesn't support Swift structs, so the most common solution is making a pair class (which will have the same properties) and manually writing convertion methods.\n\n#### Without Structify\n```Swift\nstruct User {\n    let address: String\n    let company: String\n    let email: String\n    let name: String\n    let phone: String\n    let uid: String\n    let username: String\n    let website: String\n    let birthday: Date\n}\n\nclass RLMUser: Object {\n\n    @objc dynamic var address: String = \"\"\n    @objc dynamic var company: String = \"\"\n    @objc dynamic var email: String = \"\"\n    @objc dynamic var name: String = \"\"\n    @objc dynamic var phone: String = \"\"\n    @objc dynamic var uid: String = \"\"\n    @objc dynamic var username: String = \"\"\n    @objc dynamic var website: String = \"\"\n    @objc dynamic var birthday: Date = Date()\n    \n    override class func primaryKey() -\u003e String? {\n        return \"uid\"\n    }\n}\n\nextension RLMUser {\n    func toStruct() -\u003e User {\n        return User(address: address,\n                    company: company,\n                    email: email,\n                    name: name,\n                    phone: phone,\n                    uid: uid,\n                    username: username,\n                    website: website,\n                    birthday: birthday)\n    }\n}\n\nextension User {\n    func toObject() -\u003e RLMUser {\n        return RLMUser.build { object in\n            object.uid = uid\n            object.address = address\n            object.company = company\n            object.email = email\n            object.name = name\n            object.phone = phone\n            object.username = username\n            object.website = website\n            object.birthday = birthday\n        }\n    }\n}\n```\n\nAt a first glance it seems very convenient method. But what if your struct isn't so small and have much more properties? What if you have too many structs like `User`? What if you want to add more properties to existing structs during the development? You will have to write that boilerplate code for each of your structs! And if you forget also to add those additional properties into the Realm's pair-class you'll get bugs as a bonus!\u003cbr\u003e\nAgree, pretty annoying. \u003cb\u003eSo here Structify comes to rescue!\u003c/b\u003e\n\nLong story short:\n#### With Structify\n```Swift\nstruct User {\n    var address: String = \"\"\n    var company: String = \"\"\n    var email: String = \"\"\n    var name: String = \"\"\n    var phone: String = \"\"\n    var uid: String = \"\"\n    var username: String = \"\"\n    var website: String = \"\"\n    var birthday: Date = Date()\n}\n\nclass RLMUser: Object {\n    //you only set the primaryKey as usual \n    override class func primaryKey() -\u003e String? {\n        return \"uid\"\n    }\n}\n\nextension RLMUser: StructConvertible {\n    typealias StructType = User\n}\n\nextension User: ObjectConvertible {\n    typealias ClassType = RLMUser\n}\n```\nPretty easy, huh? \u003cbr\u003e\nThe only thing you need to do is make your struct to conform to `ObjectConvertible` protocol and make a Objective-C pair class and conform to `StructConvertible` protocol. You're done! \n\n\n## Example\n\n```Swift\nlet user = User(address: \"Some address\",\n                company: \"Some company\",\n                email: \"structify@example.com\",\n                name: \"John\",\n                phone: \"Doe\",\n                uid: \"90jq0j30n0nc02930293\",\n                username: \"arturdev\",\n                website: \"http://github.com\",\n                birthday: Date())\n        \nlet rlmUser = user.toObject()\nprint(rlmUser)\n/*\nConsole:\n\nRLMUser {\n\taddress = Some address;\n\tcompany = Some company;\n\temail = structify@example.com;\n\tname = John;\n\tphone = Doe;\n\tuid = 90jq0j30n0nc02930293;\n\tusername = arturdev;\n\twebsite = http://github.com;\n\tbirthday = 2019-02-08 14:00:41 +0000;\n}\n*/\n\n```\n\nTo see the example project, clone the repo, and run `pod install` from the Example directory first, then open Tests.swift\n\n## Requirements\n\n- iOS  8.0+\n- Xcode 10.+\n- Swift 4.2+\n\n## Installation\n\nStructify is available through [CocoaPods](https://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'Structify'\n```\n\n## Author\n\narturdev, mkrtarturdev@gmail.com\n\n## License\n\nStructify is available under the MIT license. See the \u003ca href = \"https://github.com/arturdev/Structify/blob/master/LICENSE\"\u003eLICENSE\u003c/a\u003e file for more info.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farturdev%2Fstructify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farturdev%2Fstructify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farturdev%2Fstructify/lists"}