How to cast an object in Objective-C

后端 未结 5 779
死守一世寂寞
死守一世寂寞 2020-12-04 09:14

Is there a way to cast objects in objective-c much like the way objects are cast in VB.NET?

For example, I am trying to do the following:

// create t         


        
5条回答
  •  感动是毒
    2020-12-04 09:45

    Sure, the syntax is exactly the same as C - NewObj* pNew = (NewObj*)oldObj;

    In this situation you may wish to consider supplying this list as a parameter to the constructor, something like:

    // SelectionListViewController
    -(id) initWith:(SomeListClass*)anItemList
    {
      self = [super init];
    
      if ( self ) {
        [self setList: anItemList];
      }
    
      return self;
    }
    

    Then use it like this:

    myEditController = [[SelectionListViewController alloc] initWith: listOfItems];
    

提交回复
热议问题