Saturday, 18 July 2015

july 13

This post helped me understand that when using custom accessors the system will not complain. But the lack of complaint does not mean that things will work correctly.
"CoreData NSManagedObjectContexts use Key-Value Observing to track changes to the in-memory objects they own. They do this through the normal KVO mechanisms, though in some cases they leverage the runtime in unusual ways to accomplish this (which is why CoreData does not always play well with Swift).According to the documentationNSManagedObject subclasses do not automatically send KVO notifications for modeled properties. This may no longer be accurate, and is easy to verify if you are interested. For the most part it is irrelevant - if your application is interested in key value observing notifications for objects you control implement+automaticallyNotifiesObserversOf<Key> to emit automatic key value notifications for synthesized accessors.If you implement your own accessor methods for NSManagedObject properties (not...really...recommended...) you MUST ensure that the key value observing notifications methods are called at the appropriate times (willChangeValueForKey:/didChangeValueForKey:) in addition to the relevant CoreData specific methods (willAccessValueForKey:/didAccessValueForKey:). If you do not do so the internals of CoreData will not reliably track changes to those properties. And that would be bad.When a managed object instance changes the context that owns it sees the change via KVO and adds it to the internal change tracking of the context. These changes are coalesced, and when the context is saved the changes are committed.” -quellish
April 23 

Useful command
Control-Shift-Alt-v for pasting text without formatting. 

Some notes in the form of questions 

2. Give an example of using the CGRectInset method. Give 3 example arguments for it and the output that would be generated. Give an example of input that would result in the output being an empty rectangle. 

3. How do we search for an image in the assets folder with a particular name and do something based on the result of that search?

4. What two commands allow a Bez path to be drawn after it has been set up?

5. What counts as custom drawing on a view? What method would be used to manually force a redraw of the custom drawing on a view (Hint: it does not involve calling drawRect)? 

6. The method that gets the current drawing context. 

7. Describe 2 ways that images can be stored in the model. One way should involve the view being redrawn 

8. Give the 3 ways that a gesture recognizer can be added to code. 


Tuesday, 30 June 2015

june 27
segmented control is not working

Segmented controls work for buttons but look ugly.

Found out that it is possible to have multiple buttons on a nav. Was confused for a long time because there is apparently no good way to make multiple buttons in storyboard. (There are some ugly hacks.) Yet multiple buttons is trivial in code. 

Lesson: storyboards only ever offer a curated selection of the features that are used most often and are easy to set. 

note
keep track of what input is given in completion handlers

test
see if MailGen is now working (except for saving Draft obviously)

is nice

changed protocol.
now the cancel button doesn’t work.
do i enter didFinishWithResult ?

oddly if I put a breakpoint into didFinishWithResult then it crashes but no breakpoint == no crash

ok 
now header files should display the right date

reminder:
we cannot print out array in the debugger

attempting to print out an *optional* array results in the weird error message “Array index out of range”

q
why are there 12 Vert objects?

q
why are the managed objects in core data appearing multiple times ?
possible reasons
  1. fat finger
  2. test code gets run before everything and adds its own elements

I don’t see how testing could do this…

q
If I clobber the file does this change to 4?
ans
yes

note
using an optional type where an optional is needed will potentially cause failure

q
Why did it get changed to optional when I already it working as non-optional ?

result
turns out that the main problem was that I was assuming debugging output would be valid. Debugging output is garbage. 

note
only a single window is used to present content on the screen (it is an example of a singleton in IOS) and the app delegate has access to it. 

note
have many debuger launch failures today

note
root view controller is not equal to the view controller that gets presented at launch.

note
storyboards confuse the issue of initialization and class construction.
The only storyboard element that gets an init is the root view controller.
All storyboard elements are visual representations of classes. They are templates. 

note
instantiateViewControllerWithIdentifier

q
Clearly saving sometimes works for some things.
It could be that:
saving works on all properties but only the first time I do it
saving works only on some properties but does so every time I call saveContext()

I want to look at the x,y positions before and after manipulating the graph to help me decide which is true.

This failed of course because the problem is that the graph is always started in the same place.

note
Don’t assume what is given by apple will actually work. It might be something that worked at one time but the recent changes have broken it. 

note
the problem seems to be that hasChanges is false; I’m double checking that however

note
the problem is that the contexts are different. So I will set a point to see the call stack when this change happens.

