Frederick C. Lee
Frederick C. Lee

Reputation: 9513

Namespace: How do you distinguish duplicate function names, one/respective .swift file?

Hypothetical scenario: two .swift files (one.swift & two.swift), both have the function (or any other entity):

func doSomething() {
}

How would you differentiate one's doSomething() from two's doSomething()?
BTW: both .swift files are within the same Xcode target.

This is purely hypothetical for edification.

Upvotes: 2

Views: 491

Answers (1)

codester
codester

Reputation: 37189

You can not able to create if both same name top level functions are in same taget.You may want to put them in struct as static functions so you can access by struct name.

struct MyStruct {

    static func doSomething() {
    }
}

//acess by struct name
MyStruct.doSomething()

If they both are in different target or modules and declared as public you should access by their ModuleName

Upvotes: 2

Related Questions