Skip to content
Jun 7 10

Archiving data

by Rokan

Quick thoughts as to archiving data:
The best method seems to be saving to the /Caches/ directory of the iPhone application package. Then, to support the new Documents feature is easy – just move a file from /Caches/ to /Documents/ and the file is exported. As for importing, do the opposite, and effectively force a ‘restart’ of the application (by forcing all managers and singletons to reload their data).

The problem with this is the process of saving inside the program. Should it be done every time the stored data is modified? But then, what happens when the data is modified 100+ times per second? The application would attempt to encode the data, and write it to the device 100 times per second. The iPhone would simply crash in this situation (on the simulator it would even be slow! this is an extreme example). Another solution is to provide a superclass to data managing objects, which could control a batch-flow workspace. They could store a boolean as to whether the data should be saved each step or not. Then the saving would look like this:

Disable saving
Run loop - modify a bunch of data
Enable saving (this would also save the data)

By default, saving should be switched on. Personally, I’d name the methods something like as follows:

[dataObject beginBatchModifications];
for (unsigned i = 0; i < 100; i ++) {
    [dataObject removeObjectAtIndex:i];
}
[dataObject finishBatchModificationsAndSave];

This is not a perfect solution, but provides a neat code when finished.

May 29 10

UITableView reloadData not working!

by Rokan

For all of you people that are having this problem (as I was just experiencing) check a few things before submitting a bug report to Apple:

  • If you are using Interface Builder to set up your custom UITableView (without using a UITableViewController), then check that your IBOutlets are set up properly for UITableView’s properties: delegate and dataSource. If they are nil then your reloadData call will not work. Then again, your entire table won’t work, so it’s pretty clear if you haven’t set them.
  • If you have subclassed UITableViewController to run your custom processes and show your custom design, then make sure you have not set the tableView property. If you have, it will override UITableViewController’s original tableView property and will ruin your application (and will most likely crash it).
  • You must call reloadData on the main thread. This was my problem. If you are doing the sensible thing and downloading some data on a separate thread, and then passing it back through delegate methods or a notification center to your custom UITableViewController, make sure that you call reloadData back on the main thread. If you’re having trouble with this, use this or similar code:
[[self tableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];

Hopefully this cures some headaches.

Jan 10 10

iPhone OS: UITableView

by Rokan

Many people don’t understand how to use a UITableView, and that’s okay. In truth, a UITableView is one of the easiest parts of the iPhone OS API to use – you simply have to know the names of the functions, and have a good understanding of Objective C – particularly delegation, as that is the form of data input the UITableView uses. If you are unaware of what delegation is, you can look at Apple’s Documentation on delegation.

Creating a UITableView is easy. Mostly, UITableViews are inserted into UINavigationController’s, so we’ll do that too.

read more…

Aug 11 09

Verlet Physics

by Rokan

Ever wondered how games have that perfect movement effect where the objects bump into each other and flow perfectly? There is a lot to this effect, and today we’re going to learn about the basis of it: Verlet physics.

If you’ve ever wandered into the realms of game programming, you’ll probably have used a movement code much like this pseudocode:

position = position + velocity

So, in real code, it looks like this:

x += x_velocity;
y += y_velocity;

This type of movement is known as Euler movement. In this tutorial we’re going to learn about a new type of movement: Verlet.

Verlet works like this:

position = (position * 2) - position + acceleration

To see the difference, look at this example: the ball on the left uses verlet movement, and the one on the right uses euler movement. read more…

Aug 8 09

An Introduction to PHP Classes

by Rokan

About Object-Oriented Programming

Many programming languages are object-oriented. However, the method of defining an object varies from language to language. Some examples of object-oriented languages are:

  • Java
  • JavaScript
  • C++
  • and finally, PHP

Basic Class Programming in PHP

In PHP, an object is defined as this:
read more…

Aug 5 09

Repairing MySql Databases with PHP – Troubleshooting and Code

by Rokan

I’ve been playing around with the code from the previous tutorial (Is it possible to repair mysql databases with php?) and came up with a function that repairs a mysql database. I’m working on storing the database in an XML document, and importing it into PHP.

Here’s the code for the function ‘Troubleshoot()’ inside Database:
read more…

Aug 3 09

Is it possible to repair MySql Databases with PHP?

by Rokan

I am attempting to devise a method of storing the structure of a MySql database and it’s individual tables in PHP. So far, it looks a bit like this:

public static $STRUCTURE = Array(
	'members' => Array(
		Array(
			'field' => 'id',
			'type' => 'int(11)',
			'null' => 'not null',
			'extra' => 'auto_increment',
			'primary key' => ', PRIMARY KEY(id)',
			'suffix' => ','
		),
		Array(
			'field' => 'member_name',
			'type' => 'varchar(32)',
			'null' => 'not null',
			'suffix' => ','
		),
		Array(
			'field' => 'member_pass_hash',
			'type' => 'varchar(32)',
			'null' => 'not null'
		)
	)
);


read more…