Wednesday, 22 April 2015

April 21

#
# Working with protocols - Apple
#

Consider a custom view class that shows a pie chart. we have

@protocol XYZPieChartViewDataSource
-(NSUInteger)numberOfSegments;
-(CGFloat)sizeOfSegmentAtIndex:(NSUInteger)segmentIndex;

#
# bitmaker notes
#
@class Task;
@protocol TaskDelegate <NSObject>

@optional 
-(void) simpleTask: (NSString*) the optionalTask;

# tues: table views the hard way
-(BOOL)

#
some of the steps
  1. need a CGrect that defines the bounds

#
everything stored in NSUserDefaults 

#
#stanford lec 4
#
uifonttextstyleheadline
uifonttextstylecaption1
uifontt

what kind of attributes are in an attributed string
NSFontAttributeName
The value is a UIFont

NSForegroundColorAtrributeName 

#
Drag a nav controller object into the storyboard
the default nav controller is associated with a table view controller.

Select the relationship segue - view controllers option
Relationship segue - view controllers
Change the System Item from Custom to More

3 things need to be done
  1. add the “about.html” and “about.jpg” to the Xcode project
  2. assign a variable for UIWebView and associate it with the Web View object
  3. use the loadRequest  method in UIWebView to load web content

so I would expect something like
(UIWebView*)

drag supporting files to the Supporting Files folder.

#

everything with notifications is inside your app

Monday, 20 April 2015

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.


Thursday, 16 April 2015

April 16 

note
Selectors are ObjC internal representation of a method name

Selector is apparently a component of the target-action design pattern. This DP was mentioned in the first Stanford lecture in the MVC discussion.

q
"Object library" b/c you generate objects with it ?

q
Can custom classes be added to the object library? 
ans
no

note
Having some issues adding a .git file to a Xcode file that has been set to not have a .git

note

note
every view has 3 coordinate systems

note
There are 2 main graphics frameworks: UIKit, core graphics. They have different coordinate systems.

bug
Putting the initialization code in viewDidLoad did not do anything. The viewDidLoad method is never called.

The following SO thread helped me understand

the reason is that if you aren’t using storyboards the viewDidLoad method never gets called. This is true even if you alloc/init the viewController.

I was also confused about the difference between the UIViewController lifecycle and the UIView lifecycle. UIView has a method drawRect which is apparently where you are supposed to put all the drawing that is done on that view. 

To Do
Understand why we need the drawRect method rather than just putting all the drawing into 

There are 4 different possible ways to make our view controller visible. 

task 
make the button add another red block directly below the previous red block.

note
there is no reason a parent view should not know about all its children. i.e.  they can be placed in the header.

Remember
  1. for some reason the length of an array is given by count.
  2. In objective C all library methods are responsible for allocating their return values.
  3. nil, nil, nil, nil, nil, nil, nil
q
If I allocate an array but assign no elements and then try to get the first element then what happens ?

bug
a runtime errror for trying to send the copy message to my custom UIView. Does not recognize copy.


q
is there anything bad about drawing the whole scene in loadView of the root viewController ?
I think this is fine.
If there was some common things that I wanted drawn on all my views then I would to this drawing by overriding the drawRect method of the custom view.

undeclared identifier error: first look if it is a property or a local variable of the method.

note
The first nontrivial statement in a recursive function is usually an if statement testing if you are in the base case of the recursion or not.

issue
Step 1: define the problem
My recursive function prints values for height,width,x start, y start. The x and y values of the start should both be 50. The value that is printed is 0 for both. So view was drawn in the wrong place because I was using a different coordinate system.

-(CGRect)convertRect:(CGRect)rect toView:(UIView *)view

solution
convertRect is a good way to convert something into the view's coordinate system.

note
CGRects are almost always used for frames. 

the view that is a the target of the conversion operation is used as input. If view is nil then the method convert to base coordinates.

else both the view and the receiver have to belong to the UIWindow object.

there are 2 views involved.
This is sort of a projection operation. self is a view that we will project onto the other view. 

Question
Give a high level explanation of what the appDelegate does.


Wednesday, 15 April 2015

April 14

Erik "Cultivating online presence
LinkedIn endorse classmates on skills
LinkedIn groups
Twitter: use hashtags to reach more people

> Slides are online

#
[someObject foo:nill]
we have the same situation in which Java will produce a NullPointerException. 

