April 20
Stanford Lecture 3
11:43
take a crack at the public API first. Which means figure out how people are people going to use it ???
it has to know some things in order to init
a count of how many matches are possible
needs to be at least 2
Components
Usually the first thing to put into the public API is a class init
After the init is created we need to make some properties.
we set the score readonly b/c publicly it cannot be changed.
#
steps: lazy instantiation of the CardMatchingGame
OUTLET
hold down control and drag into the interface just like with any other outlet
at the top where it says connection there is a choice of making an Outlet Collection
has to be strong b/c the view has a strong pointer to all the individuals.
mousing over the button on the left hand side shows that all 12 buttons are selected
when do we use lazy instantiation?
only in view controllers.
in VCs we always override the getter so that it also deals with the case where the object has not been initialized…
always remember that there is an alternative.
we can go into viewDidLoad and put all the initialization content.
#
bitfountain
free IOS7 course
#
bug
when card back is selected nil is displayed
however, the card image is working
Solution
Put a breakpoint into the suit method. I didn’t know how to breakpoint a property so I wrote the suit method.
Result
The suit method is never called
2:00pm
Bugs
Two issues
The first issue was that I was accessing a property directly using _whatever. This by itself is fine. But if you do things that way you need to do a check before every _whatever that this property has been initialized. Otherwise you end up just returning nil.
Style: using NSLogs is fine if both the class and the method are specified. Otherwise finding the logs can be very hard.
2:30pm
matching is causing issues
Solution: insert breakpoint inside the match function so I can see when it occurs.
2:50pm
Changed it from updating face-up-before to updating face up after
Reminder:
bool is printed using %d
2:55pm
Bug: my matching function will match same values with same values.
3:07pm
for some reason strings are compared using isEqualToString
#
#
#
Lecture #4 stanford
Foundation stuff
sometimes there are 2 versions of a method that do exactly the same thing
[NSString stringWithFormat:…]
[[NSString alloc] initWithFormat]
only watched about 3 minutes
A fun one is mutableCopy
[NSArray mutableCopy] ?
Its ok to send messages to nil.
[obj methodWhichReturnsAnInt]
Dynamic (also called late) Binding is a way that objective C differs from most languages.
id = pointer to a class of unspecified type
If you “send a message to an object” (run a method on an object) of type id that the object does not know then it will crash.
Takeaway: use id sparingly
Hard question at 14:56
#
#
#
Casting to any type is very dangerous.
Casting to id is even worse.
There are 2 ways to protect ourselves
FIRST Introspection: asking at runtime what class a particular object is.
SECOND
Method testing methods take a selector (SEL).
Question: is introspection only used when pulling things from array
Answer: there are 2 main times: array selection and MVC target action/delegation.
As long as an array is in the heap all its objects are in the heap.
(It has a strong pointer to all its elements)
NSNumber: only use it for putting numbers into arrays.
At 35:28 he gives the way to safely loop over array elements that are expected to be of a particular types but not guaranteed to be.
# 8:50-9:10
# Stack vs heap
#
Question: what is the stack. what is the heap
heap = a store that an application can use to get memory
this video is crap
this is better
#
#
#
Book chapter 10
Creating a view controller class
In the previous chapter we created a view controller that served
UIViewController is a class in UIKit not in
before the segue is invoked the method
prepareForSegue:sender
is triggered
Every storyboard segue in the app should have a unique identifier.
#
A possible point of confusion is that though I can identify the destinationViewController I don’t get access to its namespace.
#
Bug: caused by mixing up the class name and the instance name.
445pm
Bug: no text being displayed on the label.
Question: is the prepareForSegue method being executed ?
#
#
#
Remember
Creating a segue from prototype cell to a custom view controller is trivial.
Segues can pass data. This Apple’s language for it. I would rather say that a VC can set properties in another VC through a segue.
For example they can be used to pass the current row index
Questions: I don’t know what design pattern segues are part of.
Chapter 11
TabBarController
UIWebView
NavController gets embedded into TabBarController
When the embedding is done an icon appears at the bottom of the nav controller.