0

How to write this code in swift 3.0?

NSSTring *countString=[NSString stringWithFormat:@"%d %@",count,EDIT_CHAR];

where, EDIT_CHAR is a Macro & count is integer.

Renuka Pandey
  • 1,730
  • 2
  • 15
  • 27

1 Answers1

1

Swift haven't a preprocessor, but you can create a structure with all you constants or flags.

struct MyAppConstants {
 static let editChar = "f"
// Etc...
}

You can call it as MyAppConstants.editChar
You question is tagged swift but the code you've posted is ObjC.

Andrea
  • 26,120
  • 10
  • 85
  • 131
  • Thank you, But making structure is only way to handle macros of obj C or something else ? – Renuka Pandey Feb 06 '17 at 11:43
  • If your are using ObjC or mixed project with Swift, you can create macros, but you can only use them in the ObjC source files(as far ad I remember). In Swift there are different practice. Struct is one of them, but can use also Enums or simply declare constant at a global scale. Using structs or enums, you can easily separate your constants for different contexts, such as UIConstants, FileConstants etc. For differences between those two approach you can read this answer from MartinR http://stackoverflow.com/questions/38585344/swift-constants-struct-or-enum – Andrea Feb 06 '17 at 13:12