Stack Overflow
Find Me
Tweets
Goodreads

Entries in XCode (2)

Wednesday
May022012

Quick Wipe of iOS Simulator Using Alfred

When I am rapidly prototyping new features, I frequently need to blow out the entire app structure from the simulator and start fresh.

To do this manually, I would follow the following steps.

From Simulator (when simulator is open)*:

  1. Go to Menu Bar
  2. Click iOS Simulator
  3. Click Reset Content and Settings

Benefits of this approach:

  • Easy to do/remember
  • Blows out all settings and apps

Drawbacks to this approach

  • Destroys ALL content, including any general settings
    • I frequently need to test something more complex, like uploading images. I will save images to the simulator by going to Safari on the simulator and saving images form the web for use in the simulator’s photo library. Using the Reset Content option destroys all of this data and it has to be recreated.

     

  • Simulator must already be running to reset settings

 

From Finder

  1. Go to path: ~/[user]/Library/Application\ Support/iPhone\ Simulator/[SDK Version]/Applications
  2. Delete all folders in the Applications folder

Benefits of this approach

  • Deletes apps from simulator without wiping settings

Drawbacks to this approach

  • Very manual, even when you have a sidebar shortcut set up in the Finder

My solution: Alfred Simulator Wipe

I love the application Alfred. Alfred is an extremely useful app that started its life as an application launcher, and has evolved into a swiss army knife that is ultimately customizable and expandable. When I get on any Mac and hit ⌘-space and see Spotlight instead of Alfred, I know my productivity will be less than normal. One of the best features of Alfred is the ability to create custom shell/Applescript extensions and run them from the app with a keyword (The devs just added the ability to pipe input into these scripts with v1.2, but I haven’t had a chance to play with it yet). This is the technique I used to automate the majority of this simulator wipe process (You have to have purchased the PowerPack to take advantage of extensions). Here is how to create an Alfred extension to wipe your Simulator applications:

  1. Download Alfred

  2. Open Alfred Preferences (with Alfred open, hit ⌘,)

  3. Click the ‘+’ button at the bottom left of the window:

  4. Select AppleScript

  5. Enter an Extension Name. Other details are optional

  6. To make it look nice in Alfred, you can drag in an icon that will be displayed in the app when the keyword is invoked

  7. Enter a title and description

  8. Pick a keyword that Alfred will use to launch the script

  9. Check the ‘background’ box (This allows the script to run and not block Alfred until it completes)

  10. Use the following code in the AppleScript field:

    tell application “Finder”
    delete (every item of folder “[Drive]:Users:[user]:Library:Application Support:iPhone Simulator:5.1:Applications”)
    end tell
    

     

  11. The iOS simulator uses a separate directory for each installed SDK. For each iOS SDK on your system (I have 3), add a new line to delete that Simulator’s installed apps. You would simply copy the delete line above and change [5.1] to a different folder name.

  12. Click the Save button when you’re done

  13. Invoke Alfred, then type in the keyword you set up to run the extension

  14. You should wind up with something like you see below

 

Alfred Screenshot

 

This will easily wipe out your simulator apps without destroying any data in the simulator itself. It’s also a lot easier than going through the Finder every time. I’m linking to an export of the extension below. Please let me know in the comments if you are doing anything similar or you can think of any improvements!

Alfred Simulator Wipe Extension

Thursday
Sep292011

Quick Xcode 4 Tip: Deleting Derived Data to Rescue Code Completion

Quick Tip:

I had an issue on a very large project in XCode. Starting 2 days ago, all of my syntax highlighting was completely broken. This is bad, but even worse, my code completion worked only partially. I was getting autocomplete for local variables only. When calling framework methods with a lot of parameters, I rely pretty heavily on code completion. I tried all of the usual fixes. This includes:

  1. Doing a Project Clean (⌘⇧K)
  2. Doing a Clean Build Folder (⌥⌘⇧K)
  3. Restarting XCode

None of these solutions fixed the issue. After some digging, I came across this StackOverflow Post which pointed me in the right direction. Seems like sometimes the project index, which contains metadata used to display code completion suggestions (among other things), can become corrupted. The solution is to delete it. This will force XCode to regenerate it, which rebuilds the index.

Here are the steps to delete your Derived Data folder.

  1. Go to XCode Settings (⌘,)

  2. Click the Locations tab. You will see a screen like this:

  3. Locations 1
  4. Click the small arrow next to the location of the Derived Data folder. This will open the Finder to the location of the Derived Data for any XCode projects you currently have on your Mac.

  5. Find the one that starts with the name of your current project and delete it.

  6. You should immediately see XCode start to re-index your project

For me, after this process completed, I got all of my functionality back. Your mileage may vary, and please make sure you back everything up before deleting anything!