swift 学习这十八:宏()

来源:互联网 发布:人工智能服务平台 编辑:程序博客网 时间:2024/05/16 01:02

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 MacrosWhere 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 definelet kCommonAPI = "http://xxxxxxx"

main.swift:

import Foundationprintln(kCommonAPI)

result:

http://xxxxxxxProgram ended with exit code: 0


0 0
原创粉丝点击