GitHub 博客园 Nanakon

访问权限

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
    }
}

 

posted on 2017-03-11 18:45  jzm17173  阅读(62)  评论(0编辑  收藏  举报

导航

轻音