如何在iOS objective-c代码中使用名称空间? [英] How does one use namespaces in iOS objective-c code?

查看:93
本文介绍了如何在iOS objective-c代码中使用名称空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个iOS应用程序,Best Korea。我的组织名称是Srsly.co。我将编写可重用的新闻库,我将在我的应用程序中使用这些库。

I'm writing an iOS app, "Best Korea". My organization name is "Srsly.co". I'm going to write re-usable "News" libraries that I'll use across my apps.

每个iOS应用程序在 .h 文件中都有自己的应用程序范围常量,库代码也会有其常量头文件。我还将对每个项目进行测试。

Each iOS app will have its own app-wide constants in a .h file, and the library code will have its constants as well in header files. I'll also have tests for each of these projects.

这是标准的做事方式吗?

Is this the standard way of doing things?

在Ruby,Python,Java等中,我将按以下方式设置名称空间:

In Ruby, Python, Java, etc., I'd set up namespaces along these lines:

co.srsly.bestkorea
co.srsly.bestkorea.test
co.srsly.newslib
co.srsly.newslib.test

据我所知,Objective-C模式是为每个开发人员选择两个或三个大写字母并为每个类名添加前缀。

As far as I can see, the Objective-C pattern is for each developer to choose two or three upper-case letters and prefix every class name with them.

所以在我的情况下,我认为我会选择 BK 作为应用的类名前缀和 NL 新闻lib代码?我是否正确地思考这个问题?

So in my case, I'm thinking I'd choose BK as the app's classname prefix and NL for the news lib code? Am I thinking about this the right way?

编辑:我正在考虑在我的应用程序代码中根本不使用命名空间 href =https://stackoverflow.com/questions/1021035/are-namespace-collisions-really-an-issue-in-objective-c?rq=1>这里

I'm considering not using namespacing at all in my application code as discussed here.

推荐答案

你是对的,Objective-C没有内置的名称空间支持,常见的解决方案是在每个类上使用大写前缀。需要注意的是苹果曾表示说两个字母前缀保留供其使用,因此您应为自己的类使用三个字母前缀。否则,建议的方法是正常的做法。

You're correct that Objective-C doesn't have built in support for namespaces, and the common solution is to use uppercase prefixes on each class. Note that Apple has stated that two letter prefixes are reserved for their use, so you should use three letter prefixes for your own classes. Otherwise, your suggested approach is the normal thing to do.

这篇关于如何在iOS objective-c代码中使用名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