Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Cast internal class object to public interface fails in Swift #2830

Closed
laviallb opened this issue Mar 29, 2019 · 1 comment · Fixed by #2969
Closed

Cast internal class object to public interface fails in Swift #2830

laviallb opened this issue Mar 29, 2019 · 1 comment · Fixed by #2969
Assignees

Comments

@laviallb
Copy link

laviallb commented Mar 29, 2019

When I declare in Kotlin :

public interface InterA {}
internal class ClassA: InterA {}

And expose in Swift an InterA backed by a ClassA instance,
Some cast operations fail:

    private func getObject<T>(_ value: InterA) -> T? {
        let castedValue = value as? T // nil
        let test1 = value is T // false
        let test2 = value is InterA // true
        let test3 = T.self == InterA.self // true
        return castedValue
    }

    let inter: InterA? = getObject(commonManager.api.a) // commonManager.api.a is a ClassA

It is not possible to cast value in T, even if T is InterA. If I change getObject to take value as Any, even test2 fails.

Everything works well if ClassA is public.

The use case behind that issue is to be able tu use a DI framework such as Swinject.

@SvyatoslavScherbina
Copy link
Collaborator

Confirmed, thank you for the report.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants