Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Do you need nsstring to import string in swift3?


Asked by Ellis Mercado on Dec 12, 2021 FAQ



In Swift3 import foundation is not required, At least not in a Project. String should have all the functionality as NSString. Answers above work fine for values in the range of a 32 bit Int, but values over this won't work as the value will roll over.
Similarly,
Swift automatically bridges between the String type and the NSString class. This means that anywhere you use an NSString object, you can use a Swift String type instead and gain the benefits of both types—the String type’s interpolation and Swift-designed APIs and the NSString class’s broad functionality.
Consequently, Swift’s String type is bridged with Foundation’s NSString class. Foundation also extends String to expose methods defined by NSString. This means, if you import Foundation, you can access those NSString methods on String without casting.
One may also ask,
Despite this simplicity of syntax, Swift’s String type is a fast, modern string implementation. Every string is composed of encoding-independent Unicode characters, and provides support for accessing those characters in various Unicode representations. Swift’s String type is bridged with Foundation’s NSString class.
And,
The contents of a String can be accessed in various ways, including as a collection of Character values. Swift’s String and Character types provide a fast, Unicode-compliant way to work with text in your code.