iOS Dev – Assignment #2 – Task #3

Protocols In the header file of the BasicCalculator you will find a protocol that defines a method

- (void)operationDidCompleteWithResult:(NSNumber*)result;

Make your ViewController-Class comply to that protocol.

First define the view controller as delegate of the calculator, then define required method of the protocol and let it display the result in the view:

// ViewController.h
@interface ViewController : UIViewController <BasicCalculatorDelegate>

- (void)operationDidCompleteWithResult:(NSNumber*)result;

// ViewController.m
- (void)operationDidCompleteWithResult:(NSNumber*)result {
    self.numberTextField.text = [NSString stringWithFormat:@"%@", result];

Please note that at the moment the view controller class only complies to the protocol. Even if its methods would already work as intended, nothing changed in the functionality compared with the previous task, because nobody actually uses the protocol …


Leave a Reply

Your email address will not be published.