TJ Asher
TJ Asher

Reputation: 767

Swift - Cannot get real text from UITextField - get NCIStr result instead

I have a UITextField that has the "Secure Text Entry" checked in my storyboard.

When I assign the text of the UITextField.text property to a variable I get a value of:

class name = _NSClStr

instead of the actual value of the text which is:

ABCD

If I uncheck the "Secure Text Entry" in the storyboard and do the same assignment to a variable I get the actual text.

The code to assign the value is pretty simple:

passFieldText = self.passField.text!

The debugger output for when the secure entry is enabled:

(lldb) print passFieldText
(String) $R0 = class name = _NSClStr

The debugger output for when secure entry is disabled:

(lldb) print passFieldText
(String) $R0 = "ABCD"

I even tried to use a local variable instead of a class variable:

let passFieldText = self.passField.text ?? ""

Same result!

(lldb) print passFieldText
(String) $R0 = class name = _NSClStr

The passFieldText is passed along to another function to validate the password and in that other function it also shows a value of class name = _NSClStr

What am I missing?

Cheers!

Upvotes: 8

Views: 1916

Answers (2)

Elias Al Zaghrini
Elias Al Zaghrini

Reputation: 295

I had the same issue, the only way to fix it is to interpolate the String:

password = "\(self.passField.text)"

It's not exclusive for print()

Upvotes: 3

TJ Asher
TJ Asher

Reputation: 767

So the cause of my problem was not the text from the password field. It turned out to be an issue with an external service.

However, to help anyone else to see the actual value of their password fields in code I'll share the suggestion by Dominik 105 and how I implemented it.

To see the value of the password field if I put the PRINT in code I see the actual value of the password field.

print("password1: \(self.passField.text ?? "")")

gives me the result I expect

ABCD

If I do the same PRINT in the debugger output I see the _NSClStr thing.

Upvotes: 0

Related Questions