19

I have some warning which worked well in ios 7 & 8. While we work with iOS 9 its gives me a warning.

This is the warning :

'appearanceWhenContainedIn:' is deprecated: first deprecated in iOS 9.0 - Use +appearanceWhenContainedInInstancesOfClasses: instead

So I used this code :

[[UITextField appearanceWhenContainedInInstancesOfClasses:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];

Instead of this code:

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];

But when I used I got the error:

Too many arguments to method call, expected 1, have 2

warning: 'base64Encoding' is deprecated: first deprecated in iOS 7.0

In below code:

 NSString *authValue = [NSString stringWithFormat:@"Basic %@", [authData base64Encoding]];

warning: 'searchDisplayController' is deprecated: first deprecated in iOS 8.0

In below code:

[self filterContentForSearchText:searchText scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
                                                   objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];

warning: 'sendSynchronousRequest:returningResponse:error:' is deprecated: first deprecated in iOS 9.0 - Use [NSURLSession dataTaskWithRequest:completionHandler:] (see NSURLSession.h

In below code:

NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

I am working with iOS9. I need to remove all these warnings. Thanks in advance!

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
user5513630
  • 1,709
  • 8
  • 24
  • 48
  • If you command-click on the method in question, you will jump to the definition, and in many cases the deprecation notice should tell you what method to use instead. For example, `+appearanceWhenContainedInInstancesOfClasses:` now takes an `NSArray` of `Class` objects instead of a `va_args` list of `Class` objects. – Zev Eisenberg Nov 04 '15 at 15:28

1 Answers1

50

appearanceWhenContainedInInstancesOfClasses: wants an NSArray of classes. Thus:

[[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setTextColor:[UIColor whiteColor]];

Instead of base64Encoding (which has been deprecated since iOS 7.0 so that's not a new warning for you), use this:

NSString *authValue = [NSString stringWithFormat:@"Basic %@", [authData base64EncodedStringWithOptions:0]];

Regarding searchDisplayController, see this Q&A.

Regarding sendSynchronousRequest:returningResponse:error:, the error message is clear. You need to rewrite that part of your app to use an NSURLSession and its dataTaskWithRequest:completionHandler: method. There are lots of helpful resources for this on the Internet, like this objc.io article: “From NSURLConnection to NSURLSession”.

Community
  • 1
  • 1
rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • Hey rob, base64encoding worked well.But that `appearanceWhenContainedInInstancesOfClasses:` got 2 errors: `Expected identifier` i tried to add but the errer is still.. Second error: ` No known class method for selector 'appearanceWhenContainedInInstancesOfClasses:setTextColor:'` – user5513630 Nov 04 '15 at 15:38
  • I got the brackets slightly wrong. I bet you can figure out how to fix it if you just look at it for a minute. – rob mayoff Nov 04 '15 at 15:40
  • one question- i used synchronous - dies it need any delegate methods to add to solve my waring, Because i haven't use any delegate method ...For my question - 4 – user5513630 Nov 04 '15 at 15:50