Archive for 2010

Custom Allocators

Here’s another of those digging into the runtime guts posts of Mike Ash’s worth reading:

Friday Q&A 2010-12-17: Custom Object Allocators in Objective-C

Finding your allocations too slow? Well, go write your own caching (or whatever) allocator then!

Another good reason to know how to do this, as pointed out in the comments, is if you’re working with crypto code (or any sensitive information, really) and it would be prudent to zero out memory after yourself when dealloced.

Continue Reading →
0

NSLogger

So everyone who’s done any Cocoa programming probably has an NSLog wrapper conditionally compiled on DEBUG for their development ease, but we seem to have seen quite a bit of gushing lately about this NSLogger project on github, so let’s take a look at the description and the Slideshare presentation here and see if it’s really all that, shall we?

NSLogger is a high perfomance logging utility which displays traces emitted by client applications running on Mac OS X or iOS (iPhone OS). It replaces your usual NSLog()-based traces and provides powerful additions like display filtering, image and binary logging, traces buffering, timing information, etc.

NSLogger feature summary:

  • View logs using the Mac OS X desktop viewer, accept connections from local network clients (using Bonjour) or remote clients connecting directly over the internet
  • Online (application running and connected to NSLogger) and offline (saved logs) log viewing
  • Buffer all traces in memory or in a file, send them over to viewer when a connection is acquired
  • Secure logging (connections use SSL by default)
  • Advanced log filtering options
  • Save viewer logs to share them and/or review them later
  • Export logs to text files
  • Open raw buffered traces files that you brought back from client applications not directly connected to the log viewer
  • You’ll find instructions for use in the NSLogger wiki.

Your application emits traces using the NSLogger trace APIs. The desktop viewer application (running on Mac OS X 10.6 or later) displays them.

Clients automatically find the logger application running on Mac OS X via Bonjour networking, and can optionally connect to a specific remote host/port. You have no setup to do: just start the logger on your Mac, launch your iOS or Mac OS X application then when your app emits traces, they will automatically show up in NSLogger if the viewer is running locally on your network. Until a logger is found, logs are buffered on the client so you don’t lose anything…

Oh-kay, that is indeed the Unquestioned Champion Of Hardcore Logging Frameworks that we’ve ever heard of, certainly. Particularly of note is logging images directly — we can think of more than a few times that would’ve been kinda handy — and these remote features, why we can think of many instances indeed these would have been wonderful:

  • Instrument your code to use a logger you instantiate on demand, in a release build. Combined with the ability to connect to the viewer remotely over the internet, this lets you distribute builds to testers or even customers, that have the capacity to connect directly to your viewer when running. One of the potential uses is live troubleshooting of issues in software running at remote locations.
  • Buffer logs to a file that you can later transmit to a server. The NSLogger desktop viewer can read this raw file (provided that is has the .rawnsloggerdata extension).

So yes, next time you have teh hardcore debugging needs, looks like this would be an excellent tool to pull out of your bag of tricks. Strikes us as just a little too much effort to go to without an obvious reason, so we’ll stick with our pretty basic DEBUG-conditionalized and not Objective-C dependent twlog() family of macros for the usually minimal logging needs we have … but next time we have one of Those Problems that just plain don’t appear on our test devices no matter how closely we follow the client instructions, yes out comes NSLogger to show us just what on earth is happening in the wild wacky client world, no doubt!

h/t: @holtwick, @openiphonedev!

Continue Reading →
3

State of the App Store

Here’s some interesting information for you:

The State of the iOS App Store [INFOGRAPHIC]

Splits up available apps by price, category, platform, etc.

Particularly intriguing was this data point:

“Number of unique developers: 62,126″

Presumably they mean “the number of developer accounts offering apps for download”. But how many is that, actually? Take us, for instance, personally we’re the only developer behind all the apps in one, two, three … twelve different accounts total it looks like. So if everyone was like us, there’s less than 5,200 actual iOS programmers out there. However, no doubt our ratio of 1/12th of a programmer per developer account — and counting!! — is on the unusual side. Probably a good number of those other 62,114 accounts have multiple programmers, in fact. So one does wonder what the actual number of active iOS programmers out there is. How about all of you? How many different client developer accounts are you responsible for?

h/t: @justinlbaker!

Continue Reading →
2

Illustrator Level Design

This is an interesting read for you:

How to use Illustrator, SVG, TouchXML and XPath for simple level design, meshes and other game data

… we wanted to try using Illustrator as a level/track design tool. Whilst we could’ve easily used Vertex Helper or similar for the Dwarf Derby project, Dead West has a complicated, layered set of co-ordinate-based game data (that Illustrator is well suited to managing).

The plan (and thus far successful execution) was this:

  1. Create nav mesh (just triangles for the purpose of this) in Adobe Illustrator
  2. Export from Illustrator to SVG
  3. Load that SVG in-game using TouchXML
  4. Build whatever data structures we need in memory by querying the XML/SVG document with XPath statements

This required some specific methods and tweaks, so I’ve brought those together below in a deliberately basic how-to…

It seems not completely dissimilar from the approach taken in the LevelSVG cocos2d project mentioned here, which as we mentioned in the BallZOut writeup uses Inkscape as its editor …

… in which case it would be nice to merge the two. Really nice. As Inkscape is … well, there are more painful programs to work with, but not very many. And Illustrator is not numbered amongst them!

Continue Reading →
1

iPod Library Sampling

So you want to play with audio from the user’s iPod library? You good with requiring 4.1 for your app? Then you should read

From iPod Library to PCM Samples in Far Fewer Steps Than Were Previously Necessary

