Networking with URLSession - Part 5: URLSession | Ray Wenderlich

Magic strings

Hy, Audrey!
What do you think about a lot of ā€œmagic stringsā€ in API like:

  • request.httpMethod = ā€œPOSTā€
  • request.addValue(ā€œapplication/jsonā€, forHTTPHeaderField: ā€œcontent-typeā€)

Should we have some kind of predefined enums or something else for such cases?

yes, certainly! specify the enum type as String, then use the case’s rawValue, to let Xcode auto-complete for you :]