Skip to content

Make AnyClass generic? #842

@madsmtm

Description

@madsmtm

Some APIs have bounds on classes, such as -[NSWindow restorationClass]:

@property (nullable, assign) Class<NSWindowRestoration> restorationClass;

This effectively says "whatever class is used here must conform to NSWindowRestoration".

A similar thing is actually needed for -[UIView layerClass], ideally that one should probably say "whatever class is used here must be a subclass of CALayer" (but I don't think Objective-C has a way to express that).

To model this, it might make sense to make AnyClass generic? Something like:

struct AnyClass<Bound = ()> {
    // ...
}

fn restorationClass(&self) -> &'static AnyClass<dyn NSWindowRestoration> { ... }
fn setRestorationClass(&self, r#class: &AnyClass<dyn NSWindowRestoration>) { ... }

fn layerClass(&self) -> &'static AnyClass<CALayer> { ... }

And a few methods for (unsafely probably) converting the class' generic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-frameworkAffects the framework crates and the translator for themA-objc2Affects the `objc2`, `objc2-exception-helper` and/or `objc2-encode` cratesenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions