{"id":24010770,"url":"https://github.com/andreadelfante/predicateflow","last_synced_at":"2025-10-05T19:56:49.044Z","repository":{"id":29907506,"uuid":"123034310","full_name":"andreadelfante/PredicateFlow","owner":"andreadelfante","description":"Write amazing, strong-typed and easy-to-read NSPredicate.","archived":false,"fork":false,"pushed_at":"2023-03-17T05:48:13.000Z","size":1981,"stargazers_count":100,"open_issues_count":2,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-05T19:56:47.147Z","etag":null,"topics":["autogenerated","cocoapods","code-generation","coredata","flow","ios","library","macos","nspredicate","nspredicates","pods","realm","realmswift","swift","tvos","watchos"],"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/andreadelfante.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-02-26T21:40:31.000Z","updated_at":"2025-01-14T03:07:03.000Z","dependencies_parsed_at":"2024-01-02T20:55:02.611Z","dependency_job_id":"e80c83d3-bd49-40b7-a3e9-cc94040c4c58","html_url":"https://github.com/andreadelfante/PredicateFlow","commit_stats":{"total_commits":126,"total_committers":7,"mean_commits":18.0,"dds":0.2857142857142857,"last_synced_commit":"2b28c7bc51cb2da4af681add62d5132228a37541"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/andreadelfante/PredicateFlow","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreadelfante%2FPredicateFlow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreadelfante%2FPredicateFlow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreadelfante%2FPredicateFlow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreadelfante%2FPredicateFlow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreadelfante","download_url":"https://codeload.github.com/andreadelfante/PredicateFlow/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreadelfante%2FPredicateFlow/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278510917,"owners_count":25998997,"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-10-05T02:00:06.059Z","response_time":54,"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":["autogenerated","cocoapods","code-generation","coredata","flow","ios","library","macos","nspredicate","nspredicates","pods","realm","realmswift","swift","tvos","watchos"],"created_at":"2025-01-08T04:16:10.637Z","updated_at":"2025-10-05T19:56:49.025Z","avatar_url":"https://github.com/andreadelfante.png","language":"Swift","readme":"# PredicateFlow\n\n[![Build Status](https://travis-ci.org/andreadelfante/PredicateFlow.svg?branch=master)](https://travis-ci.org/andreadelfante/PredicateFlow)\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/PredicateFlow.svg)](https://cocoapods.org/pods/PredicateFlow)\n![Platform](https://img.shields.io/cocoapods/p/PredicateFlow.svg?style=flat)\n[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/dwyl/esta/issues)\n![License](https://img.shields.io/cocoapods/l/PredicateFlow.svg?style=flat)\n\nWrite amazing, strong-typed and easy-to-read NSPredicate. This library allows you to write flowable NSPredicate, without guessing attribution names, predicate operation or writing wrong arguments type.\n\n## Supported platforms\n\n* iOS 9.0+\n* macOS 10.9+\n* tvOS 9.0+\n* watchOS 2.0+\n\n## Installation\n[CocoaPods](http://cocoapods.org) is actually the only way to install it.\n\n### Cocoapods\n\n\u003e CocoaPods 0.39.0+ is required to build this library\n\n1. Add `pod 'PredicateFlow'` to your [Podfile](http://cocoapods.org/#get_started) and run `pod install`\n2. In Xcode, click on your project in the file list, choose your target under `TARGETS`, click the `Build Phases` tab and add a `New Run Script Phase` by clicking the plus icon in the top left\n3. Drag the new `Run Script` phase **above** the `Compile Sources` phase and **below** `Check Pods Manifest.lock`, expand it and paste the following script:  \n   ```\n   \"$PODS_ROOT/Sourcery/bin/sourcery\" --sources \"$PODS_ROOT/PredicateFlow/PredicateFlow/Classes/Utils/\" --sources \"$SRCROOT\" --templates \"$PODS_ROOT/PredicateFlow/PredicateFlow/Templates/PredicateFlow.stencil\" --output \"$SRCROOT/PredicateFlow.generated.swift\"\n   ```\n   \n   In case you are using **PredicateFlow-Realm**, past the following  script instead of the above one:\n   ```\n   \"$PODS_ROOT/Sourcery/bin/sourcery\" --sources \"$PODS_ROOT/PredicateFlow/PredicateFlow/Classes/Utils/\" --sources \"$SRCROOT\"  --sources \"$PODS_ROOT/RealmSwift\" --templates \"$PODS_ROOT/PredicateFlow/PredicateFlow/Templates/PredicateFlow-Realm.stencil\" --output \"$SRCROOT/PredicateFlow.generated.swift\"\n   ```\n   \n   For Xcode 10 only, add a new `Output Files` and paste the following:\n   ```\n   $SRCROOT/PredicateFlow.generated.swift\n   ```\n4. Build your project. In Finder you will now see a `PredicateFlow.generated.swift` in the `$SRCROOT`-folder, drag the `PredicateFlow.generated.swift` files into your project and **uncheck** `Copy items if needed`\n\n_Tip:_ Add the `*.generated.swift` pattern to your `.gitignore` file to prevent unnecessary conflicts.\n\n## Usage\n\nDefine a class/struct with its own attributes, which implements ```PredicateSchema```:\n```swift\nimport PredicateFlow\n\nclass Dog: PredicateSchema {\n\t\n\tprivate var name: String = \"\"\n\tprivate var age: Int = 0\n\tprivate var isHungry: Bool = false\n\tprivate var owner: Person?\n}\n\nclass Person: PredicateSchema {\n\t\n\tenum Sex {\n\t\tcase male\n\t\tcase female\n\t}\n\t\n\tprivate var name: String = \"\"\n\tprivate var birth: Date?\n\tprivate var sex: Sex!\n\tprivate var dogs: [Dog] = []\n}\n```\nBuild the project. PredicateFlow will autogenerate attributes references to build predicates, putting them in structures.\n```swift\n// Generated using Sourcery 0.10.0 — https://github.com/krzysztofzablocki/Sourcery\n// DO NOT EDIT\n\n\nimport PredicateFlow\n\n/// The \"Dog\" Predicate Schema\ninternal struct DogSchema: GeneratedPredicateSchema {\n    private var compoundFieldBuilder: CompoundFieldBuilder\n\n    /// DO NOT USE THIS INIT DIRECTLY!\n    internal init(compoundFieldBuilder: CompoundFieldBuilder) {\n        self.compoundFieldBuilder = compoundFieldBuilder\n    }\n\n    /// \"name\" property\n    internal var name: StringPredicateProperty { return builder.string(\"name\") }\n    /// \"name\" property for static access\n    internal static var name: StringPredicateProperty { return DogSchema().name }\n    \n    // Other properties of Dog class autogenerated...\n}\n/// The \"Person\" Predicate Schema\ninternal struct PersonSchema: GeneratedPredicateSchema {\n    private var compoundFieldBuilder: CompoundFieldBuilder\n\n    /// DO NOT USE THIS INIT DIRECTLY!\n    internal init(compoundFieldBuilder: CompoundFieldBuilder) {\n        self.compoundFieldBuilder = compoundFieldBuilder\n    }\n\n    /// \"name\" property\n    internal var name: StringPredicateProperty { return builder.string(\"name\") }\n    /// \"name\" property for static access\n    internal static var name: StringPredicateProperty { return PersonSchema().name }\n    \n    // Other properties of Person class autogenerated...\n}\n```\n\nTo type a floawable NSPredicate, just write:\n```swift\nDogSchema.age.isEqual(10).query()\n// or\n// Vanilla mode: \n// NSPredicate(\"age == %@\", 10)\n```\nYou can also write compound predicate, and use deeper fields:\n```swift\nPredicateBuilder(DogSchema.age \u003e 10)\n    .and(DogSchema.isHungry.isTrue)\n    .and(DogSchema.age.between(1, 10))\n    .and(DogSchema.owner.element().name == \"Foo\")\n    .or(DogSchema.owner.element().dogs.maxElements().age \u003e 10)\n    .or(DogSchema.owner.element().dogs.anyElements().name == \"Foo\")\n    .build()\n    \n// Vanilla mode: \n// NSPredicate(\"age \u003e %@ AND isHungry == %@ AND age BETWEEN %@ AND owner.name == %@ OR owner.dogs.@max.age \u003e %@ OR ANY owner.dogs.name == %@\", 10, true, [1, 10], \"Foo\", 10, \"Foo\")\n```\n\nPredicateFlow can also build KeyPaths, and you can use it to get a strong-typed one.\n```swift\nDogSchema.age.keyPath()\nDogSchema.owner.element().dogs.keyPath()\n\n// Vanilla mode:\n// \"age\"\n// \"owner.dogs\"\n```\n\n## PredicateFlow/Realm\n\nIf you want to use flowable and strong-typed queries in [Realm](https://github.com/realm/realm-cocoa), add **both** `pod 'PredicateFlow'` and `pod 'PredicateFlow/Realm'` to your [Podfile](http://cocoapods.org/#get_started) and run `pod install`.\n```swift\nlet realm = try! Realm()\nrealm.objects(Dog.self)\n    .filter(DogSchema.age.isGreater(than: 10))\n    .filter(DogSchema.isHungry.isTrue)\n    .sorted(DogSchema.age.ascending())\n    \n// Vanilla mode:\nrealm.objects(Dog.self)\n    .filter(\"age \u003e %@\", 10)\n    .filter(\"isHungry == %@\", true)\n    .sorted(\"age\", ascending: true)\n```\n\n## Contributing\n\nPredicateFlow is an open source project, so feel free to contribute.\nYou can open an issue for problems or suggestions, and you can propose your own fixes by opening a pull request with the changes.\n\n## License\n\nPredicateFlow is available under the MIT license. See the LICENSE file for more info.\n\n## Attributions\n\nThis library is powered by [Sourcery](https://github.com/krzysztofzablocki/Sourcery).\n\n## Author\n\nAndrea Del Fante, andreadelfante94@gmail.com\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreadelfante%2Fpredicateflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreadelfante%2Fpredicateflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreadelfante%2Fpredicateflow/lists"}