1

A.swift:

struct ApiRequest {
    static func getUrl() {
        // MyEnum.oneDay ---> Use of undeclared type 'MyEnum'
    }
}

B.swift:

public enum MyEnum: String {
    case oneDay = "1d"
    case sevenDays = "7d"
    case thirtyDays = "30d"
}

How do I access MyEnum.oneDay?

9
  • 1
    Have you declared MyEnum inside class B ? Commented May 23, 2018 at 8:45
  • Make sure that A.swift and B.swift belongs to the same module Commented May 23, 2018 at 8:45
  • What's the problem with declaring let enumValue = MyEnum.oneDay in getUrl() function? Commented May 23, 2018 at 8:46
  • @DanielKrom: his MyEnum is defined as public, so it can be accessed everywhere Commented May 23, 2018 at 8:46
  • 2
    If its declared inside class B you need to access like B.MyEnum Commented May 23, 2018 at 8:48

1 Answer 1

2

Let's say you have a class B like this,

class B {
    public enum MyEnum: String {
        case oneDay = "1d"
        case sevenDays = "7d"
        case thirtyDays = "30d"
    }
}

you can access it in class A like this,

class A {
    struct ApiRequest {
        static func getUrl() {
            print(B.MyEnum.oneDay)
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.