• 访问权限


    ViewController.swift 

    //
    //  ViewController.swift//
    //  Created by nanakon on 17/3/11.
    //  Copyright © 2017年 nanakon. All rights reserved.
    //
    
    import UIKit
    
    /*
     internal 内部的
        默认情况下所有的类、属性、方法的访问权限都是internal
        在本模块(项目/包/target)中可以访问
     private 私有的
        只有本类中可以访问
     open 公开的
        可以跨模块(项目/包/target)都可以访问
     fileprivate swift 3
        只要在本文件中都可以进行访问
     */
    
    class ViewController: UIViewController {
        var name : String = ""
        private var age : Int = 0
        fileprivate var height : Double = 0
        
        override func viewDidLoad() {
            super.viewDidLoad()
            
            name = "why"
            print(name)
            
            age = 18
            print(age)
            
            let view = UIView() // open 跨包访问
            view.alpha = 0.5 // 属性alpha 也是open
            
        }
    }

    AppDelegate.swift

    //
    //  AppDelegate.swift//
    //  Created by nanakon on 17/3/11.
    //  Copyright © 2017年 nanakon. All rights reserved.
    //
    
    import UIKit
    
    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {
    
        var window: UIWindow?
    
    
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
            
            // internal 可以访问
            let vc = ViewController()
            vc.name = "why"
            // private 不能访问
            //vc.age
            // fileprivate 不能访问
            //vc.height
            
            return true
        }
    }
  • 相关阅读:
    Linux libcurl使用 (收藏)
    公钥和私钥与认证和签名
    fedora下配置ipv6 dns服务器
    SHA1
    linux IP 命令
    SSL/TLS协议簇加解密流程
    MD5算法实现原理
    container_of深入理解
    diff和patch使用指南
    oracle 笔记
  • 原文地址:https://www.cnblogs.com/jzm17173/p/6535841.html
Copyright © 2020-2023  润新知