the reason that multiple contexts were being created is that I was instantiating the thing in app delegate. It is easy to instantiate multiple copies of a class and then reference the wrong one. 

problem 
Sometimes it is not possible to close a running instance in xcode. 

note
start treating the build button like a resouce. Hit it less. Sometimes swift compile is reasonable but it can be deathly slow i.e. 1 minute for a minor change. 

note

added a breakpoint to test if no savedUsers are found

Saturday, 27 June 2015

June 2

q
need to understand initializers

issue
use of undeclared type UIViewController

q
where can I get a short list of the required initializers

note
whenever swift gives a weird error you should first go to the documentation

q
nothing happening on screen.
is barButtons getting hit ?

q
which of the view controllers init methods is getting triggered ?

task
with a runtime error need to find where the error took place.  First step is always an exception breakpoint

note
Whenever a runtime exception occurs the first step to solving it is to use an exception breakpoint.

q
In swift how to create a method that does not have named arguments ?

q
check if I can get ANY graph method to work
result
No. I created a method with nothing in it and it does not work. 

q
If I create a graph variable within testGraph does it run?

result
somehow the build target got changed

other interesting ways that this bug can occur are given here

june 21

issue
the send button is not dismissing the viewController

issue
  1. go to email
  2. press cancel 
  3. press delete draft
  4. go to email again
  5. press cancel

nothing happens. 

q
On the second cancel do we enter didFinishWithResult
ans
no

does setting the delegate to nil help?

note
testing if the delegate can be set to nil

note
what I really need is a way to send email automatically

note
title is objectiveC style so must be assigned before use. 

breakpoint and look at the title we are trying to assign

note
the notation for blocks as input is often (() -> Void)

bug
adding vert is not working 

changed startPos to restart and still not entering

note 
the scrollview has several subviews.
Have to send the buttons to be behind GraphWorld View or they block gesture recognition. 

note
remove verts not working

bug
UITextField cannot enter text

task
want the entity name to appear each time the attributeTable gets loaded

note
text is not being displayed after being set. Does it display at setup?

note
can’t deselect a cell after it is selected. 

note
check if the gesture recog blocks pans from occurring

bug 
"The working copy “CoreDataModeller” failed to commit files”
fatal: “WIll not add file alias MailGen.swift … mailGen.swift already exists in index

bug 
attributes are not given deterministically

refactor 
cells will contain the text of the default string for attributes. This is fetched by 

is UIKeyboardDidHide note entered?

issue
the keyboard is not dismissed.

q
is this a problem with note center ?

note
trying to find why verts have no attributes
set bpoint in testGraph()

note
instead of having a list of strings have a list of attribute objects.

so ditch attrStringsOrNil ?
yes.
it was silly to have it in the first place

ok, that will complicate some things. I will need a sort function that  can handle attributes. fine 

note
writing orNil at the end of a variable name is silly. It is easy to check if the variable is optional using alt. 

note
do I expect it to work as it is?
what have I done?
the observers have been added
the responses have been added
the array sorting is done 

tests
what I would like to test?
I want to make sure that the array can be sorted

cells are setting titles but not types. 

Future Tests

Check that the name of the .h file is the same as the name of the entity.

Sunday, 21 June 2015

june 20

q
What are the inits for UIPickerView

issue
email class was not working with an "unrecognized selector" message or something like that.
solution
check the import statements:
need to use import MessageUI

note
There are several things that need to be done in order to present a view controller programmatically. See apple docs. But the main step is

func presentViewController(_ viewControllerToPresent: UIViewController,
                  animated flag: Bool,
                completion completion: (() -> Void)?)

note
for some reason tried to use the following to convert a string to an NSData
NSData* dataFromString = [NSKeyedArchiver archivedDataWithRootObject: aString]

note

sending files by email sometimes does not occur < a minute as it should. Often it is much faster but the worst case time is a problem. Opening the mail app seems to force an update. 

Saturday, 20 June 2015

June 19

Five refactors to do
1
tapping. 
There is no need to have tap recognition in GraphWorldView.

2
get rid of all calls to pointInside() like this one:
(x as! UIView).pointInside(loc, withEvent: nil)

3
issue
my tap gestures are not getting recognized.
I turned off tap gesture recog on the the scroll view in its init
However, I may have left tap gesture recog turned on
Fond it. I am turning off all recognizers in moveMode()
What’s holding you back is rushing. Don’t assume.
4
remove gridBack from CoreController
5
add the buttons as a subview of the scrollView.
this could take 45 minutes
have 11 right now
last thing done: wrote a helper method

