× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Type 'String' does not conform to protocol 'NSCopying' error when getting object from NSDictionary

Antonio Bello
Mar 01, 2015
<p>Swift automatically converts <code>NSDictionary</code> as <code>Dictionary&lt;NSObject, AnyObject&gt;</code>. If you know that a value stored in a <code>NSDictionary</code> is a string, then you have to cast to <code>String</code>.</p> <p>The problem in your case is about the value, not the key, so you just have to cast as follows:</p> <pre><code>category.name = excerciseCategoryDictionary["name"] as String </code></pre> <p>or</p> <pre><code>category.name = excerciseCategoryDictionary["name"] as String? </code></pre> <p>depending from what's the actual type of the object you are assigning the value</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/24725708/Type%20'String'%20does%20not%20conform%20to%20protocol%20'NSCopying'%20error%20when%20getting%20object%20from%20NSDictionary/24726140">Stack Overflow</a>.</p>

Get New Tutorials Delivered to Your Inbox

New tutorials will be sent to your Inbox once a week.

comments powered by Disqus