I have a UIAlertView that asks for input and then the input is saved to a UITextField. I then want to be able to set the string of a CATextLayer to the text of the UITextField. I can NSLog the text in the text field to confirm it was set just fine like this:
NSLog (#"name = %#", nameTextField.text);
But if I try to use similar code to set the string of the CATextLayer:
[nameLayer setString:#"%#", nameTextField.text];
I get an error that says "Too many arguments to method call, expected 1, have 2". What do I need to do to set the string in the nameLayer to be the same as the text in the nameTextField?
The problem is that setString: expects one argument any you're sending two: #"%#" and nameTextField.text.
You sould be doing [nameLayer setString:nameTextField.text]; or even nameLayer.string = nameTextField.text;.
Related
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!
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()
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.
In Xcode 10 code completion, the text underlying the placeholder tokens has an extra #T# before it (to see that this is so, copy and paste the inserted code template into a different text editor):
let alert = UIAlertController(
title: <#T##String?#>, message: <#T##String?#>,
preferredStyle: <#T##UIAlertController.Style#>)
What is that? Does "T" mean Type? What difference does it make in my usage of the placeholder?
The syntax <#T##_A_##_B_#> is used to specify a default piece of code for the placeholder. The placeholder will be displayed as _A_, but when the user presses the enter key the placeholder will be replaced with _B_.
Placeholder:
After pressing enter:
It'd a useful feature when presenting something to an audience, because as opposed to snippets, I would't need to remember the name of each snippet, I'd just select a placeholder and press enter to get the right piece of code.
EDIT:
Answering your question, indeed it seems that the T refers to type. If you try to replace the placeholder with an expression, like <#T##Example1##let i = 3#>, the placeholder it's not replaced with let i = 3 as you would expect. It is instead replaced with <<error type>>.
Furthermore, this placeholder <#T##transform: (Error) throws -> U?##(Error) throws -> U?#> is replaced with:
{ (<#Error#>) -> U? in
<#code#>
}
My guess is that when you prepend the T you are telling Xcode that you will provide a type, then Xcode finds an appropriate default value for that type.
I am using UILexicon for the suggestions in custom keyboard. Following is code:
-(void) keyTapped:(UIButton*)button {
[self requestSupplementaryLexiconWithCompletion:^(UILexicon *lexicon){
// self.lexicon = lexicon;
NSLog(#"%#",lexicon.entries);
for (UILexiconEntry* entry in lexicon.entries) {
NSLog(#"%#=%#",entry.userInput,entry.documentText);
}
int i=0;
}];
}
But it is returning always same array of entries. Can anyone suggest me how to use it. I will mark correct your answer if it works. Thanks.
It's working but you should implement your own function to compare the UILexiconEntry list with the entered string as stated by apple :
UILexiconEntry
A lexicon entry specifies a read-only term pair, available within a UILexicon object, for use by a custom keyboard.
You can employ a lexicon entry by matching user input against the entry’s userInput value, and then inserting into the current text input object the corresponding documentText value. For example, if the user typed the string “iphone”, the lexicon entry with that exact, case-sensitive string in the userInput property has the string “iPhone” in the corresponding documentText property.
In some cases, the documentText string is in a different text script than the userInput string.
I have a simple UILabel that is printing text as follows:
John Doe sent a message to blahblah-
blah#blahblah.com
Thus, the email address here : blahblah-blah#blahblah.com is being cut and partially displayed on the next line. What do I need to do to make it display as :
John Doe sent a message to
blahblah-blah#blahblah.com
?
I already have the following :
self.mailLabel.lineBreakMode = NSLineBreakModeByWordWrapping;
self.mailLabel.numberOfLines = 0;
The string in question is :
[NSString stringWithFormat:#"You sent a message to %#", emailAddress];
What should I do here? Remember, the name can be long and hence, adding a line break in the string won't work because I don't want the following case :
Jonathon Dawson sent a message
to
blahblah-blah#blahblah.com
which should be
Jonathon Dawson sent a message
to blahblah-blah#blahblah.com
self.mailLabel = [NSString StringWithFormat:#"You sent a message to\n%#"];
You use \n to make a new line.
Also, make sure you set the numberOfLines to 2 on the label.
You need to add ZWNBSP(Zero-width no-break space) characters to the left and to the right of - (hyphen, aka dash) symbol:
self.mailLabel.text = [self.mailLabel.text stringByReplacingOccurrencesOfString:#"-" withString:#"\u2060-\u2060"];
Remarks:
U+2060 - Zero-width no-break space Unicode character prevents any line breaks that may be inserter to wrap the word before and after it. As soon as UILabel (as well as other text controls in Cocoa) respects Unicode, you will get text without undesired line breaks.
Wikipedia link: http://en.wikipedia.org/wiki/Zero-width_no-break_space
NSSet *subFolders = [_account subscribedFolders];
NSLog(#"subFolders: %#",subFolders);
Output:
...
"[Gmail]/\U05d8\U05d9\U05d5\U05d8\U05d5\U05ea",
"[Gmail]/\U05d7\U05e9\U05d5\U05d1"
...
Is there any way I can show the above text in its original language (Hebrew) ?
Things I tried:
changing the debugger from LLDB to GDB - Didn't work
Checking under preferences -> Text Editing UTF-* is selected
Thanks
There is no issue with displaying unicode characters in the console, so I would assume it's the way the string is getting into the set in the first place.
I would suggest iterating over all the objects inside subFolders with something like:
for( id object in [subFolders allObjects] ) {
//Print out the name of the item explicitly
}
Even if this doesn't work, it at least lets you work with the strings directly. If it's still printing out:
"[Gmail]/\U05d8\U05d9\U05d5\U05d8\U05d5\U05ea"
It would look as if you're being sent escaped unicode characters, and I would suggest this: https://stackoverflow.com/a/7861345/352891 - this may work directly on NSSet's description
NSString* strOld=[NSString stringWithFormat:#"%#",responseObject];
NSLog(#"%#",[NSString
stringWithCString:[strOld cStringUsingEncoding:NSUTF8StringEncoding]
encoding:NSNonLossyASCIIStringEncoding]);