I have code in Xcode:
NSError *error = [[NSError alloc] init]; NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
And it causes the following error in the logs
[NSError init] called; this results in an invalid NSError instance. It will raise an exception in a future release. Please call errorWithDomain:code:userInfo: or initWithDomain:code:userInfo:. This message shown only once.
You might tell me that the answer is in the log, but I don't understand how to trigger NSError.
You are not allowed to instantiate NSErrorthrough -init; use -initWithDomain:code:userInfo:or constructor method +errorWithDomain:code:userInfo:.
NSError
-init
-initWithDomain:code:userInfo:
+errorWithDomain:code:userInfo:
In your case, this is redundant, since this method will create it in case of an error.
This is a normal template to use it:
NSError *error = nil; NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; if (!urlData) { NSLog(@"Error: %@", [error localizedDescription]); return NO; } // Successful
, . NSError *, nil. , . , NSError, - . , ,
NSArray* array = [[NSArray alloc] init]; array = ...;
NSError Cocoa , NSError - , , . . , , , , == nil.
:
NSError *error = [[NSError alloc]init];
NSError *error = nil;
, errorWithDomain:code:userInfo: initWithDomain:code:userInfo:.
errorWithDomain:code:userInfo:
initWithDomain:code:userInfo:
Use is -[NSError init]not recommended and may cause an exception in a future version.
-[NSError init]
Example:
NSError *errMsg = [NSError errorWithDomain:@"domain" code:1001 userInfo:@{ NSLocalizedDescriptionKey:@"Localised details here" }];
Source: https://habr.com/ru/post/1615956/More articles:Fast optional initialization - initializationChrome custom tabs and text box - androidhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1615953/what-is-the-difference-between-gradle-install-and-gradle-publishtomavenlocal&usg=ALkJrhj0IYQTrKCnxdr53Sc8b_E2hlMXdwChange the selection color of the entire page - cssSmack Android, creating a service for receiving messages - javaAre not English SMS displayed as multiple lines? - javaMNIST For Beginners ML - Why is the "One Hot" Length of Vector 11? - tensorflowJava 8 - lazy pricing? - javaScala Download file upload: Unable to write instance of views.html.uploadFile.type in HTTP - scalaCalling the C standard library function from asm in Visual Studio - assemblyAll Articles