iOS 4.1 added a number of new classes to AV Foundation (indeed, these were among the most significant 4.1 API diffs) to provide an API for sample-level access to media. The essential classes are AVAssetReader and AVAssetWriter. Using these, we can dramatically simplify and improve the iPod converter.

I have an example project, VTM_AViPodReader.zip (70 KB) …

The ‘previously necessary steps’, in case you’d missed those too, were

In a July blog entry, I showed a gruesome technique for getting raw PCM samples of audio from your iPod library, by means of an easily-overlooked metadata attribute in the Media Library framework, along with the export functionality of AV Foundation. The AV Foundation stuff was the gruesome part — with no direct means for sample-level access to the song “asset”, it required an intermedia export to .m4a, which was a lossy re-encode if the source was of a different format (like MP3), and then a subsequent conversion to PCM with Core Audio…

Yes, that’s quite the process so it is. Meriting that post’s title,

From iPhone Media Library to PCM Samples in Dozens of Confounding, Potentially Lossy Steps

indeed. But hey, if you absolutely have to support anything besides the latest and greatest, then you’ll need to know that too!

Continue Reading →
0

Tip: iOS Fonts

Would you like a handy reference for rendered images of all the currently available fonts on iPhone and iPad? Here you go then:

iOS Fonts – ‘A Place for Happy Typography’

h/t: @Dylan_Beadle!

Continue Reading →
3

AWS SDK for iOS

If you have any involvement with Amazon Web Services stuff, you’ll probably find this of interest:

New AWS SDKs for Mobile Development (Android and iOS)

The AWS SDK for Android and the AWS SDK for iOS provide developers with access to storage (Amazon S3), database (Amazon SimpleDB), and messaging facilities (Amazon SQS and Amazon SNS). Both SDKs are lean and mean to allow you to make the most of the limited memory found on a mobile device. The libraries take care of a number of low-level concerns such as authentication, retrying of requests, and error handling.

Both of the SDKs include libraries, full documentation and some sample code. Both of the libraries are available in source form on GitHub (iOS and Android) and we will be more than happy to accept external contributions.

In order to allow code running on the mobile device to make calls directly to AWS, we’ve also outlined a number of ways to store and protect the AWS credentials needed to make the calls in our new Credential Management in Mobile Applications document…

Haven’t done anything with AWS ourselves yet, but no doubt this will be handy if we ever do; if you do some work with this fun stuff, be sure to let us know how it goes for you!

h/t: @joe_carney!

Continue Reading →
1

Transparent Toolbars

Aaaaaand continuing on from yesterday’s ‘good reasons to use method swizzling’ theme, let’s say that you want to have a couple standard UIBarButtonItems beside each other in a navigation bar, like this:

buttonsintabinnav.png

Now, every time we’d done this before, we’d used custom buttons; just stick them in a view, set leftButtonsItem to use that custom view, done. Same way as the custom title view shown there. But you can’t put UIBarButtonItems in a view. Hmmm. Well, you can put them in a tab bar with a UIBarButtonSystemItemFixedSpace between them, and then use that tab bar as a custom view, right? Well, that might work if your navigation bar was opaque, but the Perceptive Reader will note that the navigation bar above is not opaque. And a UITabBar meshes with that … poorly. Hmmmm, hmmmm.

The solution is to be found here:

Making UIToolbar and UINavigationBar’s background totally transparent

I have an upcoming iPhone application, Cartographer, that is highly stylised and requires high customisation of the interface to achieve a convincing, beautiful vintage look. To make it work, I needed transparent toolbars and navigation bars for my UIViewController-based views.

The solution I came up with for this was to implement a category on UINavigationBar and UIToolbar, and overriding drawRect: with a method that does absolutely nothing. Then I can place my own textures behind the bar, and they’ll be seen, instead of the default bar background…

Ex-cellent. Now I feel really good about buying Cartographer to support this fine, fine fellow’s helpful blogging! (Haven’t launched it yet, mind you, project deadlines and the trip we’re planning to use it for are converging in an increasingly disturbing fashion…) And, as you can see from the screenshot, it works just a treat in your translucent navigation bars.

That article goes on to discuss adding textures using CALayer, and here’s another couple links on that subject as well, just to keep our bar customization stuff in one link:

How I add background image to UINavigationBar

Another CALayer Tip for Background Image

Note that second one is about adding background images into UIViewController, supporting both landscape and portrait mode no less!

Continue Reading →
0

Tip: Custom User Agent

So remember waaay back when we mentioned how to go about messing with the undocumented internals of UIWebView if you needed to call -setCustomUserAgent for some good reason? Well, we’ve always been mildly nervous about that approach … but now, here is a rather safer way to go about things:

UIWebView user-agent weirdness and how to change user-agent value programmatically

which uses the technique described here,

Changing the headers for UIWebKit HTTP requests

to do some swizzling of NSMutableURLRequest’s setValue:forHTTPHeaderField: method.

A rather massive replacement for a simple declaration of a hidden method yes … but just in case Apple ever starts getting persnickety about people actually using desktop-available calls on the guts of UIWebView, a massive replacement you would be very well advised indeed to adopt!

Continue Reading →
0

BNColor

Here’s an object with a handy set of extended capabilities from UIColor:

An upgrade from UIColor

This post introduces the BNColor class, a versatile color object that can be easily changed, saved to disk, and offers live switching between HSV and RGB color spaces – all features that are missing from the built-in UIColor class.

And hex/decimal/percent string accessors too. Beats writing it yourself!

Continue Reading →
0
Page 1 of 28 12345...»