swift 学习这十八:宏()

Common.swift:

import Foundation

// in objective-c, but in swift, #define can't be used any more
// use let keyword to define a macro, look up original document:
/*
Simple Macros
Where you typically used the #define directive to define a primitive constant in C and Objective-C, in Swift you use a global constant instead. For example, the constant definition #define FADE_ANIMATION_DURATION 0.35 can be better expressed in Swift with let FADE_ANIMATION_DURATION = 0.35. Because simple constant-like macros map directly to Swift global variables, the compiler automatically imports simple macros defined in C and Objective-C source files.
*/
// in objective-c
// #define kCommonAPI @"http://xxxxxxx"

// but in swift, no #define, just use let to define
let kCommonAPI = "http://xxxxxxx"

main.swift:

import Foundation

println(kCommonAPI)

result:

http://xxxxxxx
Program ended with exit code: 0


上一篇:Swift 学习之二十:类型强转(+、-、*、/)


下一篇:Storm概念学习系列之storm的功能和三大应用