CopyPastor

Detecting plagiarism made easy.

Score: 0.8097662925720215; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2019-07-08
by Emre Ciftci

Original Post

Original - Posted on 2014-12-05
by Antonio



            
Present in both answers; Present only in the new answer; Present only in the old answer;

> You're using `NSDictionary`. Unless you explicitly need it to be that type for some reason, I recommend using a Swift dictionary.
> You can pass a Swift dictionary to any function expecting `NSDictionary` without any extra work, because `Dictionary<>` and `NSDictionary` seamlessly bridge to each other. The advantage of the native Swift way is that the dictionary uses generic types, so if you define it with `Int` as the key and `String` as the value, you cannot mistakenly use keys and values of different types. (The compiler checks the types on your behalf.)
> Based on what I see in your code, your dictionary uses `Int` as the key and `String` as the value. To create an instance and add an item at a later time you can use this code: > var dict = [1: "abc", 2: "cde"] // dict is of type Dictionary<Int, String> dict[3] = "efg" > If you later need to assign it to a variable of `NSDictionary` type, just do an explicit cast: > let nsDict = dict as! NSDictionary > And, as mentioned earlier, if you want to pass it to a function expecting `NSDictionary`, pass it as-is without any cast or conversion.

**Source:**
[Antonio's Answer][1]

[1]: https://stackoverflow.com/a/27313755/7512091
You're using `NSDictionary`. Unless you explicitly need it to be that type for some reason, I recommend using a Swift dictionary.
You can pass a Swift dictionary to any function expecting `NSDictionary` without any extra work, because `Dictionary<>` and `NSDictionary` seamlessly bridge to each other. The advantage of the native Swift way is that the dictionary uses generic types, so if you define it with `Int` as the key and `String` as the value, you cannot mistakenly use keys and values of different types. (The compiler checks the types on your behalf.)
Based on what I see in your code, your dictionary uses `Int` as the key and `String` as the value. To create an instance and add an item at a later time you can use this code:
var dict = [1: "abc", 2: "cde"] // dict is of type Dictionary<Int, String> dict[3] = "efg"
If you later need to assign it to a variable of `NSDictionary` type, just do an explicit cast:
let nsDict = dict as! NSDictionary
And, as mentioned earlier, if you want to pass it to a function expecting `NSDictionary`, pass it as-is without any cast or conversion.

        
Present in both answers; Present only in the new answer; Present only in the old answer;