What is difference between NSDictionary vs Dictionary in Swift?

后端 未结 4 2126
清歌不尽
清歌不尽 2021-02-18 12:52

I\'m learning Swift, and I can see Dictionary in it.
But there are lots of examples that are using NSDictionary with Swift.
What\'s the

4条回答
  •  我寻月下人不归
    2021-02-18 13:23

    Here's the deal,

    For all intents and purposes, they are the same thing. So long as you import Foundation, the compiler will know them as the same thing.

    As for specific differences, thus Apple doc helps.

    Overview

    NSObject is the root class of most Objective-C class hierarchies. Through NSObject, objects inherit a basic interface to the runtime system and the ability to behave as Objective-C objects.

    What that means, in a nutshell, is that NSObjects are ancient relics from olden (objective c) times.

    As for what is better, that is up to you. I find swift objects better than the ns counterpart just for the purpose of keeping code modern, however you may have to use ns objects if you are using code like NSURLCONNECTION that requires ns objects.

    Hope this helps.

提交回复
热议问题