{"id":18284265,"url":"https://github.com/blkbrds/realms-ios","last_synced_at":"2025-04-05T07:31:29.994Z","repository":{"id":62452667,"uuid":"49371350","full_name":"blkbrds/realms-ios","owner":"blkbrds","description":"Safe method for Realm","archived":false,"fork":false,"pushed_at":"2019-12-09T06:30:50.000Z","size":239,"stargazers_count":20,"open_issues_count":2,"forks_count":5,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-04-01T21:59:30.000Z","etag":null,"topics":["objectmapper","realm","realmswift"],"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/blkbrds.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-01-10T14:57:10.000Z","updated_at":"2023-08-20T04:29:53.000Z","dependencies_parsed_at":"2022-11-01T23:45:49.579Z","dependency_job_id":null,"html_url":"https://github.com/blkbrds/realms-ios","commit_stats":null,"previous_names":["tsrnd/realms-ios"],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blkbrds%2Frealms-ios","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blkbrds%2Frealms-ios/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blkbrds%2Frealms-ios/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blkbrds%2Frealms-ios/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blkbrds","download_url":"https://codeload.github.com/blkbrds/realms-ios/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247305714,"owners_count":20917197,"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":["objectmapper","realm","realmswift"],"created_at":"2024-11-05T13:12:52.944Z","updated_at":"2025-04-05T07:31:24.986Z","avatar_url":"https://github.com/blkbrds.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/tsrnd/realms-ios.svg?branch=master)](https://travis-ci.org/tsrnd/realms-ios)\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/RealmS.svg)](https://img.shields.io/cocoapods/v/RealmS.svg)\n[![Platform](https://img.shields.io/cocoapods/p/RealmS.svg?style=flat)](http://cocoadocs.org/docsets/RealmS)\n[![Coverage Status](https://codecov.io/github/tsrnd/realms-ios/coverage.svg?branch=master)](https://codecov.io/github/tsrnd/realms-ios?branch=master)\n\n[![RealmSwift](https://img.shields.io/badge/RealmSwift-~%3E%202.2-brightgreen.svg)](https://img.shields.io/badge/RealmSwift-~%3E%202.2-brightgreen.svg)\n[![ObjectMapper](https://img.shields.io/badge/ObjectMapper-~%3E%202.2-brightgreen.svg)](https://img.shields.io/badge/ObjectMapper-~%3E%202.2-brightgreen.svg)\n\nRealm + ObjectMapper\n====================\n\n## Requirements\n\n - iOS 8.0+\n - Xcode 9.2 (Swift 4.0+)\n\n## Installation\n \n \u003e Embedded frameworks require a minimum deployment target of iOS 8\n\n### CocoaPods\n\n[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:\n\n```bash\n$ gem install cocoapods\n ```\n\n\u003e CocoaPods 1.2+ is required to build RealmS 2.3+\n\nTo integrate RealmS into your Xcode project using CocoaPods, specify it in your `Podfile`:\n\n```ruby\nsource 'https://github.com/CocoaPods/Specs.git'\nplatform :ios, '8.0'\nuse_frameworks!\n\npod 'RealmS', '~\u003e 4.0.0'\n```\n\nThen, run the following command:\n\n```bash\n$ pod install\n```\n\n## Usage\n\n### Mapping\n\n**Rule:**\n- Object has `primaryKey` must be StaticMappable (i)\n- Object has no `primaryKey` should be Mappable (ii)\n\n```swift\nimport RealmSwift\nimport ObjectMapper\nimport RealmS\n\n// (i)\nfinal class User: Object, StaticMappable {\n    @objc dynamic var id: String!\n    @objc dynamic var name: String?\n    @objc dynamic var address: Address?\n    let dogs = List\u003cPet\u003e()\n\n    override class func primaryKey() -\u003e String? {\n        return \"id\"\n    }\n\n    func mapping(map: Map) {\n        name \u003c- map[\"name\"]\n        address \u003c- map[\"address\"]\n        dogs \u003c- map[\"dogs\"]\n    }\n\n    static func objectForMapping(map: Map) -\u003e BaseMappable? {\n        return RealmS().object(ofType: self, forMapping: map)\n    }\n}\n\n// (ii)\nfinal class Address: Object, Mappable {\n    @objc dynamic var street = \"\"\n    @objc dynamic var city = \"\"\n    @objc dynamic var country = \"\"\n\n    @objc dynamic var phone: Phone?\n\n    let users = LinkingObjects(fromType: User.self, property: \"address\")\n\n    convenience required init?(map: Map) {\n        self.init()\n    }\n\n    func mapping(map: Map) {\n        street \u003c- map[\"street\"]\n        city \u003c- map[\"city\"]\n        country \u003c- map[\"country\"]\n        phone \u003c- map[\"phone\"]\n    }\n}\n```\n\n### Import JSON to Realm\n\n```swift\nlet realm = RealmS()\nrealm.write {\n  realm.map(User.self, jsUser) // map JSON object\n  realm.map(Shop.self, jsShops) // map JSON array\n}\n```\n\n\u003e - `nil` value will be bypass, if you want set `nil` please use `NSNull()` instead.\n\n### Clean Up\n\n```swift\nextension User {\n    override public class func relativedTypes() -\u003e [Object.Type] {\n        return [Address.self, Pet.self]\n    }\n\n    override public class func clean() { }\n}\n\nextension Address {\n    override class func relativedTypes() -\u003e [Object.Type] {\n        return [Phone.self]\n    }\n\n    override class func clean() {\n        let realm = RealmS()\n        let objs = realm.objects(self).filter(\"users.@count = 0\")\n        realm.write {\n            realm.delete(objs)\n        }\n    }\n}\n```\n\n`Address` table will be clean-up after a `User` is deleted from Realm.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblkbrds%2Frealms-ios","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblkbrds%2Frealms-ios","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblkbrds%2Frealms-ios/lists"}