3

In apple documentation Unlike class names, protocol names don’t have global visibility. They live in their own namespace.

What does this mean as documentation does not elaborate it. I have tried and I have make two protocols with same name but they are in different files compiler shows warning duplicate protocol. When I import both protocols in single file the first protocol import hides other protocol deceleration. So first imported protocol method works. Other gives warning

So what does this line mean? I am not able to understand it properly.

2 Answers 2

2

In other programming languages, you can have the same class name in different directories or packages.

In Objective C, class names are global and there fore there is no name space concept. The names have to be unique. There cannot be two Employee classes.

But for protocols, you can have a same protocol defined in different files and based on which files you import, you have visibility into that protocol.

If you do not import that header file, you do not know about that protocol. - This is probably what is meant in the documentation when it says "Protocols do not have global visibility"

Also at the same time, if you have two definitions of the same protocol, only the first one will be respected. Infact the compiler will show you a clear warning to this fact.

Sign up to request clarification or add additional context in comments.

Comments

2

You can have more than one protocol having same name, but you cant use in a same class. The former will hide the later one.

2 Comments

Thanks for your response But i have make two protocols with same name but compiler gives warning duplicate protocol and when i import it in same file the compiler import first one and ignore other.
That is what i wrote, you cant use same protocol name is same file (in this case it is the namespace). Either you can change the name or add your required protocol method into one protocol.

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.