Polymorphism in Objective-C with Abstract Methods

| | August 4, 2015

I need to be able to reuse a ViewController in Objective-c. In c# the code of what I’m trying to do would like like this:

 public abstract class SettingsViewController
{
    public abstract void SaveData();

    public void Save_Click()
    {
        SaveData();
    }
}

public class AgeController : SettingsViewController
{
    public override void SaveData()
    {
        Console.WriteLine("Do Something from AgeController");
    }
}

public class GenderController : SettingsViewController
{
    public override void SaveData()
    {
        Console.WriteLine("Do Something from GenderController");
    }
}

But I don’t see any clear way how to do this.

One Response to “Polymorphism in Objective-C with Abstract Methods”

  1. In the Objective-C language, there are no abstract methods. But in Objective-C software development, you easily make a method abstract by implementing it with an NSAssert () as the code.

Leave a Reply