Cast objects safely in obj-c