• Swift 语法


    根据类名来实例化对象,比如,要根据一个类名的字符串创建ViewController实例。

    let controllerName="SpainAppProto."+xibName  // xibName 形如 XXViewController
    var classType: AnyObject.Type=NSClassFromString(controllerName)
    var nsobjectype : UIViewController.Type = classType as UIViewController.Type
    var viewController: UIViewController = nsobjectype(nibName: xibName, bundle: nil) 

    但是 在根据 UIViewController.self 来实例化的时候就要稍微转化下

        var x: String = m.debugDescription  // m为 UIViewController.self
        x = x.stringByReplacingOccurrencesOfString("Optional(", withString: "")
        x = x.stringByReplacingOccurrencesOfString(")", withString: "")
        let anyClass: AnyClass = NSClassFromString(x)
        let viewControllerClass: UIViewController.Type = anyClass as UIViewController.Type
        let viewController = viewControllerClass()
  • 相关阅读:
    Bluetooth GATT介绍
    Bluetooth ATT介绍
    Bluetooth GAP介绍
    Bluetooth Low Energy介绍
    CC2540介绍
    DBus介绍
    802.11 MAC层
    802.11介绍
    Python资料
    Bluedroid之GKI
  • 原文地址:https://www.cnblogs.com/ziyeSky/p/4198590.html
Copyright © 2020-2023  润新知