{"id":13872187,"url":"https://github.com/theblixguy/Invalidating","last_synced_at":"2025-07-16T02:30:28.546Z","repository":{"id":48975705,"uuid":"381179995","full_name":"theblixguy/Invalidating","owner":"theblixguy","description":"Backports the new @Invalidating property wrapper to older platforms","archived":false,"fork":false,"pushed_at":"2021-07-08T22:36:05.000Z","size":438,"stargazers_count":73,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-11-15T20:21:32.838Z","etag":null,"topics":["appkit","invalidating","ios","macos","property-wrapper","tvos","uikit"],"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/theblixguy.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":"2021-06-28T22:54:40.000Z","updated_at":"2024-05-04T06:44:09.000Z","dependencies_parsed_at":"2022-08-24T15:50:36.016Z","dependency_job_id":null,"html_url":"https://github.com/theblixguy/Invalidating","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theblixguy%2FInvalidating","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theblixguy%2FInvalidating/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theblixguy%2FInvalidating/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theblixguy%2FInvalidating/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theblixguy","download_url":"https://codeload.github.com/theblixguy/Invalidating/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226095606,"owners_count":17572958,"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":["appkit","invalidating","ios","macos","property-wrapper","tvos","uikit"],"created_at":"2024-08-05T23:00:36.126Z","updated_at":"2024-11-23T20:30:44.023Z","avatar_url":"https://github.com/theblixguy.png","language":"Swift","readme":"# ViewInvalidating\n\nA property wrapper that backports the new `@Invalidating` property wrapper to older versions of iOS/tvOS/macOS. For more information on this new property wrapper, see the WWDC 2021 talk [\"What's new in AppKit\"](https://developer.apple.com/wwdc21/10054) for a brief introduction.\n\nThe syntax and types closely follows what Apple is doing, so when it's time to finally update your project's deployment target to iOS 15+/tvOS 15+/macOS 12+, you can easily migrate to using Apple's version by making very minimal changes. See the [migration section](#migration-to-ios-15+/tvos-15+/macos-12+-deployment-target) for more info!\n\n## Usage\n\nAnnotate your `Equatable` properties with `@ViewInvalidating` and provide options that will be used to invalidate the view whenever the property's value changes:\n\n```swift\nfinal class MyView: UIView {\n  // Calls setNeedsLayout()\n  @ViewInvalidating(.layout) var cornerRadius: CGFloat = 12.0\n  \n  // Calls setNeedsLayout() then setNeedsUpdateConstraints()\n  @ViewInvalidating(.layout, .constraints) var heightConstraintValue: CFloat = 200.0\n  \n  // Calls setNeedsLayout() then setNeedsUpdateConstraints() then invalidateIntrinsicContentSize()\n  @ViewInvalidating(.layout, .constraints, .intrinsicContentSize) var magicProperty: CGFloat = 1234.0\n```\n\nYou can initialize the property wrapper with up to 10 options. You can of course add extensions to support more options though, but realistically speaking you'll likely never have a need to pass more than a few of them!\n\nBy default, there is support for a total of 5 invalidation options per platform:\n\n#### Common\n- Layout\n- Display\n- Constraints\n- Intrinsic Size\n\n#### macOS only\n- Restorable State\n\n#### iOS 14+ only\n- Configuration\n\n### Adding custom invalidators\n\nYou can add custom invalidators by creating a type that conforms to `UIViewInvalidatingType` or `NSViewInvalidatingType` protocol (depending on the target platform) and implementing the `invalidate` method requirement:\n\n```swift\nextension Invalidations {\n  struct Focus: UIViewInvalidatingType {\n    static let focus: Self = .init()\n\n    func invalidate(view: UIView) {\n      view.setNeedsFocusUpdate()\n    }\n  }\n}\n```\n\nYou can then expose it to the property wrapper by extending the `InvalidatingStaticMember` type:\n\n```swift\nextension InvalidatingStaticMember where Base: UIViewInvalidatingType {\n  static var focus: InvalidatingStaticMember\u003cInvalidations.Focus\u003e { .init(.focus) }\n}\n```\n\n\u003e #### Note: \n\u003e\n\u003e If you're using Xcode 13, you should do this instead:\n\u003e\n\u003e ```swift\n\u003e extension UIViewInvalidatingType where Self == Invalidations.Focus {\n\u003e  static var focus: Self { .focus }\n\u003e }\n\u003e ```\n\n\u003e The `InvalidatingStaticMember` type only exists to workaround some language limitations which have been addressed in Swift 5.5, which ships with Xcode 13. So if you're on the latest Xcode, you do not need to use the workaround. The `InvalidatingStaticMember` will also be unavailable.\n\nThen you can use your new invalidator on `@ViewInvalidating`:\n\n```swift\nfinal class MyView: UIView {\n\n  // Calls setNeedsLayout() and Focus.invalidate(self)\n  @ViewInvalidating(.layout, .focus) var customProperty: CGFloat = 1.0\n}\n```\n\n## Requirements\n\n- Deployment target of iOS 11+, tvOS 11+ or macOS 10.11+\n- Xcode 11 or above\n\n## Installation\n\nAdd the following to your project's `Package.swift` file:\n\n```swift\n.package(url: \"https://github.com/theblixguy/Invalidating\", from: \"0.1.0\")\n```\n\nor add this package via the Xcode UI by going to File \u003e Swift Packages \u003e Add Package Dependency.\n\n## Migration to iOS 15+/tvOS 15+/macOS 12+ deployment target\n\nWhen it's time to update your project's deployment target to iOS 15+/tvOS 15+/macOS 12+, you will need to make some very minor changes to your code to make it compatible with Apple's `@Invalidating` and related types.\n\nThe types that ship with this package have been annotated with `@available` and contain the right mappings to Apple's types on its `renamed` argument to make it super easy for you to update your code. Once you have update the deployment target, you will see some errors:\n\n![Migration Fix-it](Images/migration_fixit_code_1.png)\n![Migration Fix-it](Images/migration_fixit_code_2.png)\n\nAs you can see, they all offer a fix-it to automatically change the type names. With a click of a button, the errors disappears without you even having to manually rename them:\n\n![Migration Fix-it](Images/migration_fixit_code_applied_1.png)\n![Migration Fix-it](Images/migration_fixit_code_applied_2.png)\n\n✨\n\n## License\n\n```\nMIT License\n\nCopyright (c) 2021 Suyash Srijan\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","funding_links":[],"categories":["Swift"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheblixguy%2FInvalidating","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheblixguy%2FInvalidating","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheblixguy%2FInvalidating/lists"}