Conversation
This allows it to be used to initialize static variables with the same type-safety and autocompletion benefits. Note that this can only apply to the two-argument variant, since there is no way to split the string at compile-time.
As an unanticipated benefit of this process, you can now use Xcode’s ⌃⌘E feature with |
By further taking the type of `OBJ` and casting `nil` as the receiver, object types can be passed as the left hand side directly, e.g. `id<NSValidatedUserInterfaceItem>`, allowing type-safety, refactoring, and autocompletion of properties of types without having to resort to `Foo.new` hacks as the left hand side (which can be jarring and/or inconvenient).
@robrix
|
@lldong use |
@lldong That’s not a valid type name; you want |
Cheers @jakebromberg 😄 |
@robrix @jakebromberg libextobjc/extobjc/EXTKeyPathCoding.h Lines 22 to 23 in 6a669e5
|
Ahh, I gotcha—good catch @lldong, cheers. |
@jspahrsummers I don’t know how you feel about any of this, but I’m inclined to kick it to the curb given Swift. |
that is a surprisingly disturbing gif (we could always revert to non-typename keypaths so that the bare class name can still be passed) |
Submodule changes to be committed: * Configuration c8e5527...4ac967d (12): > Merge pull request jspahrsummers#80 from cocologics/feature/xcode9-update > Merge pull request jspahrsummers#79 from cocologics/feature/xcode9-update > Merge pull request jspahrsummers#71 from fabb/analyzer_localized > enable CLANG_ANALYZER_NONNULL > enable CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION > enables SWIFT_TREAT_WARNINGS_AS_ERRORS > Merge pull request jspahrsummers#67 from fabb/enable_nullability_completeness_warning > Merge pull request jspahrsummers#65 from Abizern/xcode8_debug_flag > Merge pull request jspahrsummers#64 from diederich/enableTestability > Merge pull request jspahrsummers#63 from diederich/implicitCaptureOfSelf > Merge pull request jspahrsummers#62 from calebd/xcode-8-beta-5-warnings > Merge pull request jspahrsummers#61 from ikesyo/disable-framework-codesigning
* bumped the xcconfigs to latest version * fix build on Xcode 9 ('void' missing in strict declaration checking) Submodule changes to be committed: * Configuration c8e5527...4ac967d (12): > Merge pull request #80 from cocologics/feature/xcode9-update > Merge pull request #79 from cocologics/feature/xcode9-update > Merge pull request #71 from fabb/analyzer_localized > enable CLANG_ANALYZER_NONNULL > enable CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION > enables SWIFT_TREAT_WARNINGS_AS_ERRORS > Merge pull request #67 from fabb/enable_nullability_completeness_warning > Merge pull request #65 from Abizern/xcode8_debug_flag > Merge pull request #64 from diederich/enableTestability > Merge pull request #63 from diederich/implicitCaptureOfSelf > Merge pull request #62 from calebd/xcode-8-beta-5-warnings > Merge pull request #61 from ikesyo/disable-framework-codesigning
@keypath(NSObject, version)
.This allows it to be used to initialize static variables with the same type-safety and autocompletion benefits, at the cost of complicating the macro’s definition.
Note that this can only apply to the two-argument variant, since there is no way to split the string at compile-time.
Further, an additional change allows types to be passed as the first argument of
@keypath
, removing the need for workarounds like@keypath(Foo.new, …)
which can be jarring, and which may be inconvenient in cases where e.g.+new
is unavailable or you don’t even have a concrete class (e.g. with protocols). However, as @lldong points out, this currently breaks generation of class keypaths (e.g.@keypath(NSObject, version)
).The trick this uses to take the type of a comma express compiler-visible mechanism might be useful elsewhere; is something like that already available elsewhere?I ended up not requiring that trick at all; using the comma operator simplified this greatly. Seems like only multistatement things would need the block trick, and they’re probably already in one.