Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify NSError localizedDescription

Do you guys know if there is a nice way to set/modify a NSError's localizedDescription after it has been instantiated other than recreating it? I didn't find any.

like image 465
user3250560 Avatar asked Mar 11 '14 20:03

user3250560


People also ask

What is Localizeddescription Swift?

A string containing the localized description of the error.

Which of the following is used when creating a NSError object?

The core attributes of an NSError object are an error domain (represented by a string), a domain-specific error code and a user info dictionary containing application specific information.


1 Answers

The NSError class is - like many Cocoa classes - immutable.

However, the doc states for -localizedDescription that:

By default this method returns the object in the user info dictionary for the key NSLocalizedDescriptionKey. If the user info dictionary doesn’t contain a value for NSLocalizedDescriptionKey, a default string is constructed from the domain and code.

So just use errorWithDomain:code:userInfo: to create a new instance or copy and supply an appropriate user info.

Here's another nice introduction to the NSError class.

like image 170
cacau Avatar answered Sep 24 '22 13:09

cacau