Tuesday, December 29, 2009

iPhone dev Stupidity 116: How to find out what mach_msg_trap wait

from stackoverflow:


"Turn out my app is not actually spending 65% of it's time in the mach_msg_trap function. It was a configuration error in Instruments on my part.

The Sampler tool defaults to All Sample Counts, this will measure all threads regardless of their state.

Instead switch to Running Sample Times that will reflect the current actual workload."

Shark has similar options:


Wednesday, December 16, 2009

iPhone dev Stupidity 115: UITableView delete section

When items of a section are deleted, the section is deleted automatically - no need to write section delete code like:


[self.tableView deleteSections: [NSIndexSet indexSetWithIndex: section] withRowAnimation: UITableViewRowAnimationLeft];


Tuesday, December 15, 2009

iPhone dev Stupidity 114: Muliti column order

1. to order by two columns

From here

SELECT * FROM Individual
ORDER BY FirstName, LastName

2. We want to sort files by name - when two files have the same name we sort them by the date time:

NSString * sql = [NSString stringWithFormat: @"SELECT arts.*, tags.name FROM arts, tags WHERE category_id = %d and arts.tag_1 = tags.tag_id and ((tags.name = '%@' and arts.date_touched > '%@') or tags.name > '%@') ORDER BY tags.name LIMIT 1", cur_art.category_id_, cur_name, cur_art.date_touched_, cur_name];



iPhone dev Stupidity 113: Write protection of Resource

In the device, the resource/library folder is read-only. In the simulator, there's no protection for the folder.

Sunday, December 13, 2009

iPhone dev Stupidity 112: SQLite, Last inserted row id

From Widipedia:


Database designers that use a surrogate key as the primary key for every table will run into the occasional scenario where they need to automatically retrieve the database generated primary key from a SQL INSERT statement for use in another SQL statements. Most systems do not allow SQL INSERT statements to return row data. Therefore, it becomes necessary to implement a workaround in such scenarios.

Using a database-specific stored procedure that generates the surrogate key, performs the INSERT operation, and finally returns the generated key. For example, in Microsoft SQL Server, the key is retrieved via the SCOPE_IDENTITY() special function, while in SQLite the function is named last_insert_rowid().

Wednesday, December 09, 2009

iPhone dev Stupidty 111: SQL table order

From here:

"In a relational database... rows have no order! This cannot be stressed enough.  I don't care how you order the rows, SQL Server is under no obligation to return the data in that order.  And frankly, even if you order the data using the clustered techniques mentioned, this only guarantees it when you rebuild it.  After that, SQL Server may split pages, and then you technically don't have a flat structure anymore. "