Showing posts with label xcode. Show all posts
Showing posts with label xcode. Show all posts

Thursday, 28 August 2014

Really useful Xcode plugins

I'm a happy Xcode user, mainly using it for C++ programming. It's a relatively nice IDE (except for when I need to break out the big guns and fire up Vim for heavy lifting).

There are a few plugins that make it an even nicer IDE.

This is as much a note to myself as anyone else.

Backlight
One of the plugins that highlights the current cursor line. I have no idea why Xcode still doesn't do this by default.
https://github.com/limejelly/Backlight-for-XCode

Fuzzy Autocomplete
Makes autocomplete work on steroids, like the Open Quickly fuzzy matching. Nice.
https://github.com/FuzzyAutocomplete/FuzzyAutocompletePlugin

SCXcodeMiniMap
Puts a wee "mini map" beside your scrollbar. Can be useful if you write insane unnavigable source files. (Hint: aim for code that doesn't need it)
https://github.com/stefanceriu/SCXcodeMiniMap

BBUDebuggerTuckAway
Hides the debugger view as soon as you start typing into the editor. Handy. Saves a common keystroke.
https://github.com/neonichu/BBUDebuggerTuckAway

AdjustFontSize
Quite keyboard shortcut for adjust font sizes. Useful as I switch between a retina display and various monitor sizes depending on where I'm working.
https://github.com/zats/AdjustFontSize-Xcode-Plugin

BlockJump
CTRL-] and [ navigate up and down by block.
https://github.com/tyeen/BlockJump

Xcode4_beginning_of_line
Command + left arrow goes to the first non whitespace character, like any sane editor should.
https://github.com/insanehunter/XCode4_beginning_of_line

XAlign
One i'm just trying out. I find this kind of alignment can help reveal code intent, although it adds extra work to maintain. So let's make the computer do the work. Command-shift-X
https://github.com/qfish/XAlign

Saturday, 25 February 2012

Xcode 4 C++ class template updated

I've updated the C++ class template for Xcode 4. You may want to take the latest from github and re-run your installation scripts.

This version now:

  • Allows you to specify a class' (optional) superclass
  • Allows you to add a virtual destructor
  • Can make a new class non-copyable (with hidden copy constructor and assignment operator)
  • Has a sexy icon that matches all the other Xcode template icons.


Could life get any better?

Grab the update from Github here.

Thursday, 23 February 2012

Xcode 4: A C++ class template

Xcode 4 C++ users, rejoice!

It's really annoying that Xcode 4 has never shipped with a template for creating a new C++ class, with header and implementation file.

It lets you create objective C classes with header and implementation. But you always have to create a C++ header file in one step, and then the implementation in a second step.

And, honestly, why do those steps take so long to update the project?

It's not good enough, and so here's the answer...

The Xcode 4 C++ Class Template

I've created a super-simple to install C++ class template and installer.

Grab it on Github here.

Using it is a simple case of running a script and restarting Xcode. I've built in support for Xcode 4.2 and the new Xcode 4.3. The installer runs a number of sanity checks to make sure you're not about to install something dumb on your computer.

Full docs are in the README file up there.

I hope you find it useful. I know I do.

Making your life better, one class at a time...

Monday, 5 December 2011

Skip Lists: A C++ STL-style implementation

Recently someone mentioned an interesting container type to me, the skip list. It piqued my interest and so, naturally, I wanted to play around with it. It's been a while since I last wrote an STL-style container, so I thought I'd attempt to write an STL-compatible skip list implementation. Fun times.

And so I present to you my latest code offering, the C++ STL-style skip_list container. Grab it from the GitHub project here. Or read on for further information...


Skipping the list

The skip list is an interesting data structure. You could (simplistically) consider it a hybrid of a std::list and a std::set; it's a list-like data structure than provides good insertion, removal and search performance. As ever, the trick to good search speed is to trade off some memory to improve traversal performance.

Traditionally the skip list is an extension of a standard forwards-only linked list. Wikipedia has a pretty good page on the structure. Check it out if you want more gory details.

Atop a standard linked it, it maintains a set of higher-order linked lists that act as indexes into the main structure below. These provide faster access to the middle of the list. This provides efficiency on a par with a balanced binary tree (i.e. what a std::set is usually implemented in terms of). Insertion, removal and search operations are typically O(log N). Remember: a standard linked list (which you'd have to manually keep in order) would have all those operations take O(N).

The particularly interesting detail about the skip list implementation is the algorithm used to determine the allocation of nodes to higher-order lists. Rather than use a fixed balancing scheme, or inspecting the data as it's added and comparing against the existing structure, we assign nodes to levels probabilistically - always adding them to the main list, and then (with decreasing levels of probability) adding them to the high levels lists, too.


My implementation

I chose to implement a bi-directional skip list, so each node in my version retains a back-pointer to the previous node. This makes the list more useful in general, and ensures that it's a drop-in replacement for std::list.

Like std::set, my version takes a template Comparison functor (typically std::less) so you can tailor the ordering of data in your container. I also, naturally, support custom allocators, and provide all "the usual" STL container operations.

I have tested the code on:
  • Mac OS using Xcode 4.2
  • Windows usigin Visual Studio 2008
  • Linux using gcc 4.4
I have benchmarked the performance of my skip_list container. Because of the probabilistic nature of the container, sometimes it will perform better than other times when given random test data.

The memory consumption is almost exactly the same as std::set in general, and it tends to allow faster forwards and reverse iteration. Depending on the way the wind is blowing, large node insertion/removal operations can be dramatically faster (taking a little as 25% of the time of std::set for the same data) or a bit slower (I've seen up to ~110%).

The source archive contains my benchmarking code, so feel free to try it yourself.

The GitHub project for skip_list is https://github.com/petegoodliffe/skip_list.


Future plans

I have not yet provided C++11 "move" or initialiser_list operations, so that would be an interesting addition.

I could extend the data structure to provide O(log N) random access (e.g. indexing and random access iteration), too, at the expense of one more integer value in each node. That would be an interesting extension to consider - probably as a parallel variant of the existing container.


Future writings

If there's enough interest, I might start a new blog series on writing an STL-like container based on this implementation. There was a lot of interest in my previous series describing an STL-style circular buffer. Since this is a meatier data structure, the case study would be more useful.

Let me know if you'd like this!

Wednesday, 16 November 2011

Xcode 4 keyboard/mouse shortcuts

(I'm posting this here mostly so I don't lose it, although I'm sure it'll be useful to other Xcode 4 users out there.)

There are a couple of really handy Xcode mouse click modifier key combinations that I can never remember when I want them (kind of like a Super Street Fighter key combo).

In particular, you can click on symbols in the code editor and have them open in this editor, in the alt editor, in a new window, or... even... with a (ugly looking) popup asking you where to open (e.g. in a new tab).

Here's the lowdown:


Xcode 4 editor symbol clicks

Modifiers Click What happens
⌘⎇^ + single Open in alt editor
⌘⎇⇧ + single Select where to open (with popup)

+ single Open in this editor
+ double Open in this new editor window
+ single Show help popup
+ double Show help in organiser

⌘⎇⇧ Make alt editor counterpart again (super useful)

Key (what the silly symbols mean) 
Command (cmd)
Option (alt)
^ Control (ctrl)
Shift

Wednesday, 21 September 2011

iOS: Using older SDKs with newer Xcode versions

When you update Xcode versions, the installer automatically removes any old SDKs you have lying around, and replaces them with the latest version.

This is fine behaviour, as the most recent SDKs remain backwards compatible. You can set your project to target older iOS versions. If you do this, the newer SDK features are disabled for you.

However, there are times when you need to use an older SDK.

For example, I am running the latest Xcode with a beta iOS 5 SDK installed. Since this was originally installed on a clean machine, I didn't set the beta install to use a parallel directory and leave the "release version" of the developer tools intact - they simply weren't installed. (Making a parallel install is, in general, the best practice when installing a beta Xcode/SDK set).

Fear not. You can still get your newer Xcode to build with an older SDK, without downgrading your Xcode or making a parallel install:


  • Close any running Xcode instance you have open.
  • Locate the install DMG for an old version of Xcode (e.g. Xcode_3.2.5_and_ios_sdk_4.2_final.dmg, they name them so well) and open it.
  • Do not run the installer!
  • Open the Packages directory in that disk image. It is a hidden directory. Try this terminal incantation: "open /Volumes/Xcode\ and\ iOS\ SDK/Packages"
  • Locate the iPhoneOS and iPhoneSimulator SDKs for the version you want. Run just those pkg files. (e.g. I ran the iPhoneSDK4_2.pkg and it's matching iPhoneSimulatorSDK4_2.pkg)
  • Make sure you specify the /Developer directory as your install location. If you don't, the SDKs will be installed in your root directory, under the /Platforms directory; you'll have to manually copy them into /Developer/Platforms yourself.
  • Now, re-open Xcode. If the SDKs installed in the right locations, they will be selectable in your project now.


Friday, 22 July 2011

Xcode: Determining the current SDK version in a script

In an iOS XCode project, I needed a shell script target (aka "External Build Tool" target) that invokes other scripts which in turn build stuff using Xcode. Curiously recursive.

Now, I needed to pass that script the current iOS SDK version being used so it could arrange its own build malarkey, and get all its SDK ducks in a row.

There is no environment variable for that defined by Xcode. Bah. The closest you get is the current deployment target version, which appears in $IPHONEOS_DEPLOYMENT_TARGET.

That seems like rather a large omission.

You do get given $SDKROOT which is a file path to the current SDK. But that's not quite the same thing as a simple version number.

Never, fear, shell gibberish to the rescue. This is what I came up with:

SDK_VERSION=$(echo $SDKROOT | sed -e 's/.*iPhone\(OS\)*\(Simulator\)*\([0-9]*.[0-9]*\).sdk/\3/')

If you know a better way to do this, I'd love to know.