Skip to content

[SR-7045] Cannot instantiate UICollectionViewLayout's invalidationContextClass #49593

@karwa

Description

@karwa
Previous ID SR-7045
Radar None
Original Reporter @karwa
Type Bug
Environment

Xcode 9.2

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: f87bd12334e974b8fb93a8a9889509df

Issue Description:

UICollectionViewLayout exposes a "invalidationContextClass" property, which should be a class which is a subtype of UICollectionViewLayoutInvalidationContext.

There are a couple of (related) issues with how this is imported in to Swift:

1) Poor importing. The property is of type "AnyClass". It should be "UICollectionViewLayoutInvalidationContext.Type".

2) Not possible to instantiate an object of the correct type. There isn't a whole lot of documentation about this API, but I think you're supposed to instantiate objects of this exact type (e.g. https://github.com/Instagram/IGListKit/blob/master/Source/IGListAdapter.m#L1080).

I've been trying to do the same thing in Swift, but it doesn't seem possible. Again, this appears to be an issue with the Swift-ObjC bridging:

let collectionView: UICollectionView = ...

let clazz = (type(of: collectionView.collectionViewLayout).invalidationContextClass as! UICollectionViewLayoutInvalidationContext.Type)

// None of these work.
let context = clazz.init()
let context = clazz.new()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions