NSString or String

0

Well, I had a doubt about the primitive types of Swift, and some classes like NSString.

var miString : NSString
var miString2 : String

miString = "Hola"
miString2 = "Hola"

miString.length
miString2.characters.count

1. Why and how is it that primitive types have methods?

2. Because and how is it that the NSString object can be equal to a String without using any constructor ... (As it would be NSString("String o lo que sea") )

    
asked by MatiEzelQ 19.03.2016 в 15:33
source

1 answer

5

You must differentiate between NSString and String . In Swift, an object of type String is a primitive type, but it has extensions with methods to manipulate them.

In the case of NSString is not a primitive type. You just have to look at your initializer to know it's a class like any other that allows you to use chains and do operations with them.

On being able to equal a NSString to a String and the other way around, it is simply an implementation of the frameworks that allow to do those operations.

    
answered by 19.03.2016 / 16:35
source