BroSimple BroSimple - 1 year ago 114
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.

Answer Source

#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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download