The nil object will be accessed first at [anArray count] However, instead of throwing a NullPointerException, Objective-C will simply return 0 in accordance with the rules above, so the loop will not run. 
However, if we set the loop to run a set number of times, then we're first sending a message to anArray at [anArray objectAtIndex:i];
This will also return 0, but since objectAtIndex: returns a pointer, and a pointer to 0 is nil/NULL, NSLog will be passed nil each time through the loop. (Although NSLog is a function and not a method, it prints out (null) if passed a nil NSString.

For some reason NSLog prints the nill pointer as nil.


# An example of sending a message to the nil pointer.
NSString* string1=nil;

int y= [string1 stringByAppendingString:@"a"];
The compiler gives a warning about type conversion. But the value of y will be 0.

#
ObjC lec 1
strong means “keep this pointer in the heap as long as I or anyone else have a strong pointer to it”

In ObjC you can send a message to a _nill pointer.

NSString* astring;
[astring 

#
What is IBOutlet
An indicator. 

#
The prototype cell is associated with the UITableViewCell.
Have to change it to CustomTableCell class.

the method dequeueReusableCellWithIdentifier:cellIdentifier returns the “default” cell UITableViewCell. We have customized this to CustomTableViewCell. So we are responsible for casting this return to the new cell type.

in chapter 5 we want to respond to the user touching the screen.

More delegates!
We use UITableViewDelegate in order to handle cell selection
Data sources are an example of delegates

The following 2 methods are used for the selection of a particular row
-tableView:willSelectRowAtIndexPath:
-tableView:didSelectRowAtIndexPath

4:00pm
Look at the UITableViewDelegate
Look at “Managing Selections”
we have willSelectRow and didSelectRow
these are the methods we are going to implement

UITableViewController already adopts the UITableViewDelegate protocol.
This means that any of that delegates methods can be completed.

A table cell in Basic style has 3 parts.

The following 2 lines of code are used to make a check mark at the end of the line
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]
cell.accessoryType = UITableViewCellAccessoryCheckmark

a cell has some accessories available to it.
need to select one of these.


Tuesday, 14 April 2015

April 12

App Plan
I would like to be able to be able to
1. have a canvas with infinite scroll and pinch to zoom
2. be able to add polygons
3. there will be no coordinate system.
the polygons will be constructed in the following way

There are 8 actions
1. Add poly
3. select poly (select poly changes the color)
3a. add vert at head
3b. del vert at head
3c Hausdorff = select another. simple animation ending with a line drawn between the pair of points determined by Hauss. This line disappears if
3d min hausdorff = select another
3e delete
7. exit mode
(add and delete are hard

other
1. don't care about snap to point
2. don't care about recognizing boxs, rects, etc

Good fundamentals for IOS dev
1. read documentation before asking online
2. watch WWDC videos

Bugs
Tried to create a new class and got the error
"redefinition as a different kind of symbol"
But I changed rect to rectangle and the bug was resolved. I guess there is something in the Foundation namespace.

#
Outstanding issues
I still have not figured out how to do refactoring in Xcode..

#
Started at 9:00
In an hour and 45 mins was only able to implement a single super class...

# 2pm
again
UITableViewDelegate
UITableViewDataSource

NumberOfRowsInSectionc
cellForRowAtIndexPath
these are methods which are part of the UITableViewDataSource protocol
this means that it is mandatory to implement these methods as part of the protocol.

An ObjC thing in the namespace is distinguished by the names of each of its inputs.
So for example we could call a method that takes two inputs X and Y
"X:Y"

#
In java the class file name is forced to be the same as the file name
But this is not required in C...

#
Bug

Was reading the text too quickly. Need to read each line slowly to grasp its meaning.

#
# notes on the text
#
Constraints are visible in Document Outline
There are 4 kinds of constraints

There are a couple of things we need to do
1. we need to switch from UITableViewController over UITableView
So its important to understand that UITableView will work for table display. We just need to implement that protocol
Whenever I'm given a list of protocols in the form <A,B,C,D> to implement it would be good to compare A,B,C,D to see if there are some common words that start the method names.
Unlike Java which would have some define some class for each protocol, in objective C we just use prefixes to designate a particular class.

Chapter 4
Another new project. Single view application.
We call it CustomTable.
We disable size classes by going into the File Inspector
We are going to create a Cocoa Touch Class called CustomTableViewController

#
viewDidLoad method
add some stuff
we are needing to implement two datasource methods

tableView:numberOfRowsInSection
tableView:cellForRowAtIndexPath
there are default implementations. However, they don't usually work good.

In one of them we are going to pass in the number of sections. However, the number of sections here is one.
April 13
method that returns set of students

Defining them
Start by defining the protocol
using @protocol

Objective C only has single inheritance. Inheritance from a single class.
@protocol TaskDelegate <NSObject>

#
Limits of tools
Is UITableView not able to display a distinct image for each entry in the table view.

To build a custom cell simply use
UILabel, UIImageView
are UIControls that can be added to the prototype cell.

To perform these customizations we need to change the cell style from Basic to Custom.

2 changes are needed to make the images larger.
1. change row height of the cell
2.

#
Reading
"Programming Views in IOS"
Each parent is responsible for positioning its children.

#
What is the difference between an action and an outlet ?

#
ViewController are informed about view status using outlets.
Views are updated by actions.

I have a TextView for entering celcius temp. I need this view to communicate with the viewcontroller class. So I would think I need to use action.

"Interface type" cannot be statically allocated.

Questions
What does static allocation mean in ObjectiveC ?

#
Useful commands
initWithFormat

Remember
Keyboard does not vanish after the user has entered some text. The solution is to create a method that takes a sender of type id as input and returns an IBAction.
Did end on exit