VB.NETでオブジェクトをキャストする方法と同様に、objective-cでオブジェクトをキャストする方法はありますか?
たとえば、私は次のことを試みています:
// create the view controller for the selected item
FieldEditViewController *myEditController;
switch (selectedItemTypeID) {
case 3:
myEditController = [[SelectionListViewController alloc] init];
myEditController.list = listOfItems;
break;
case 4:
// set myEditController to a diff view controller
break;
}
// load the view
[self.navigationController pushViewController:myEditController animated:YES];
[myEditController release];
しかし、SelectionListViewControllerがFieldEditViewControllerを継承していても、SelectionListViewControllerクラスには 'list'プロパティが存在し、FieldEditViewControllerには存在しないため、コンパイラエラーが発生します。
これは理にかなっていますが、「list」プロパティにアクセスできるようにmyEditControllerをSelectionListViewControllerにキャストする方法はありますか?
たとえばVB.NETでは次のようにします。
CType(myEditController, SelectionListViewController).list = listOfItems
助けてくれてありがとう!