summary
Morning: I struggled with adding an image in the middle of another view. 
Afternoon: fixed the buttons so that they would be dispalyed on the scroll view. 
Took some time to understand that

  1. the problem was view order
  2. there was no way to fix this without reassigning a parent view of some other views. The methods sendSubviewToFront and sendSubviewToBack are weak tools, they only change the position of entries in the subviews array and trigger a redraw. If the given input view is not in the subviews array they will fail silently. 

Monday, 15 June 2015

june 14
task
set the image background of GraphView to be the grid

probably there is a property that says that images of UIScrollView must scale to fit. 

q
do we enter the double loop in drawGraph ?

q
does the context provided deleted objects just for convenience or do we really need it ?

q
is getIntersectingVert running
a
yes

q
Are both the cases of hitting and not hitting being treated correctly?

issue
we are not having vert collisions

task

method to get current state

Wednesday, 10 June 2015

June 8 2015

Cannot invoke getVertViewById with an argument of type Int32
lazy may not be used on an already-lazy global

note
swift: dealloc is now deinit

“graph does not have a member named moveVertById”

Currently working on GraphExtension
4 errors in GraphExtension = 10 mins

fix moveVertById. 
a 3 argument method that is supposed to be called on graph.

note
it is safer to have 

note
do not expect the compiler to fare well when you try to do advanced things like adding two numbers within a method call

note
In objective C you can only ask an object “Is your class X?"
In swift you should be able to ask an object “what is your class?”
but I have never actually done this.

for some reason circSize and edgeSize are not CGFloats

8:30pm
currently working on VertView

note
when you see code you need to see it in tandem with the markers 

note 
what is the type of array.count

note 
With value types there is usually no good reason to use as!. 
Instead you instantiate one value from another. 

task 
modify moveVertById

note
working inside graphWorldView

note
You will never be harmed by making all data an optional variable.

task
check if drawEdges is getting trigged.
result
yes

task
check if X1<X2 is getting triggered
result
the error was that I was checking if v and w were in the same place rather than in different places

problem
only three of the four verts are being drawn

task
examine the breakpoint set after edgeFrame and see how many times it gets hit
1

fact
when an observation of a vert is made the finishedObservedMethodFlag has been set on that vert. 

fact
Four observations are made for the test graph. There are 3 ways that the method could fail to work. The keyPath could be wrong. The graphView could be nil. The views of the vert might not be fresh. 

fact
all the verts have working key value observers. 

task
remove the print statements that are being used.
results
the print statements are not in GraphWorldView

issue 
edge view is nil in drawEdges2

task 
add logic to prevent edgeViews being set as not fresh if there are no edges in the vert.
This will happen in Edge cat.

done
there is now a breakpoint right after the edgeView call. 
There is one within the edgeView as well but within the loop.
If we don’t get to this breakpoint I can be certain that’s where the problem is. 

note
there is no good reason for using auto-unwrapping. 

note
after removing auto unwrap from e I have not solved the problem.
I am point inside of the else block

done
removed setNeedsDisplay on addVertAtPoint

note
in some more advanced swift frameworks the type used in objective C will be different. Often you pass in a string instead of just the name

note
think the problem is 
(1) EdgesViews being drawn after VertViews so 

(2) that I was not pushing the view back in the 

Tuesday, 26 May 2015

May 26 Lecture

Step 1
Get a certificate that has push notifications on apple.developer

Step 2 
Download p12 file

Step 3
Create a new provisioning profile

Ad Hoc is a type of developer profile.

However, choose iOS development

Step 4
Need to choose the corresponding AppID

Step 5
Download this profile

Step 6
Go to parse. In settings under Push Notification Settings turn on client push enabled.

Add the p12 file in parse

Step 7
Open a project with parse
Set the bundle identifier by looking at the profile created on the apple dev site
Usually com.something

Step 8
In the project settings set the code signing identifier

Step 9
Also set the team in general

Step 10
Set the parse id (Parse.setApplicationId()) to match what is on the parse page. 

Step 11
PFUser.enableRevocableSessionInBackground()

Step 12
var pushNotifications:UIUserNotificationSettings=UIUserNotifications(forTypes: .alert, categories:nil)
application.registerUserNotificationSettings(pushNotifications)
application.registerForRemoteNotifications()

