swift 学习这十八:宏()

来源:互联网 发布:as3.0调用js页面方法 编辑:程序博客网 时间:2024/06/05 03:09

Common.Swift:

[plain] view plain copy
 print?
  1. import Foundation  
  2.   
  3. // in objective-c, but in swift, #define can't be used any more  
  4. // use let keyword to define a macro, look up original document:  
  5. /*  
  6. Simple Macros  
  7. 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.  
  8. */  
  9. // in objective-c  
  10. // #define kCommonAPI @"http://xxxxxxx"  
  11.   
  12. // but in swift, no #define, just use let to define  
  13. let kCommonAPI = "http://xxxxxxx"  

main.swift:

[plain] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. import Foundation  
  2.   
  3. println(kCommonAPI)  

result:

[plain] view plain copy
 print?在CODE上查看代码片派生到我的代码片
  1. http://xxxxxxx  
  2. Program ended with exit code: 0  
0 0
原创粉丝点击