Core Data part 3 – Add Data

DEMO PROJECT Given that, 1) You have your Data Stack set up 2) You have a model set up, and generated your model object which derives from NSManagedObject. Make sure your properties are @dynamic so that it uses the superclass’s synthesis (via NSManagedObject). Remember, if you do not use @dynamic, and instead use @synthesize, it […]

Core Data – adding a data model

create the xcdatamodelid file File >> New >> File Under iOS >> Core Data >> Data Model Select it and give it a name. Make sure you use this name in your core data stack’s code. This is so that it can load it into a MOM object successfully. Click on .xcdatamodeld file to see […]

Dynamic Typing

Dynamic typing enables the runtime to determine the type of an object at runtime. For example say we have this code:

This is a statically typed pointer. It declares that the variable myAtom is a pointer to an object of type Atom. With static typing, the compiler performs type checking, and thus detects type […]

SEL and method signatures

To summarize, the following are the key elements of Objective-C object messaging: Message: A name (the selector) and a set of parameters sent to an object/class. Method: An Objective-C class or instance method that has a specific declaration comprised of a name, input parameters, a return value, and the method signature (the data type(s) for […]

Custom TableView Cell

Create the TableView First, we create a tableView member variable in our ViewController

Second, we declare its property, and synthesize

Then in the viewDidLoad, we allocate for the tableView and add it to the view hierarchy.

Result: We now have an empty table. However, it doesn’t do anything because we need to […]

getting location of core data sqlite file

Then, copy it. Open up finder, and press command + shift + g. A location window will pop up and paste the copied path into it. Press enter, and you’ll see the .sqlite file

When to use delegate, blocks, or notifications Delegates should be used when there are multiple “events” to tell the delegate about and/or when the class needs to get data from the delegate. A good example is with UITableView. A block is best used when there is only one (or maybe two) event. A completion block (and maybe a failure block) are […]

ARC is not a garbage collector!

ref – There is no garbage collection with ARC, so there is nothing to call. If you control the scope and ownership of your objects, ARC will look after the memory use for you. Apart from assigning ‘nil’ to a reference or letting the reference go out of scope, the only other consideration is […]

Retain cycle with Blocks in iOS

references A Quick Gotcha About Blocks First, please read Block Basics But why do we use copy to keep the Block around? By default blocks are created on the stack. Meaning they only exist in the scope they have been created in. This is an optimization, since stack allocation is much cheaper than heap allocation. […]

Delegate retain cycle in iOS When a parent has a reference to a child object, you should use a strong reference. When a child has a reference to its parent object, you should use a weak reference or a unsafe_unretained one (if the former is not available). A typical scenario is when you deal with delegates. First, let’s set […]