Swift 3:公共访问修饰符和内部访问修饰符之间的区别? [英] Swift 3: The difference between Public and Internal access modifiers?

查看:81
本文介绍了Swift 3:公共访问修饰符和内部访问修饰符之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了Apple关于Swift 3中访问修饰符的参考.我在stackoverflow上也阅读了相同的内容,但没有像询问的人那样得到答案.据我正确理解,它分为四个级别:

I read the Apple's reference about access modifiers in Swift 3. I read also about the same on stackoverflow but I didn't get an answer as the person who asked. As I understood correctly, there are four levels:

  1. 公开,公开
  2. 内部
  3. Fileprivate
  4. 私人

我为自己创建了方案,以了解所有这些修饰符之间的区别,并在此处.如您所见,公共"和内部"修饰符之间没有区别.但是它们处于不同的级别.任何想法将不胜感激!

I created the schemes for myself to understand a difference between all these modifiers and uploaded here. As you can see, there are no differences between Public and Internal modifiers.. However they're on different levels. Any idea would be appreciated!

推荐答案

您的图表不正确.

A.swiftB.swift的公共成员可用于C.swiftD.swift.唯一的限制是类不能被子类化(它们必须是open.

Public members of A.swift and B.swift are available to C.swift and D.swift. The only restriction is that classes can't be subclassed (they would need to be open.

这篇关于Swift 3:公共访问修饰符和内部访问修饰符之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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