0

Let's say we got a super class named BaseViewController, in whose .h file defined a enum as the following.

typedef NS_ENUM(NSUInteger, SectionType) {
    SectionTypeUserName,
    SectionTypeUserAddress,
    ...
    SectionTypeUserPets
}

This enum is the type of the section in a table view.

Now, I got another view controller named ASubViewController which is inherited from BaseViewController.

Because the section type now is a little bit different like the below, how to insert a new element at the head of if.

typedef NS_ENUM(NSUInteger, SectionType) { SectionTypeUserTitle, // Just insert this line SectionTypeUserName, SectionTypeUserAddress, ... SectionTypeUserPets }

Because nothing of the rest code need any modification. The defualt setting is enough.
So how to implement it?

Steper
  • 17
  • 4
  • I don't think the Enum would be accessible in your child controller. So you can just re-use this enum name in your child controller. – votelessbubble Dec 07 '18 at 07:02
  • Yeah, of course it can't be accessed. This a wrong example. My point is how to redefine it. I will update it. – Steper Dec 07 '18 at 07:08
  • Ok now it makes sense. Have you tried this? https://stackoverflow.com/a/45099817/1996025 – votelessbubble Dec 07 '18 at 07:10
  • Enums cannot be changed or overriden. They are not even a part of the class. I would say that even inheritance of these two controllers is a bad idea. Dont create random subclasses to reuse implementation, refactor the base controller instead or create a common superclass for both. – Sulthan Dec 07 '18 at 07:16
  • While, it does inspire me. But actually my purpose is insert a new element at the head of the enum! I will update my question again. – Steper Dec 07 '18 at 07:24
  • @Sulthan I think you are right. I will think about it. – Steper Dec 07 '18 at 07:25

0 Answers0