String NSString and what difference?

Swift programming language learning time may not experience this thing,But with the depth of learning,As you read other people's code when,You will probably encounter this type NS,This time you will certainly be curious,similar String and NSString In the end where the difference? They seem to be exactly the same way! and,As by keyword,We can also easily make data conversion between both of them。

Make it clear type NS,We have to start from NeXTSTEP operating system to start the year:

To write the NeXT operating system,The invention Objective-C。Until now,Apple's operating system and all applications are written in this language.。and,In order to facilitate developers,There are a Cocoa framework。

we all know,OC is not a separate language,It comes from C Language,Like a superset of the C language。So it is not similar to the C ++ namespace,To avoid conflicts,Then you need to distinguish a unique prefix,For example, together with the C language is not this type of String,So naturally there NSString type the name of the class。

As to why NS

Which it is not known,In short prefix been using this became a problem left over from history,You canThis pageSee a variety of known prefix。


 

Now Swift to be compatible OC,That will naturally compatible with these types,You can use the Swift String type,Also you can use the OC type NSString - sometimes there are some who do not have the former method for you to use (for example, the string into digital。)


 

Further reading

NeXTSTEP

 

 

Original article written by LogStudio:R0uter's Blog » String NSString and what difference?

Reproduced Please keep the source and description link:https://www.logcg.com/archives/1054.html

About the Author

R0uter

The non-declaration,I have written articles are original,Reproduced, please indicate the link on this page and my name。

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *