Archive for 'Programming'

OPEventTracker

This is a handy addition to your bag of tricks:

Extremely Handy iOS UI Event Tracking Library (Perfect For The Performance Obsessed)

Anyone who has used an iOS device has experienced the frustration caused by a stuttering or pausing user interface.

While users may not notice these small hiccups on the desktop, it’s impossible to miss on the iPhone or iPad where the only thing on the screen is your app.

I’ve mentioned an excellent guide on multithreading with GCD so many of these situations can be avoided, but sometimes you need to do things in the main thread that could be disrupt the user’s experience.

Today I came across an open source library that tracks UI events which is perfect for those times…

Specifically, if you have any content that refreshes off the web, it would be nice to hold off while the user is actively interacting with it, wouldn’t it?

Honorable mention to an interesting pattern of packaging notifications we hadn’t encountered before:

extern const struct OPEventTrackerNotifications {
   __unsafe_unretained NSString *started;
   __unsafe_unretained NSString *stopped;
} OPEventTrackerNotifications;

const struct OPEventTrackerNotifications OPEventTrackerNotifications = {
   .started = @"OPEventTrackerNotificationStarted",
   .stopped = @"OPEventTrackerNotificationStopped",
};

That is rather more elegant than the long list of clumsy names scattered around the code we generally use, indeed.

Continue Reading →
0

Xcode Grab Bag

Here’s a collection of tips and tricks for dealing with The Xcode Experience™ as your project management needs get complex; we’re quoting some parts particularly novel to us, but all of these are worth reading thoroughly!

Managing Large iOS Projects

Non-code assets for static libraries

There are occasions when static libraries require assets, e.g., images and sound files. Sub-projects and projects in the same workspace share a build directory and Xcode manages the build order of each project so that the main target is always built last. Because of this we can add build phases to our main project and sub-project which copy static library assets into the main bundle…

Improve performance by moving run time operations to compile time

To improve performance move expensive operations from run time to build time and cache the result. This can be achieved by creating an OS X ‘Command Line Tool’ target that runs as part of the bundles build process. Core Data can be used to store the data created at build time (Core Data is cross platform so a Core Data store that is created on OS X can be read by iOS)…

Custom Build Phases and Scripts

So one bug, that I manage to repeat just about every project, is errors with the constants that reference resources. I get the names of PNG files, tags and identifiers wrong all the time. Or I change the name in the resource, even something simple like capitalization. Fortunately with enough testing these errors come to light. But I’ve also solved this problem before. And in a way that uses the compiler to test for some form of correctness. The simple solution is to create a process that preprocesses the resources and creates a source file with all the constants.

But how to drive the preprocess? Xcode custom build phases and custom build scripts are nearly ideal for this type of work…

Easy Xcode Static Library Subprojects and Submodules

In which a method is presented for reliably building static libraries with subprojects in Xcode, and it is suggested that this method, combined with Git submodules or other similar mechanisms, provides the best way to share libraries, frameworks, or other code between projects…

Avoiding duplicate symbol issues when using common utilities within a static library

…Use the preprocessor to rename the symbols automatically during the build phase. This is done by adding a series of -DOldSymbol=NewSymbol flags to the ‘Other C Flags’ build setting – like -DTPCircularBuffer=ABCircularBuffer, for instance…

How exactly does __attribute__((constructor)) work?

1. It’s run when a shared library is loaded, typically during program startup… NOTE: Although this syntax is specific to GCC, LLVM and Clang have been written to support it as well, and code compiled using Clang-LLVM seems to work just like GCC-compiled code.

Slim down your iOS app by excluding files from production builds

…You won’t find this feature in Apple’s documentation. But it does exist in the form of a user-defined build setting called EXCLUDED_SOURCE_FILE_NAMES and it’s a really handy feature. I’ll use TestFlight in this example but you can use this approach to exclude any files from a build…

Open Source Project Providing An API For Manipulating Xcode Projects

This project provides an API for editing Xcode projects. Through the API you can perform many different manipulations directly through code such as adding a file to a project, adding frameworks, and more…

And to finish up with one on working practices, for those of us still finding Xcode 4 gets in our way more often than Xcode 3 did:

How to make Xcode’s UI work for you (maybe)

(maybe) is a good way to put it, yes. But it is becoming less loathsome with some work setting up designated tabs, we’ll grant that much.

UPDATES:

Compiling Image Resources into a Static Library

OCLint: A static source code analysis tool for Objective-C and related languages

Continue Reading →
0

Review: Test-Driven iOS Development

So we imagine that if you’re reading this, chances are that you’re pretty confident in your programming skills and figure that the optimal development methodology is for people to stay out of your way. We understand. Spent better than two decades repeatedly proving so, in fact. But recently we’ve been shipping additions to a growing family of generally accoladed sports apps; and that has demonstrated to us nicely that the problem with that approach is that it scales past a single app … questionably. At the moment with nine teams in three sports things are still reasonably manageable, but that won’t last, if you get our drift. So we have been looking into things we can do to optimize the scaling process. Which, serendipitously, brings us to Graham Lee‘s new book:

We’d actually talked with Graham briefly after his TDD presentation at the Seattle VTM conference last year, where he’d just about convinced us that TDD might be something other than the development-slowing waste of time we’d previously observed it to be at places that applied it as a management-imposed afterthought, so we had fairly high expectations of the book; and why yes, yes indeed it would be an excellent book even if it wasn’t the one and only out there for iOS on the subject — matter of fact, we unconditionally recommend it to anyone who wants to be a better iOS programmer!

If you’ve already got the TDD religion from other platforms, you can jump directly to Chapter 4 “Tools For Testing”; those of us of a more skeptical bent will find reading through Chapters 1-3 an nice gentle progression through demonstrating the value of testing at all through to “How to Write a Unit Test” and how that leads to safely refactorable design.

Said Chapter 4 goes over the Xcode built-in support thoroughly and introduces GTM, GHUnit, CATCH, and OCMock on the coding side, plus Hudson/Jenkins and CruiseControl on the integration side. That covers anything you’re even remotely likely to encounter in existing projects.

Chapter 5 “Test-Driven Development of an iOS App” starts the 6 chapter process of developing BrowseOverflow, a StackOverflow question browser; full source available on github for everyone. Note that we say “process of” rather than “walkthrough of” developing; these aren’t 5 chapters of simple lecturing, at every step the analysis and alternatives are discussed thoroughly, with asides on design patterns, refactoring, and all kinds of good stuff, finishing up with Chapter 11 on general design principles derived from the process, thoroughly applicable even if you’re not using TDD at all.

Finishing up the book, Chapter 12 “Applying Test-Driven Development to an Existing Project” gives some straightforward advice on grafting testing into your ongoing development, and Chapter 13 “Beyond Today’s Test-Driven Development” surveys techniques not fully baked for iOS development yet.

Overall, we’d say that pretty much every — no, seriously, pretty much every — iOS programmer would solidly benefit from reading this book. Even if you’re already developing with solid test coverage, there’s almost certainly some insights here you’ll find useful. And if you’re in the position of most of us where you’re using tests half-heartedly and more likely not at all, you should put reading this to figure out just how this TDD thing could do you some good at the top of your list of self-improvement tasks. And if you’re new to development in general, why then this should be pretty much the next thing in your programming curriculum after design patterns!

Continue Reading →
0

Securing Data

If you’re at all concerned about security of data stored on your users’ devices, here’s a good introduction to

Securing Data in iOS

There are numerous ways to secure data that you are storing on an iOS device.

The simplest way is to take advantage of the iOS Data Protection (iOS 4+). This can be accomplished by setting an attribute on a file like this…

A Core Data sqlite store can also be encrypted by setting the NSFileProtectionKey file attribute to one of the above values (after you create your persistent store coordinator).

However, an important thing to realize is that this type of data protection requires the device to have a passcode set on it.

What if you really need to insure that your data is protected regardless of whether the device has a passcode set? One way is to use the CommonCrypto libraries from Apple. This can be fairly complex. There is a great write up here from Rob Napier on what’s involved. Fortunately, he has also provided a wrapper that greatly simplifies this process

One more way to protect your data, specifically data that you want to store in a SQLite database, would be to use SQLCipher. SQLCipher encrypts/decrypts data at the page level and is transparent to your application code. You still use the standard SQLite APIs, with one additional method call when accessing the database (passing your key to sqlite). There are excellent instructions on setting it up for use in an iOS project here.

Any other techniques for secure storage we should be aware of, Dear Readers?

h/t: @romainbriche!

UPDATE:

And speaking of security, check out this whitepaper: iOS Application Insecurity!

Continue Reading →
0

Scale Something

This is a good read in the “problems we’d love to have one day” category:

Scale Something: How Draw Something rode its rocket ship of growth

… A few days after Draw Something launched, we started to notice something…strange. The game was growing — on its own. And it was growing fast. On release day, it reached 30,000 downloads. About 10 days later, the rocket ship lifted off — downloads accelerated exponentially, soon topping a million…

Break out the champagne time? Not so fast:

… The smooth sailing was short lived. We quickly started seeing spikes and other really strange performance issues. At this point, we were pretty much working around the clock. Things got really bad around 1 a.m. one night, which is when we realized the main issue — our cloud data store was throwing errors on 90 percent of our requests. Shortly after, we received an email from our vendor telling us we were “too hot” and causing issues, so they would have to start rate limiting us.

At this point, the service was pretty much a black box to us, and we needed to gain more control. We were now receiving around 30 drawings per second, a huge number (at least to us at the time). So there we were, 1 a.m. and needing a completely new backend that can scale and handle our current traffic…

… At one point our growth was so huge that our players — millions of them — were doubling every day. It’s actually hard to wrap your head around the fact that if your usage doubles every day, that probably means your servers have to double every day too. Thankfully our systems were pretty automated, and we were bringing up tons of servers constantly. Eventually we were able to overshoot and catch up with growth by placing one order of around 100 servers. Even with this problem solved, we noticed bottlenecks elsewhere.

