{"id":16853205,"url":"https://github.com/devxoul/jlmodel","last_synced_at":"2025-03-18T10:23:32.084Z","repository":{"id":11900030,"uuid":"14463518","full_name":"devxoul/JLModel","owner":"devxoul","description":"JLModel allows you to manage models in very simple way.","archived":false,"fork":false,"pushed_at":"2014-04-30T08:28:07.000Z","size":232,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-24T16:43:18.102Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devxoul.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-17T08:17:02.000Z","updated_at":"2019-11-26T13:38:21.000Z","dependencies_parsed_at":"2022-09-07T02:52:12.001Z","dependency_job_id":null,"html_url":"https://github.com/devxoul/JLModel","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/devxoul%2FJLModel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxoul%2FJLModel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxoul%2FJLModel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxoul%2FJLModel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devxoul","download_url":"https://codeload.github.com/devxoul/JLModel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244199081,"owners_count":20414584,"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-10-13T13:50:11.695Z","updated_at":"2025-03-18T10:23:32.062Z","avatar_url":"https://github.com/devxoul.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JLModel\n\nJLModel allows you to manage models in very simple way.\n\n\n## Installation\n\n### Using git submodule\n\n```\n$ git submodule add https://github.com/Joyfl/JLModel.git myproject/libs/JLModel\n$ git submodule update\n```\n\nThen add folder to your Xcode project.\n\n\n### or just download it.\n\n\n## Defining Model Classes\n\n### Basic Types\n\nModel classes are subclass of JLModel. Don't forget to write a `Model()` in `.h` files. `Model()` makes it available to use short type definition and relationship definition.\n\n###### Sample model class definition:\n\n\n```\n#import \"JLModel.h\"\n\nModel(User) // DON'T forget this.\n\n@interface User : JLModel\n\nInteger id;\nString name;\nDate created_time;\n\n@end\n```\n\n### Relationship\n\nYou can define relationship between models with `ToOne()` and `ToMany()`. These need first argument as target model class.\n\n###### One-to-one relationship example:\n```\n#import \"Address.h\" // Another model class\n...\nInteger id;\nString name;\nToOne(Address) address;\n```\n\n###### One-to-many relationship example:\n```\n#import \"Post.h\" // Another model class\n...\nInteger id;\nString name;\nToMany(Post) posts;\n```\n\n### Non-model Array\nIf there's an array of primitive type or non-model type, you can use `Array` to describe it. `Array` object can contain any type of data such as `NSInteger`, `NSDictionary`.\n```\nArray myArray;\n```\n\n### All types\n\n| Type | Converted to |\n|---|---|\n| Integer | NSNumber * |\n| Float | NSNumber * |\n| Boolean | NSNumber * |\n| String | NSString * |\n| Date | NSDate * |\n| Array | NSArray * |\n| ToMany | NSArray\\\u003cClass\u003e * |\n| ToOne | Class * |\n\n## Creating Model Instance\n\n### Empty Model Instance\n\nYou can create model instance with objective-c grammar.\n\n```\nuser = [[User alloc] init];\n```\n\n### Model with Dictionary\n\nJLModel supports initializing from an `NSDictionary` object. Name of model class properties and its of `NSDictionary` keys need to be same.\n\nFor example, you retrieved a JSON data like below:\n\n```\n{\n\t\"id\": 3,\n\t\"name\": \"devxoul\",\n\t\"posts\": [\n\t\t{\n\t\t    \"id\": 120,\n\t\t    \"title\": \"Awesome Framework: JLModel\",\n\t\t    \"content\": \"It is awesome!\"\n\t    },\n\t    {\n\t    \t\"id\": 142,\n\t    \t\"title\": \"Hello, World!\",\n\t    \t\"content\": \"Good morning guys.\"\n\t    }\n\t]\n}\n```\n\nand defined model class like below:\n```\n#import \"JLModel.h\"\n#import \"Post.h\"\n\nModel(User)\n\n@interface User : JLModel\n\nInteger id;\nString name;\nToMany(Post) posts;\n\n@end\n```\n\nThen you can create model class instance with `- [JLModel initWithDictionary:]` method.\n\n```\nNSDictionary *userDict = // NSDictionary from retrieved JSON.\nUser *user = [[User alloc] initWithDictionary:userDict];\n\n// User: id=3, name=devxoul\nNSLog(@\"User: id=%@, name=%@\", user.id, user.name);\n\n// Posts: 2\nNSLog(@\"Posts: %d\", user.posts.count);\n```\n\n## Warning\n\nThis is on development. Please care of using.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevxoul%2Fjlmodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevxoul%2Fjlmodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevxoul%2Fjlmodel/lists"}