1

I've created an Error enum for a class I'm building:

enum QuestionDataHelperError: Error {
  case NoResponseFromServer
  case NoDataReturnedFromServer
  case InvalidResponseFromServer
}


/// A Singleton which retrieves Question objects from the server
/// Access Singleton via .shared()
class QuestionDataHelper {
  ...
}

Currently I have the error enum in the global namespace above the class declaration, is this the correct way to go about it? Or should error enums have be in their own file?

Cheers!

mike
  • 2,073
  • 4
  • 20
  • 31
  • 1
    Even if you put the enum in its own file, it will still be available at global scope... If you want to create namespacing, then just do it: nest the enum in structs or classes, for example. But your current way also works, of course. – Eric Aya Jan 25 '17 at 11:56
  • 1
    Good point, if both declaring it outside the class scope and having it in its own file end up with it being in the global namespace anyway then I think the differences boil down to personal preference rather than any technical merit. – mike Jan 25 '17 at 13:44

0 Answers0