This had us on our toes and working 24 hours a day. I think at one point we were up for around 60-plus hours straight, never leaving the computer. We had to scale out web servers using DNS load balancing, we had to get multiple HAProxies, break tables off MySQL to their own databases, transparently shard tables, and more. This was all being done on demand, live, and usually in the middle of the night…

Heh. We lived through our own minor server capacity crisis a couple months back, and that was scary enough; but this, this is big boy stuff. Salutary reminder that it’s always good to be prepared for success!

h/t: iOS Dev Weekly!

Continue Reading →
0

TBHintView

This is a sweet-looking library for easily adding helper popups to your app:

touchbee / TBHintView

Screen Shot 2012-04-27 at 7.18.13 AM.png
  1. Easy to use
  2. Multiple page support
  3. Able to specify title text and icon per page
  4. Page can contain either text, one image or a custom view
  5. Various presentation animation types
  6. Hint can be docked to top or bottom within view
  7. Manually dismissed by user or auto-dismiss after certain period
  8. Background and text colors customizable
  9. Perform custom code within block upon hint dismissal

Certainly much more elegant than the alerts we usually use for that kind of thing!

h/t: ManiacDev!

Continue Reading →
0

Mobile Game Engines

Well, this looks like pretty much the veritably ultimate game engine selection resource — MobileGameEngines.com:

Screen Shot 2012-04-26 at 6.28.24 AM.png

Lets you search for selected features easily, and each entry has basic descriptions, collects links to books on the framework, and allows comments. 57 engines listed for iOS at the moment, covering pretty near each and every game engine that we’ve ever mentioned in passing around here (only recent omission we noticed is that Blackberry framework ManiacDev found) and a great deal more besides!

h/t: @gaminghorror!

Continue Reading →
2

SVPullToRefresh

This looks handy if you’d like to add pull-to-refresh to your lists easily, like one single line of code to add a refresh block:

samvermette / SVPullToRefresh

SVPullToRefresh allows you to easily add pull-to-refresh functionality to any UIScrollView subclass with only 1 line of code. Instead of depending on delegates and/or subclassing UIViewController, SVPullToRefresh extends UIScrollView with a addPullToRefreshWithActionHandler: method as well as a pullToRefreshView property….

And if you’re not as scaredy-cat of possible patent issues as the place that we’d really like to add pull-to-refresh to right now is, of course. But that’s another battle altogether…

h/t: @samvermette, ManiacDev!

Continue Reading →
0

100 Killer App Tools

Here’s a roundup of tools for the developer which’ll almost certainly have something new to you:

100 Tools to Develop the Next Killer iOS or Android App

  1. Random + Noteworthy Tools
  2. DIY (No Coding) App Creation Tools
  3. Development, Analytics and Management Platforms
  4. Mockup and UI Design Tools
  5. Mobile Ads + Monetization
  6. Test, Refine and Get Feedback
  7. App Promotion & Marketing
  8. Enhance App Functionality
  9. Other and Miscellaneous

Read the comments as well, more mentioned there too!

h/t: @Apptopia!

Continue Reading →
0

Image Optimization

So what with this new iPad and all, you notice that file sizes are a concern in your development? Yep, us too; but there’s some help out there we can glean from these case studies:

Tweetbot (an excellent, graphically-rich iOS Twitter client) weights 33.4MB, of which over 26MB is used for 978 images. It has all images compressed with Xcode, which converted them to “CgBi” format.

Here are results of converting images back to PNG and optimizing them with ImageOptim and ImageAlpha:

Screen Shot 2012-04-15 at 3.09.17 PM.png

That’s pretty impressive, isn’t it now? The tools used there are

ImageAlpha

ImageAlpha converts 24-bit PNG to paletted 8-bit with full alpha channel. This greately reduces file sizes with only minor loss of quality…

… Even images that need more than 256 colors can be made more compressible using special alpha-channel-aware posterizer.

ImageOptim

ImageOptim optimizes images — so they take up less disk space and load faster — by finding best compression parameters and by removing unnecessary comments and color profiles. It handles PNG, JPEG and GIF animations.

ImageOptim seamlessly integrates various optimisation tools: PNGOUT, AdvPNG, Pngcrush, extended OptiPNG, JpegOptim, jpegrescan, jpegtran, and Gifsicle

Note that you have to turn off Xcode’s built-in (de)optimization when using these, otherwise you’ll be rather confused as to why your binary isn’t any smaller.

Also don’t forget the transparent JPEGs masking trick we mentioned before, which might be more helpful depending on your images; for even more help with that, check out JPEGmini which general opinion seems to be have got some pretty nifty improvements on standard JPEG compressors!

h/t: @redglassesapps!

UPDATE:

Check out this Shoebox game graphics utility which includes a “JPGA Bitmap” tool to automatically produce JPEGs with masks!

Continue Reading →
1
Page 1 of 82 12345...»