Swiftify
Swiftify copied to clipboard
#define constants declared in .m should not be made global
Variable declared in the .m file like in these files should not be converted to global variables. Original Source Code X509.m.zip Converted Code X509.swift.zip
@Ibrahimhass
-
In your particular sample, even though these
#define
macros are defined in the .m file, they are outside of the#implementation
section. In order to make them non-global, we need to include them in a class, but I cannot see a pattern or reasoning to make them members of theX509
class. Nor do I see enough reasoning to declare a custom class e.g.PrivateVariables
for these variables. -
Even if these macros were declared inside of the
#implementation
section, they are allowed to be used at least from anywhere in the source file. This leads to the only possible suggestion - to declare them asfileprivate
variables. Is that something that you have in mind?
IMO they still have to be refactored (casing should be changed, and variables are likely to be moved to a particular class), thus I don't see a lot of benefit of adding a fileprivate
modifier. Do you?
- What catches my eyes in your sample is that header comments and global variables appear at the bottom of the file, which I could not reproduce by converting just the
.m
file. Let me know how did you get such results.
@Ibrahimhass Please review and reply when you have time (don't spend too much time on this though).
@alex-swiftify
Even if these macros were declared inside of the #implementation section, they are allowed to be used at least from anywhere in the source file. This leads to the only possible suggestion - to declare them as fileprivate variables. Is that something that you have in mind?
Yes, I suggest that we add the fileprivate
modifier so that the names do not collide if the same variables are used in any other class too as a private variable.
What catches my eyes in your sample is that header comments and global variables appear at the bottom of the file, which I could not reproduce by converting just the .m file. Let me know how did you get such results.
I am also not able to replicate this behavior now. I tried using the Project Converter and the Xcode Extension.
Related Jira issues: https://swiftify.atlassian.net/browse/SWC-377 https://swiftify.atlassian.net/browse/SWC-1110