0

I have this enum in swift:

@objc enum HomeViewDataType: Int {
    case statistics
    case allTime
}

and this protocol;

@objc(TCHomeViewDataUpdaterDelegate)
protocol HomeViewDataUpdaterDelegate {
    ....
    func homeViewDataType() -> HomeViewDataType
}

If I ask Xcode to add the protocol stubs automatically it will add the enum keyword inside the return type parenthesis:

- (enum HomeViewDataType)homeViewDataType
{
    <code>
}

I never seen this before: (enum HomeViewDataType)

Any idea why?

It works with or without the enum keyword btw.

Zsolt
  • 3,648
  • 3
  • 32
  • 47
  • `enum HomeViewDataType` is a valid type notation in C/ObjC and you need to put the keyword `enum` to represent enum types unless you have some `typedef` of the enum. Better read the basic part of C-language. – OOPer Aug 25 '18 at 07:18
  • thanks @OOPer. the bridging header generates the following: typedef SWIFT_ENUM(NSInteger, HomeViewDataType) { HomeViewDataTypeStatistics = 0, HomeViewDataTypeAllTime = 1 }; When xcode generates the stub I assume it opts for adding the `enum` keyword even though it is not necessary. ref: https://stackoverflow.com/a/742716/429763 – Zsolt Aug 27 '18 at 10:38
  • Yes, usually Apple's framework (in ObjC) uses `NS_ENUM` and it also generates `typedef`. I do not know why Swift does not use the shortest representation, but, just my guess, Swift team might want to use the same code base for no-typedef enums and typedef-ed enums. – OOPer Aug 27 '18 at 11:30

0 Answers0