Increasing an integer value of a UITextField

This is the code completion code that animates squareOne

. When it is clicked, it becomes hidden. If the image index is used squareOne

, this is the same as icon

and if squareOne

hidden, the animation repeats. (This is the condition where I want the score to increase). If squareOne

not pressed, it will still repeat.

completion:^(BOOL complete) {
    if (complete) {
        [self squareOneColour];
        [self squareOneMover];
        if (self.squareOne.hidden==YES) {
            if (a==b) {
                [self squareOneColour];
                [self squareOneMover];
                //I want the score to increase here
            } else if (a!=b) {
                [self squareOneColour];
                [self squareOneMover];
                NSLog(@"square one isn't supposed to be pressed");
}}}}];} //Just to make more compact

      

When I try to do this, I always create dozens of variables NSString

and NSUInteger

, and I think my way is inefficient and it doesn't work ... Can anyone help me get the integerValue

textbox score

to enlarge on every click squareOne

and match the image on icon

?

+3


source to share


1 answer


How easy it is to use:

myTextField.text = @(_myTextField.text.integerValue + 1).stringValue;

      

What are we doing:



  • Get integerValue from textbox and add
  • Set it as a value in the peroperty textbox by placing it as NSNumber (using "@") and then call the stringValue method on it.

Regarding code formatting:

  • I recommend not using trailing comments, for example foo += 5 //Add foo-tax

    . The rationale is that developers can take the time to get comments on comments so they can line up and format well. Its the usual "lint" check in code quality tools.
  • Do not put all curly braces on one line. It's usually best to stick to formatting conventions.
+3


source







All Articles