views:

3185

answers:

9

Is there a straightforward way to clean up the directory where xcode deploys an app when building for the iPhone simulator? I have a sqlite database that gets copied into the Documents folder on startup if necessary. The problem is that I might change my schema, but the new database won't get copied, because one already exists.

Ideally, every time I build, it would nuke the previous contents. Is this possible, or do I have to manually do it?

Thanks.

tj

+9  A: 

The simulator installs apps to

/Users/<username>/Library/Application Support/iPhone Simulator/User/Applications

There are a bunch of GUID files and directories. They match up to the apps you have installed on your simulator.

You can manually delete all the files/directories in there (will remove all applications from your simulator)

I know there is some way to add scripts to the build process in XCode. Sadly I don't know how to do that. Hopefully somebody else can help with that.

Also it looks as if XCode changes the GUID it uses each build (the directory where my app sits changes between builds in XCode), so trying to delete the same directory all the time won't work. If you are only working on one app at a time then clearing out the entire directory would be an option.

Hope that helps.

chris.

PyjamaSam
A: 

Does the simulator support AppleScript?

Roger Nolan
A: 

Just checked. The simulator does not contain an Applescript Library, so no, the simulator does not support Applescript.

mmc
+3  A: 

I think you mean AppleScript dictionary, but the Simulator's lack of a dictionary shouldn't stop you from doing basic Core Event and UI scripting.

After turning on Enable Support for Assistive Devices in the Universal Access prefs pane, run this script:

activate application "iPhone Simulator"
tell application "System Events"
    click menu item "Home" of menu "Hardware" of menu bar of process "iPhone Simulator"
end tell

It doesn't look like you can actually click on the Simulator screen and drive iPhone apps, but you can do basic manipulations on the Simulator UI.

cdespinosa
+2  A: 

What you are really trying to do is to clear out your database, if you've changed the schema. One way to do this, and it would make you happier in the long run when you start shipping version 2.0, 3.0, etc. of your app, is to check the version of your sqlite table, and if it has changed, then discard the old file and use the one in your bundle.

Finding a way to clean up the Simulator won't help the real world problem of how to clean up a customer's iPhone when you ship a new version with a new schema.

For extra points, after determining that you have encountered an old schema, you may want to copy the new database over without destroying the old one, and load any interesting data out of the old database, into the new one. Then blow away the old database. That way you can preserve your user's additions to the database.

mahboudz
In general, I agree with you when you are talking about release upgrades, but in the midst of development of any particular version, this is far more overhead than is necessary. Database schema can change on a per-build basis, and needing to write conversion code for every build is just wrong.
Travis Jensen
+3  A: 

The way I do this is to simply click and hold on the icon for my app in the simulator--then when it starts to wiggle click the black and white (x). A message will pop up asking whether you really want to delete and you just click yes. The next time you build and deploy your app it will use the new sqlite db without a hitch and you don't have to go muck around in the filesystem.

quadelirus
This doesn't seem to work - it doesn't ACTUALLY delete data from the simulator?
Adam
My mistake - this works fine (confirmed by reading the directory in the accepted answer. I'd just forgotten Apple's user-unfriendly design of NSUserDefaults (unset values aren't reported by any sensible manner)
Adam
A: 

it may be overkill but..

you can also use the menu and 'Reset Content and Settings...'

ShoeLace
A: 

From Apples Dev Resources:

To set the user content and settings of the simulator to their factory state and remove the applications you have installed, choose iPhone Simulator > Reset Content and Settings.

Johe Green
A: 

How do you actually stop xcode doing this (using a new folder every time you run the app in the simulator)? I usually want my settings to persist from one run of the app to the next but almost every time xcode 3.2.4 forces me into a new folder hence my previous settings have been lost. Previous versions of xcode usually re-used the most recent folder so my app's settings persisted (and I say "usually" because sometimes it moved me to a new folder, but I could never detect a pattern that explained when it would or would not do this). Thanks.

jarmod