class XYActivity: UIActivity,YouTubeHelperDelegate { var youTubeHelper:YouTubeHelper var uploadURL: String! override init() { self.youTubeHelper = YouTubeHelper() } override func activityType() -> String? { return nil } // }
我想让uploadURL公开,也就是说,要在其他类中分配.
当我添加公共infront的var uploadURL:String!它建议我把它作为内部.我想让它公开.请帮忙
解决方法
默认情况下,修饰符是内部的,这使得当前模块中的任何地方的类,方法和属性未被显式声明为私有.
如果你的项目仅由一个应用程序组成,那么你可能不需要公共 – 内部的效果相同.如果您正在开发框架,并且需要该属性可以从其他模块中的代码访问,则需要将整个类和暴露的方法/属性声明为public.
建议阅读:Access Control
摘录描述默认访问级别:
All entities in your code (with a few specific exceptions,as described later in this chapter) have a default access level of internal if you do not specify an explicit access level yourself. As a result,in many cases you do not need to specify an explicit access level in your code.
以及单一目标应用的访问级别:
When you write a simple single-target app,the code in your app is typically self-contained within the app and does not need to be made available outside of the app’s module. The default access level of internal already matches this requirement. Therefore,you do not need to specify a custom access level. You may,however,want to mark some parts of your code as private in order to hide their implementation details from other code within the app’s module.