Use of constant (#define) in Swift Language – iOS

Swift Constant Test
Swift Constant Test

In Objective-C we are using a header file to create constant variables like as
[code lang=”obj-c”]
// Objective-C
#define APP_ALERT_TITLE "Objective-C Constant"
[/code]
Swift has new syntax to define the constant (#define)
[code lang=”obj-c”]
// Swift
let APP_ALERT_TITLE = "Swift Constants"
[/code]

Lets try

Create a swift file with the constants

[code lang=”obj-c”]
import Foundation
class Constants {
// MARK: List of Constants
static let APP_ALERT_TITLE = "Swift Constants"
static let SAMPLE_MESSAGE = "The alert is working !!"
}
[/code]
Note : Here the MARK statement is also changed.
[code lang=”obj-c”]
// Objective-C
#pragma mark –
#pragma mark List of Constants
[/code]
[code lang=”obj-c”]
// Swift
// MARK: List of Constants
[/code]

Read more