閱讀618 返回首頁    go 阿裏雲 go 技術社區[雲棲]


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 @"https://xxxxxxx"

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

main.swift:

import Foundation

println(kCommonAPI)

result:

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


最後更新:2017-04-03 07:56:58

  上一篇:go Swift UI學習之UIAlertController(變得麻煩了)
  下一篇:go cocos android分析