cs193p – Assignment #1 Task #3

Please note, this blog entry is from a previous course. You might want to check out the current one.

Add a text label somewhere which desribes the results of the last flip. Examples: “Matched J♥ & J♠ for 4 points” or “6♦ and J♣ don’t match! 2 point penalty!” and simply “Flipped up 8♦” if there is no match or mismatch.

The information needed to display is already inside the model. Analogue to the score create a new property to hold the text string, and set it in flipCardAtIndex:
Continue reading “cs193p – Assignment #1 Task #3”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #1 Task #2

Please note, this blog entry is from a previous course. You might want to check out the current one.

Add 4 cards to the game (for a total of 16).

Start by selecting one row of cards, copy and place them on your storyboard:

cs193p - assignment #1 task #2
cs193p – assignment #1 task #2

Now connect all four new cards to the outlet connection by control dragging each of them to:

@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *cardButtons;

The complete code is available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

cs193p – Assignment #1 Task #1

Please note, this blog entry is from a previous course. You might want to check out the current one.

Follow the detailed instructions in the lecture slides (separate document) to reproduce the latest version of Matchismo we built in lecture (i.e. the one with multiple cards) and run it in the iPhone (normal, non-Retina, non-iPhone 5) Simulator. Do not proceed to the next steps unless your card matching game functions as expected and builds without warnings or errors.

… actually done during the lecture. The complete code is available on github.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

iOS Dev – Assignment #2 – Extra Task

Add a memo-function to store a number

Start my rearranging the buttons to make space for three new ones:

iOS Dev – Assignment #2 - Extra Task – Additional Buttons
iOS Dev – Assignment #2 – Extra Task – Additional Buttons

Create a variable to store the value:

float numberInMemory;

Initialize it:

- (void)viewDidLoad
{
    ...
    numberInMemory = 0;
}

And connect the buttons to suitable methods:

- (IBAction)addMemoryButtonPressed:(UIButton *)sender {
    numberInMemory += [self.numberTextField.text floatValue];
}

- (IBAction)subtractMemoryButtonPresed:(UIButton *)sender {
    numberInMemory -= [self.numberTextField.text floatValue];
}

- (IBAction)getMemoryButtonPressed:(UIButton *)sender {
     self.numberTextField.text = [NSString stringWithFormat:@"%@", [NSNumber numberWithFloat:numberInMemory]];
}
FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

iOS Dev – Assignment #2 – Task #4

Delegation The BasicCalculator communicates its result to a delegate. This asynchronous implementation is a bit overhead in this simple example, but think of a scientific calculator with more elaborate functionality. You can start a very complex operation and the Calculator-Class takes care of processing this operation in the background. After some time it finishes and communicates its result to the controller. Have a close look at the implementation of the delegation in the Basic- Calculator class. Now make your ViewController class the delegate of the calculator and make the project a fully working calculator.

When the view has loaded initiate the calculator and set the view controller as delegate of the calculator:
Continue reading “iOS Dev – Assignment #2 – Task #4”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

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 …

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

iOS Dev – Assignment #2 – Task #2

Check some edge-cases Division by 0, double decimal points, leading 0s, …

Division by 0 is already handled in the code from the previous task.

For the double decimal points expand the commaPressed: method like in assignment #1:
Continue reading “iOS Dev – Assignment #2 – Task #2”

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail