Lnpopupcontroller: Best practices for using popupPresentationState

Created on 5 Dec 2020  ·  5Comments  ·  Source: LeoNatan/LNPopupController

Description

This is simply a question about best practices using your library. I updated to library version 2.10.25 which updated the enum popupPresentationState. I successfully made the changes, but I have a question:

How should I handle the transitioning case? I want to make my switch statement exhaustive and in order to do so, the compiler adds transitioning. The problem is that this is now deprecated based on your docs. I could use default to cover this case, but I would prefer to use @unknown default. However, if I use @unknown default without adding transitioning then the compiler gives a warning Switch must be exhaustive.

Any thoughts on how to best handle this?

Example code of what I am doing (with comments for explanation):

func demoOfSwitchStatement() {
    switch tabBarController.popupPresentationState {
    case .open, .barPresented, .barHidden:
        // This is supported.
        break

    case .transitioning:
        // The docs state: "Should no longer be used." However, to make this switch exhaustive, I need to have it here.
        break

    @unknown default:
        // This is here to get rid of the compiler warning: "Switch covers known cases, but 'LNPopupPresentationState' may have additional unknown values:
        break
    }
}

Docs which show transitioning is deprecated:
deprecated

Steps to Reproduce

Use a switch statement on the property popupPresentationState

Device, OS and Xcode Versions

Xcode 12.2
iOS 13 and iOS 14
LNPopupController 2.10.25

question

Most helpful comment

Yes, looks good

All 5 comments

Ufff 🤦‍♂️

Good question. I didn’t want to break existing API usage by removing that case, and it is actually used internally. But for the user-facing property, that transitioning case will never be seen. It’s used internally for in between cases. This was the only compromise I found.

I think you can also expect the enum to not change in the future, so a default statement is likely good enough. You can also use the delegate methods instead of relying on the enum; with KVO, the state changes should be equivalent to the delegate callbacks.

I will remove the deprecated APIs eventually. I had plans for a 3.0, with a major presentation revamp, but I doubt it will happen. So, we’ll see when an actual 3.0 hits.

If you have suggestions how to hide this enum from the compiler, by some magic annotation, I’d happily add it. How does Apple do it for their own deprecated enum cases?

@LeoNatan I took some time to look at your question, but unfortunately don't know how Apple does it. Sorry I couldn't be of more help.

To move forward on this, I believe you said that a _default statement is likely good enough_. Is this ok then?

    func demoOfSwitchStatement() {
        switch tabBarController.popupPresentationState {
        case .open, .barPresented, .barHidden:
            // This is supported. Handle these cases.
            break
        default:
            // Don't need to handle right now since it is a placeholder for **transitioning** deprecated case.  
            break
        }
    }

Please see comment above: // Don't need to handle right now since it is a placeholder for **transitioning** deprecated case.

Yes, looks good

got it, thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nhatduong picture nhatduong  ·  7Comments

RajChanchal picture RajChanchal  ·  3Comments

funkenstrahlen picture funkenstrahlen  ·  3Comments

chauhan130 picture chauhan130  ·  8Comments

johnswifttt picture johnswifttt  ·  5Comments