BroSimple BroSimple - 7 months ago 66
Objective-C Question

What is #define in swift

In Objective-c it's

#define getDataURL @""

but in Swift it's something else and I can't figure it out

It's probably simple but thank you for helping out.


#define is a preprocessor directive that Objective-C inherited from C (since it's a superset of C).

Swift doesn't have a preprocessor at all so you can't have the same exact behavior of #define textual replacement but you can do something different, eg:

class MyConstants {
  static let DATA_URL = "";

That's semantically different since preprocessor directives doesn't even reach semantic phase of the compiler but you can use it in a quite similar way.