Skip to content

Add cifilter-builtins style guide rule#376

Open
stephenfurlani-cell wants to merge 1 commit intoairbnb:masterfrom
stephenfurlani-cell:sjf--swift-style--cifilter-builtins
Open

Add cifilter-builtins style guide rule#376
stephenfurlani-cell wants to merge 1 commit intoairbnb:masterfrom
stephenfurlani-cell:sjf--swift-style--cifilter-builtins

Conversation

@stephenfurlani-cell
Copy link
Copy Markdown

Prefer CIFilter typed factory methods (CIFilterBuiltins) over string-based CIFilter(name:) and setValue(_:forKey:). Adds rule entry to the Patterns section immediately before File Organization.

Summary

Adds a new Patterns rule recommending CIFilter's typed factory methods (from CIFilterBuiltins) over the string-based CIFilter(name:) initializer and KVO setValue(_:forKey:).

No SwiftLint or SwiftFormat rule exists for this — it is a style guide entry only.

Reasoning

CIFilter(name:) returns an optional and requires stringly-typed KVO for parameter access. The CIFilterBuiltins factory methods (available since iOS 14) provide non-optional returns and compile-time type-checked properties, eliminating an entire class of runtime errors.

The typed API requires import CoreImage.CIFilterBuiltins, which is an unusual submodule import but is Apple's documented approach.

Reference: https://developer.apple.com/documentation/coreimage/processing-an-image-using-built-in-filters

Prefer CIFilter typed factory methods (CIFilterBuiltins) over string-based
CIFilter(name:) and setValue(_:forKey:). Adds rule entry to the Patterns
section immediately before File Organization.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread README.md
// RIGHT
let url = #URL("https://example.com")
import CoreImage.CIFilterBuiltins
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be just import CoreImage or do you need to specifically import CoreImage.CIFilterBuiltins in addition to CoreImage?

Copy link
Copy Markdown
Member

@calda calda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice thanks! Could you please move it to the new "Apple Frameworks" section of the style guide, and run the markdown linter? (bundle exec rake lint:markdown)

Comment thread README.md
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the rule above the section's back to top button (as opposed to adding a new one)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants