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 :]