srolesen
srolesen

Reputation: 21

Xcode 7 suppress deprecated warnings

For compatibility I regrettably need to use methods that were deprecated in iOS 9, and it generates warnings that I am not able to suppress after 15 hours of trying. Example:

'CFWriteStreamCreateWithFTPURL' was deprecated in iOS 9.0: Use NSURLSessionAPI for ftp requests'

I have tried:

  1. project>target>Build Phases>click on appropriate file, and select flag -w
  2. project>target>Build Phases>click on appropriate file, and select flag -(specific flag for error)
  3. project>project>Build Settings>Apple LLVM 7.0 - Warnings - All Languages>Depreciated Functions> No
  4. project>project>Build Settings>Apple LLVM 7.0 - Warnings - Objective C>Overriding Depreciated Objective C Methods>No
  5. tried finding pragma alternative but it looks like it is not possible
  6. Edit: I need to use depreciated methods regardless of what OS version is on device

I can suppress warnings in ObjC, but it just doesn't seem to work in Swift 2.0 and I have to admit that it's starting to really bug me, I know that I have to use different methods eventually, but right now it is not possible.

How do you suppress warnings in Xcode 7/Swift 2?

Upvotes: 1

Views: 831

Answers (2)

gnasher729
gnasher729

Reputation: 52632

The easiest method is to have an Objective-C file full of methods with similar names to the deprecated ones, and calling them. Let's say methodX is deprecated, then you add

- (void)methodX_deprecated {
    [self methodX];
}

and put a compiler directive to ignore deprecated methods around this. What's nice is that it tells you where exactly in your code you are using deprecated methods, because eventually you want to get rid of them (when iOS 11 is released)

Upvotes: 0

srolesen
srolesen

Reputation: 21

I was the one who asked the question above, and if anyone is here looking for the answer to the same problem here is what I have found so far: point 1-6 are not effective in swift because there is no precompiler. (if that is really the case i wish apple would have warned me when I tried to use -w)

if you really do need to use deprecated methods and are unwilling to put up with the warnings it generates then you can add that part of your code as a framework and compile that part of your project for a previous OS version. It would be better to not use deprecated methods at all! http://www.rockhoppertech.com/blog/swift-framework-creation/

I hope this is helpful to someone, and if it is wrong then please tell me why and how below :)

Upvotes: 1

Related Questions