Xcode: would like to highlight soon-to-be-deprecated sections of source code

113 views Asked by At

I'm searching for a method of highlighting sections of a source code file so that everyone on the team knows immediately that they are reading deprecated code.

For example, I was hoping I would find something like this:

#pragma clang diagnostic push
#pragma clang diagnostic use-italic-font
- (void) myDeprecatedFunction
{
    ... 300 lines of deprecated function body 
    ... that will be removed soon
}
#pragma clang diagnostic pop

Maybe there is an Xcode extension or plugin that could do this?

I use these other tools sometimes, but they are insufficient:

#warning 
//TODO
//FIXME
#pragma mark
#pragma -
#pragma GCC poison

Sometimes I go so far as doing this:

// !!!! DEPRECATED VERSION OF STRUCT !!!!
typedef packed struct
{
   UInt8        mParamID; // !!!! DEPRECATED VERSION OF STRUCT !!!!
   SInt8        mDmxChannelOffset; // !!!! DEPRECATED VERSION OF STRUCT !!!!
   UInt16       mEncoderMinVal; // !!!! DEPRECATED VERSION OF STRUCT !!!!
   UInt16       mEncoderMaxVal; // !!!! DEPRECATED VERSION OF STRUCT !!!!
   UInt16       mHomeVal; // !!!! DEPRECATED VERSION OF STRUCT !!!!
   UInt8        mEncoderSensitivity; // !!!! DEPRECATED VERSION OF STRUCT !!!!
   UInt8        mParamFlags; // !!!! DEPRECATED VERSION OF STRUCT !!!!
   UInt8        mExtraCode; // !!!! DEPRECATED VERSION OF STRUCT !!!!
   UInt8        mExtraValue; // !!!! DEPRECATED VERSION OF STRUCT !!!!
   SInt8        mExtraDMXAddressOffset; // !!!! DEPRECATED VERSION OF STRUCT !!!!
   UInt8        mReserved; // !!!! DEPRECATED VERSION OF STRUCT !!!!
   UInt8        mMoreDataFlags; // !!!! DEPRECATED VERSION OF STRUCT !!!!

   // Dynamic state
   SInt8        mDynamicDmxChannelOffset; // !!!! DEPRECATED VERSION OF STRUCT !!!!
   SInt16       mDynamicEncoderMinVal; // !!!! DEPRECATED VERSION OF STRUCT !!!!
   SInt16       mDynamicEncoderMaxVal; // !!!! DEPRECATED VERSION OF STRUCT !!!!
   SInt16       mDynamicHomeVal; // !!!! DEPRECATED VERSION OF STRUCT !!!!
   UInt8        mDynamicEncoderSensitivity; // !!!! DEPRECATED VERSION OF STRUCT !!!!
   UInt8        mDynamicFlags; // !!!! DEPRECATED VERSION OF STRUCT !!!!
} ParamInfo_Vers3; // !!!! DEPRECATED VERSION OF STRUCT !!!!
1

There are 1 answers

1
l'L'l On

Why not use the @available attribute:

// you'll get a deprecation warning here.
@available(iOS, deprecated: 10.2, message: "ancient")
typedef packed struct {
    ....
}

I'm not sure if it works for Obj-C, but for Swift it definitely should. It's also possible to get creative:

#if DEBUG
@available(*, deprecated, message: "Use newer instead")
let dep = "deprecated"
#else
@available(*, deprecated, message: "Use newer instead")
let `self` = "deprecated"
@available(*, deprecated, message: "Use newer instead")
let `DEP` = "deprecated"
@available(*, deprecated, message: "Use newer instead")
let Optional = "deprecated"
#endif

So below you would have two items deprecated:

kSTRING_CONSTANT = "123"

print("123", obtain(self: "123"))

print(DEP)  // deprecated
print(self) // deprecated
print(kSTRING_CONSTANT)