Step 13
var push = PFPush()
push.setMessage(“Test push notification”)
push.sendPushInBackground()

### Facebook
Step 1
Facebook developer page
My Apps
Settings
Make sure that the Bundle 


Monday, 25 May 2015

May 25 Lecture

this week=tinder clone
push notifications, Facebook graph, geopoint, on may26

storyboards useful here

swift gesture recognizers
Selector(“wasDragged”)
for labels userInteractionEnabled is false by default. Have to set it to true

add func
func wasDragged() {
    print(“dragged")
}

wasDragged(gesture:UIPanGestureRecognizer)

summary
Two things taught
First, UIPanGestureRecognizer
Second, transforms
CGAffineTransform
CGAffineTransformMakeRotate
then there are 3 things
  1. apply the transform
  2. apply the inverse transform at the end

Friday, 22 May 2015

May 22 Lecture
mix and match

storyboards + spritekit + segues
can use SKviews in sprite kit
embed UIViews and modify them in UIViewControllers 

network calls
For example, can launch an analytics call inside a closure using SKAction.

note
drag container into storyboard creates an embed segue

to have a close button
work inside of prepareForSegue
minimize 

-chained animation
animations created with UIView.animateWithDuration can be chained by putting further animations into the completion block


why use a weak reference for the container outlet?

Thursday, 21 May 2015

May 21 
q
With sprites is there any way to have position be a corner rather than the midpoint

Reading about operators on NSHipster
Compound statements

q
How is the override statement used in swift ?

note
it seems like the only way that core should be changed is through key-value observing. 

q
does my core controller class start listening when the class is initiated ?

q
are protocols passed by inheritance

note
there are 2 ways that verts should be created. The first way is when we make verts for testing. In this case they are created by choosing a position. There are no animations.
The other case is when they are 

note 
when I am done with the setupVert I will need to check that drawGraph has been removed everywhere

bug
my buttons are not displaying
the method barButtons is getting hit

bug 
not able to change the model .
q
I am entering setDrawn somehow. 
there is a bug on drawn

#
debugging first questions. 
how often do we come to the point of the error
so this would mean walking over the error messages and printing drawnNum for each of them 

q
could it have something to do with the internet connection?

is setupVert used in the wrong place somewhere. 
Or there is a core controller setupVert and one inside the vert itself. Is the wrong method being called?

q
is this a race condition created by the current call to drawGraph in onNewGraph ? drawGraph tries to access the variable before core data has saved it. 

note
no. the bad call is originating in invalidate.

note
one issue with key value observing is that if you are observing several properties you will end up triggering many observation events. The problem with that is that observation events will be triggered before you have finished changing all the properties. 

I don’t know how to tell the view controller to wait until all the properties have been changed before responding.

q
I did not observing on all the properties so why is invalidate getting called so often … ?

issue
vert is no longer getting invalidated after a move

test
see if I am ever remove outdated views

q
why is drawEdges not getting called at the right time ?

#
The main problem I have with key value observing is that often you want to observe the completion of methods rather than changes in values. What do you do in this case? 

METHOD 1 Just add a property 
didFinishObservableMethod in the class. Observe this property. At the end of every observable method we should set this property to be true. 
This kind of fucks you if your goal is to work with core data because you need to rebuild the model once again.

METHOD 2 TOUCHING
A brutal hack that achieves the same goal is just adding observedVal=observedVal at the end of every observed method. 
A problem with the brutal hack is that it does not work on class methods.
wrong idea about solution
You could add a class method touchObservedData to get around this. 
reason
Class methods can only call class methods. 

review question
Why does core data use @dynamic ?

#Data Model laundry list
Remember to change the parseObj

Idea
Class methods are simply an unwise idea. They exist only because of the following mantra “In OO everything is objects and so classes are objects”

q
Are we entering the neighboursDrawn method ?

Task 1
Get verts drawing
Task 2
Get edges drawing

#
What happens to my invalidation code?
Shouldn’t it occur in vert

test
check if the newX and newY passed in are good
result
moveVertToX: toY is not getting called

bug
have a line v.self.vertViewId. I don’t know why this doesn’t generate a compiler error

bug
getVertViewById is always returning nil
v.vertViewId
the id 

note
NSNumbers are dangerous and horrible because of pointer assignment. 

vertViews are now getting assigned.
Now is getVertViewById getting anything ?

q
is the list of verts empty ?

q
is po working correctly?
a
yes. po does not work on NSNumbers. 

test
the problem could be with the vertViewId of v ?

result
vertViewIds are now working on core objects
question
vertViewIds working on views ?

question
is vertViewId getting set after the vert is allocated and init

question
is the vertView found by getVertViewById nil or not

question
back to basics. when is the key path getting matched

question
what is expected
When testGraph is being created all the vertViews found by getVertView will be nil. This will result in views being alloced. 
what is happening
The method is entered 8 times. 
vertView is nil 4 of those times. 
drawn is set to YES 4 of those times. probably wrong.

issue
moveVertToX is not getting called after a move
the problem could be that one of the args in drawGraphAfterMovingVert is nil

issue 
I am passing a nil vert into the graph method moveVertById

note
I am being reckless. I should always have been checking the bounds on arrays.

note
the compiler will not throw an error when you do shit like
NSNumber* id

cause
Creating an NSNumber with an incompatible type. I said the thing was an int when really it was a pointer. Boom
Some compiler warnings are lethal. 

task
Lets reduce the number of compiler warnings 

q
If we turn off setNeedsDisplay in initWithFrame will drawRect still be called ?

q
if we are never supposed to call drawRect then only the system is allowed to set the argument?
// or do we have control of a property to set this?

q
is the problem that fastEnumeration doesn’t actually do a check?

note
if you use a selector you can’t assume its synchronous so you can’t assume that the remainder of the method after the selector call is synchronous either

issue
method definition for touchObservedProperty not found

q
In IOS you can just redraw a view by changing its position 

note
unrecognized selectors at runtime are usually the result of not using enough code guards

cause
Creating an NSNumber with an incompatible type. I said the thing was an int when really it was a pointer. Boom. Some compiler warnings are lethal. 
cause
The only reason to use NSNumber is that it is an object and some of the nice tools Cocoa provides to us can only take objects as arguments. 
In theory use an object instead of a primitive should not be a problem. But having two different “forms” for numbers introduces a pair of possible pitfalls
  1. using a primitive where you should be using an NSNumber
  2. using an NSNumber where you should be using a primitive
terminal
"no next tag press return"


Sunday, 17 May 2015

May 16

bug
moveVertByIdAndDrawGraph - the moveVertById method is not working on self.graph
issue
You can only send objects in performSelector: withObject: .  To be more accurate you can only send variables of pointer type.
issue
The selector name is wrong. The compiler will give a warning for this but it will still run. 
note
Changing methods that are called in delegates in a lot of work. You have to change the method name in the implementation, the header, and the protocol definition. This would go faster if I could ever remember the command to switch between header and implementation. 
issue
Both the view controller method and the view method are out of date.
note
We have to set the viewId and pass the view id back
setting the view id occurs in the ViewController
passing the view id back occurs in the 

-(void)drawGraphAfterMovingVert:(int)viewId toXPos:(NSNumber*)endX toYPos:(NSNumber*)endY;
is this the right thing that I should be moving ?

note
in iOS there is no such thing as performSelector: withObject: withObject withObject: . two withObjects is the limit. 
question
is drawGraph getting hit after a move
answer
yes 

question
is removeSubviews getting hit
answer
removeSubviews is a graphWorldView method

issue
currently one of the breakpoints is just “setup”
goal
I want the graph cat to save. 
question
is the graph cat currently getting executed ?
answer
yes

it is sufficient to have parse save each of the verts
question: is the for loop in save in the Graph cat currently getting executed

bug and resolution: my save method in the PFVert class was not getting called because of a namespace collision.
style
Calls into my subclasses of PFObject should originate from PFVert

question
is blocking of saves of data that already exists in parse working ?

I can see from Parse that the Parse data model is not getting updated after I move a vert.
Question: is this happening because getVertById is returning nil ?
Answer: no. getVertById is returning a vert

note
When you write an NSLog statement it will always feel like you don’t need to write what method its in - after all its only going to be there for testing. 
goal
what I need is visibility into the number of Parse saves that get done. 
I can generalize this goal. 
note
Use __block variables to share storage.
bug
async issue
For some reason when I attempt to get the value of count I get out zero.
note
Apple's “debugging new in Xcode 6” from 2013 is way over my head.
day summary
I got changing the model to work.

GOT ASYNC PROBLEMS

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.