Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert NSString to Character in Swift?

I want to convert NSString to Character in Swift.

I am getting a String from NSTextField, where I input a single character (Example "@"), I need this in Character type.

like image 485
Dejan Skledar Avatar asked Oct 25 '14 17:10

Dejan Skledar


People also ask

Is NSString UTF 8?

An NSString object can be initialized from or written to a C buffer, an NSData object, or the contents of an NSURL . It can also be encoded and decoded to and from ASCII, UTF–8, UTF–16, UTF–32, or any other string encoding represented by NSStringEncoding .

What is NSString in Swift?

NSString : Creates objects that resides in heap and always passed by reference. String: Its a value type whenever we pass it , its passed by value. like Struct and Enum, String itself a Struct in Swift.

What is NSString in objective c?

(NSString *) is simply the type of the argument - a string object, which is the NSString class in Cocoa. In Objective-C you're always dealing with object references (pointers), so the "*" indicates that the argument is a reference to an NSString object.


1 Answers

Use Character class

var chars = [Character](str)
like image 118
Mohsen Avatar answered Nov 15 '22 11:11

Mohsen