Type ID in swift



  • I often see the type code in lessons and examples

    + (id)parameterUnitWithObject:(id)object{
    

    And I can't figure out what this is all about id?



  • id - an index for any type, but different from void * He always points to the object Objective-C. In other words, a type object id should be inherited from NSObject or NSProxy (or simply having all the methods of these classes - retainreleaseisa and so on.

    The compiler will normally accept the caste of any ObjC facility in id and vice id in any objective-c. This principle is based on all (or almost all) types of containers in ObjC.

    Another interesting feature is that you can do any known compiler technique on the Oid site. For example:

    id something;
    [something becomeFirstResponder];
    

    To what is the equivalent of id in swift:

    By a swift equivalent id Type AnyObject or AnyObject?if it could be nil.

    For example:

    var something: AnyObject
    

    or

    @IBAction func buttonClicked(sender : AnyObject) {
        print("Button was clicked", sender)
    }
    

    or

    func newFunc() -> AnyObject? {
        return nil
    }
    

    or

    let something = "something"
    self.someMethod(something as AnyObject)
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2