3

The is the completion code of the code that animates squareOne. When it is clicked it becomes hidden. If the index of the image squareOne uses, is the same as icon and if squareOne is hidden, then the animation repeats. (This is the condition I want the score to increase on). If squareOne isn't clicked at all 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 doing this I always create dozens of NSString and NSUInteger variable and I think my way is inefficient, and it doesn't work... Can anyone help me get the integerValue of the textfield score to increase every time squareOne is pressed and matches the image on icon?

Minestrone-Soup
  • 399
  • 1
  • 16

1 Answers1

3

How about just using:

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

What we're doing is:

  • Get the integerValue from the text field and add one
  • Set it back as the value on the text field's text peroperty, by boxing it as an NSNumber (using '@') and then call the stringValue method on it.

Regarding code formatting:

  • I recommend not to use trailing comments, eg foo += 5 //Add foo-tax. The rationale is that developers can waste time getting trailing comments to line up and be formatted nicely. Its a common 'lint' check in code quality tools.
  • Don't pack up all of your braces into one line. It's usually best to stick to formatting conventions.
Jasper Blues
  • 28,258
  • 22
  • 102
  • 185
  • 1
    `integerValue` is a property of `NSString` and `stringValue` is a property of `NSNumber`, so your "technically" note is unnecessary. Apple changed a boat-load of methods like these into properties with iOS 8. – nhgrif Nov 13 '14 at 01:51
  • @nhgrif "Technically dot notation is only for properties, but it can look nice for simple methods (ones that would be "computed properties" in Swift)." . . ah, you're right. – Jasper Blues Nov 13 '14 at 01:55