{"id":18132035,"url":"https://github.com/cemolcay/protocolorientedviewmodel","last_synced_at":"2025-10-03T22:35:12.003Z","repository":{"id":62451225,"uuid":"90065329","full_name":"cemolcay/ProtocolOrientedViewModel","owner":"cemolcay","description":"Create universal view's with different layouts for each platform and share the view logic between them.","archived":false,"fork":false,"pushed_at":"2019-11-28T21:10:39.000Z","size":33,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-20T03:48:04.244Z","etag":null,"topics":["protocol-oriented","protocol-oriented-programming","swift","view-model"],"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/cemolcay.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":"2017-05-02T18:29:47.000Z","updated_at":"2024-03-02T15:17:22.000Z","dependencies_parsed_at":"2022-11-01T23:34:10.766Z","dependency_job_id":null,"html_url":"https://github.com/cemolcay/ProtocolOrientedViewModel","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cemolcay/ProtocolOrientedViewModel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cemolcay%2FProtocolOrientedViewModel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cemolcay%2FProtocolOrientedViewModel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cemolcay%2FProtocolOrientedViewModel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cemolcay%2FProtocolOrientedViewModel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cemolcay","download_url":"https://codeload.github.com/cemolcay/ProtocolOrientedViewModel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cemolcay%2FProtocolOrientedViewModel/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271672867,"owners_count":24800706,"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-22T02:00:08.480Z","response_time":65,"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":["protocol-oriented","protocol-oriented-programming","swift","view-model"],"created_at":"2024-11-01T12:10:05.218Z","updated_at":"2025-10-03T22:35:06.949Z","avatar_url":"https://github.com/cemolcay.png","language":"Swift","readme":"ProtocolOrientedViewModel\n===\n\nCreate universal view's with different layouts for each platform and share the view logic between them.\n\nRequirements\n----\n\n- Swift 3.0+\n- iOS 8.0+\n- tvOS 9.0+\n- macOS 10.10+\n\nInstall\n----\n\n```\nuse_frameworks!\npod 'ProtocolOrientedViewModel'\n```\n\nUsage\n----\n\nThis is most useful for universal ios/tvos/mac projects.  \nCreate `Layout`s for your view. For example, portrait and landscape.  \nCreate xib's for each layout of each platform or just create them programmaitaclly.\n\n``` swift\nenum HomeScreenLayout: Layout {\n  case portrait\n  case landscape\n\n  // Define the type of view\n  typealias ViewType = HomeScreenView\n  var view: HomeScreenView? {\n    // return from xib or create and return them here for each layout.\n  }\n}\n```\n\nCreate your view and its delegate with actions.\n\n``` swift\nprotocol HomeScreenViewDelegate: class {\n  func homeScreenViewDidPressSomething(_ homeScreenView: HomeScreenView)\n  ...\n}\n\nclass HomeScreenView: POView { // POView is a typealias of NSView and UIView for sharing view.\n  weak var delegate: HomeScreenViewDelegate?\n  @IBOutlet var someLabel: UILabel?\n\n  @IBAction func somethingDidPress() {\n    delegate?.homeScreenViewDidPressSomething(self)\n  }\n\n  ...\n}\n```\n\nAnd create your view model\n\n``` swift\nclass HomeScreenViewModel: ViewModel, HomeScreenViewDelegate {\n\n  // MARK: ViewModel\n  // define the type of view\n  typealias ViewType = HomeScerenView\n  var view: HomeScrenView? { didSet{ view?.delegate = self }}\n\n  // Make your updates for your view.\n  typealias LayoutType = ExampleLayout\n  func render(layout: ExampleLayout?) {\n    view?.someLabel?.text = dataSource.someValue\n    view?...\n\n    if let layout = layout, case .portrait = layout {\n      // Do layout specific stuff.\n    }\n  }\n\n  // MARK: HomeScreenViewDelegate\n  func homeScreenViewDidPressSomething(_ homeScreenView: HomeScreenView) {\n    dataSource.someValue = \"new value\"\n    render(layout: nil)\t\n  }\n\n  ...\n}\n```\n\nCall `updateLayoutFor:InView:` function on the view model to update layout of your view.  \nAlso see the example project for universal usage with multiple layouts with xibs in multiple platforms.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcemolcay%2Fprotocolorientedviewmodel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcemolcay%2Fprotocolorientedviewmodel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcemolcay%2Fprotocolorientedviewmodel/lists"}