Archiving data
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.
UITableView reloadData not working!
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.
Login via MySQL
It seems not many people know how to do this, or they spend a long time figuring it out. I figured I might as well post it up for all to see.
This tutorial will teach you to set up a mysql table in a currently existing database, and use that mysql table to store usernames and passwords of your members. It will then show you how to verify that a user with a specific username and password exists.
This tutorial uses PHP, MySQL queries, and some HTML to achieve this.
Some important things to keep in mind are:
- The database never keeps track of an unencrypted member password.
- Members passwords must be case-sensitive, but usernames are optionally case-sensitive.
We will be storing the members’ passwords using the encryption method MD5. It is secure and easy to access in PHP.
So, first is to set up the table. I am presuming here that you already have a MySQL database set up. If you don’t, Google it.
read more…
iPhone OS: UITableView
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.
Verlet Physics
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…
An Introduction to PHP Classes
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…
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…
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…
