Home  >  Q&A  >  body text

ios - swift中怎么强制类型转化为AnyObject

UIDevice.currentDevice().performSelector(
    "setOrientation:",
    withObject:UIInterfaceOrientation.LandscapeRight
)

有如上代码 后面 withObject 的参数是一个 AnyObject 类型的,这样直接传的话会报错,试过几种方法都不行,求大神帮忙。T T

高洛峰高洛峰2761 days ago705

reply all(2)I'll reply

  • 怪我咯

    怪我咯2017-04-17 17:47:44

    Repost UIInterfaceOrientation.LandscapeRight.rawValue

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:47:44

    id corresponds to AnyObject?, you define a var with ? and try it:

    import Foundation
    func displayObjectName(yourobject : AnyObject?)
    {
        NSLog("%@",yourobject as! String);
    }
    
    
    var s:String?="Hello,World";
    displayObjectName(s);

    reply
    0
  • Cancelreply