//
// AppDelegate.swift
// 反射机制
//
// Created by 庄壮勇 on 2018/1/10.
// Copyright © 2018年 Personal. All rights reserved.
//
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
/**
1. 知道 Swift 中有命名空间
- 在同一个命名空间下,全局共享!
- 第三方框架使用 Swift 如果直接拖拽到项目中,从属于同一个命名空间,很有可能冲突
- 以后尽量都用用 cocoapod
2. 重点要知道 Swift 中 NSClassFromString(反射机制) 的写法
- 反射最重要的目的,就是为了解耦!
- 搜索 '反射机制和工厂方法'!
- 提示: 第一印象会发现一个简单的功能,写的很复杂
- 但是, 封装的很好,而且弹性很大!
*/
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// *** 代码中的 ? 都是 '可选'解包,发送消息,不参与计算
// 所有的?都是Xcode 自动添加的!
// 1. 实例化 window
window = UIWindow()
window?.backgroundColor = UIColor.white
// --- 输出 info.plist的内容
// ProductName / 版本 是记录在 info.plist
// [String : Any]?
print(Bundle.main.infoDictionary ?? "")
// 1>因为字典是可选的,因此需要解包再取值
// 如果字典为nil, 就不取值
// 2> 通过key从字典中取值,如果key 错了,就没有值了
// Any? 表示不一定能够获取到值
let ns = Bundle.main.infoDictionary?["CFBundleName"] as? String ?? ""
// 2. 设置 跟控制器, 需要添加命名空间 -> 默认就是 '项目名称'(最好不要有数字和特殊符号)
let clsName = ns + "." + "ViewController"
// AnyClass?
let cls = NSClassFromString(clsName) as? UIViewController.Type
// 使用类创建视图控制器
// UIViewController?
let vc = cls?.init()
// let vc = ViewController()
window?.rootViewController = vc
// 3. 让 window 可见
window?.makeKeyAndVisible()
return true
}
}
// AppDelegate.swift
// 反射机制
//
// Created by 庄壮勇 on 2018/1/10.
// Copyright © 2018年 Personal. All rights reserved.
//
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
/**
1. 知道 Swift 中有命名空间
- 在同一个命名空间下,全局共享!
- 第三方框架使用 Swift 如果直接拖拽到项目中,从属于同一个命名空间,很有可能冲突
- 以后尽量都用用 cocoapod
2. 重点要知道 Swift 中 NSClassFromString(反射机制) 的写法
- 反射最重要的目的,就是为了解耦!
- 搜索 '反射机制和工厂方法'!
- 提示: 第一印象会发现一个简单的功能,写的很复杂
- 但是, 封装的很好,而且弹性很大!
*/
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// *** 代码中的 ? 都是 '可选'解包,发送消息,不参与计算
// 所有的?都是Xcode 自动添加的!
// 1. 实例化 window
window = UIWindow()
window?.backgroundColor = UIColor.white
// --- 输出 info.plist的内容
// ProductName / 版本 是记录在 info.plist
// [String : Any]?
print(Bundle.main.infoDictionary ?? "")
// 1>因为字典是可选的,因此需要解包再取值
// 如果字典为nil, 就不取值
// 2> 通过key从字典中取值,如果key 错了,就没有值了
// Any? 表示不一定能够获取到值
let ns = Bundle.main.infoDictionary?["CFBundleName"] as? String ?? ""
// 2. 设置 跟控制器, 需要添加命名空间 -> 默认就是 '项目名称'(最好不要有数字和特殊符号)
let clsName = ns + "." + "ViewController"
// AnyClass?
let cls = NSClassFromString(clsName) as? UIViewController.Type
// 使用类创建视图控制器
// UIViewController?
let vc = cls?.init()
// let vc = ViewController()
window?.rootViewController = vc
// 3. 让 window 可见
window?.makeKeyAndVisible()
return true
}
}