Posts Tagged 'Programming'

Tip: NSDateFormatter Localization

So you’re checking out the Japanese localization on your latest project, and hey that’s odd — your NSDateFormatter that you set to [NSLocale currentLocale] is producing output rather unJapaneseish:

defaultlocale.png

Turns out, as described here on Stack Overflow, [NSLocale currentLocale] on a system with a Japanese calendar returns en_US@calendar=japanese even if the user language is set to Japanese. That seems like a rather strange and probably incorrect default behaviour, does it not?

The solution is to set it to the locale of the user’s preferred language,

[dateFormat setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:[[NSLocale preferredLanguages] objectAtIndex:0]] autorelease]];

which produces the rather more Japanese appearing

japaneselocale.png

So … apparently if you want your localizations to actually work as a local user is likely to expect, you should adopt that language-based locale creation scheme. Anybody have any clue why the default works that way and if this scheme actually is the best practice?

UPDATE:

And if you’re wondering why your NSDateFormatter date code breaks in iOS 5, why yes your NSLocale may be at fault there too:

… This is an intentional change in iOS 5. The issue is this: With the short formats as specified by z (=zzz) or v (=vvv), there can be a lot of ambiguity. For example, “ET” for Eastern Time” could apply to different time zones in many different regions. To improve formatting and parsing reliability, the short forms are only used in a locale if the “cu” (commonly used) flag is set for the locale. Otherwise, only the long forms are used (for both formatting and parsing). This is a change in open-source CLDR 2.0 / ICU 4.8, which is the basis for the ICU in iOS 5, which in turn is the basis of NSDateFormatter behavior…

Now you know!

Continue Reading →
1

AppKit Drawing

Good post over at Cocoa with Love on doing pretty drawing using AppKit:

iconapp.png

In this post, I’ll look at drawing a detailed image in code by combining multiple visual elements. Unlike previous posts I’ve done on drawing in Cocoa, this will focus on the AppKit classes. The code will use NSGraphicsContext, NSBezierPath, NSAffineTransform, NSGradient, NSGlyph and show you some simple ways to export the contents of an NSView to a file…

Most of it ought to be somewhat straightforward to adapt to Core Graphics on iOS as well, for when you want your interface to look just that shiny. Oooh, shiny!

Continue Reading →
0

cocos2d AI: Troll Boss

So you may recall that we’ve been reasonably impressed with The iPhone Game Kit as an introduction to game programming in general and the iPhone with cocos2d in particular, especially the community development project they started with their customers; seems that’s coming along nicely, and they wrote recently to give us a heads up on a piece they’re putting out there for everyone:

AI: What cocos2d Cannot Do

The iPhone Game Kit has always provided the basic framework for creating artificial intelligence. Since day one, we’ve been showing you how to make skeletons seek, attack, and even dance. Now we will show you a few more advanced tricks, like how an enemy can perform ranged attacks, special attacks, flee, teleport, and yes, burp out crazy windstorms which send the player spinning…

And of course they pretty much guaranteed a mention here by making the example a Big Troll.

Screen shot 2011-02-14 at 11.37.31 PM.png

Fear the mighty TROLL! ARRRR!

Any-ways, it’s a nice walkthrough of adding moods, special attacks, and so forth to your cocos2d actor objects, definitely worth a read through and considering more seriously picking up that iPhone Game Kit thing if you haven’t already!

Continue Reading →
0

Resource Checking: Cong

Here’s a handy tool for running over your OS X apps to look for resource issues — Cong:

What is Cong?

To check for leaks, you use leaks or Instruments. To check for obvious (or less obvious) bugs, you use gcc and LLVM options, or you use the Build and Analyze feature of Xcode. To check that your code works, you test it. But what do you use to check the resources of the bundle of your application? Say hello to Cong.

Checking what is obvious to stop being oblivious

Cong checks multiple points and details that can seem obvious but which are not always known by everyone. Your application may be running fine, may have won Awards and still be not perfect. For instance, did you know that there is a limited set of characters allowed for a bundle identifier and that ‘_’ (underscore) is not one of them? Did you know that the recommended encoding for .strings files is UTF-16? Did you know that the CFBundleGetInfoString key is deprecated for Info.plist files?

Looks handy, yep. So we ran it over our last OS X release, and …

Screen shot 2011-02-13 at 11.57.22 PM.png

… and so it actually is handy. Fancy that. OK, straight into our regular toolchest that one goes!

h/t: xcode-users!

Continue Reading →
1

RSS Parsing

So today we had a little trifle to knock off that features reading a blog feed and a Twitter feed … from accounts written to in Japanese. So rather than repurpose some of the XML parsing code we’ve used before for that kind of thing, especially since said code was written in an, ah, expedient fashion that required some knowledge of the feed’s contents, figured we’d look around a bit and see what we could find in a dedicated and reusable feed parser. And why yes, yes here is a very nice one indeed:

MWFeedParser — An RSS and Atom web feed parser for iOS

MWFeedParser is an Objective-C framework for downloading and parsing RSS (1. and 2.) and Atom web feeds. It is a very simple and clean implementation that reads the following information from a web feed:

Feed Information

  • Title
  • Link
  • Summary

Feed Items

  • Title
  • Link
  • Date (the date the item was published)
  • Updated date (the date the item was updated, if available)
  • Summary (brief description of item)
  • Content (detailed item content, if available)
  • Enclosures (i.e. podcasts, mp3, pdf, etc)
  • Identifier (an item’s guid/id)

Nicely done bit of work it is too. Very easy to integrate indeed, compiles cleanly, helpful example source for displaying feed and items, handles — as far as we can tell — Japanese text in both a Feedburner blog feed and a Twitter feed with perfect aplomb. Highly recommended as a start for your RSS parsing needs.

And hey, if you’d like more of a walkthrough on how to go about constructing your project, or rather than using the standard SDK networking and XML parsing classes you’d prefer something that uses ASIHTTPRequest and GDataXML, of course Ray Wenderlich has a tutorial for that!

How To Make A Simple RSS Reader iPhone App Tutorial

Continue Reading →
5

Tutorial: Chat App

Here’s a tutorial worth looking at if you’re as unfamiliar as we are — that’s “pretty darn unfamiliar indeed”, that is — with server programming:

Building an iPhone chat app from the ground up

In this article, work through the entire process of building an iPhone chat application from the server all the way to the user interface on the front end…

The iPhone side is all completely bog standard SDK you’re probably familiar with, so it’s a nice example of how a very little bit of PHP server code can be used to handle some realish-time communication needs with PHP and just a dash of SQL and XML. Nifty!

And if this is indeed something that would be handy for you, check out the author’s other articles while you’re there. Lots of XMLy and PHPy and so on webby goodness there, looks like.

h/t: ManiacDev via @rwenderlich!

Continue Reading →
2

Tip: Image Highlighting

So you want to have a highlight effect on an image like the one UIButton does? Hey, here’s a handy function to create a highlighted version of an arbitrary UIImage:

UIButton graphics highlighting

uibutton_highlight.png

… On the left, you’ll see an image that is similar to the icon for the Calendar program on the iPhone. Next is that same image, highlighted by UIButton. The third image is highlighted with the function shown below. The two highlighted versions are almost exactly the same. You can tell the difference with a color-dropper tool, but I doubt you could tell them apart with the naked eye…

Yep, that looks pretty darn close to the real thing. Handy little addition for your bag of tricks!

Continue Reading →
1

RESTKit

This looks like an interesting framework for your web-backed application development — RestKit:

RestKit is an Objective-C framework for iOS that aims to make interacting with RESTful web services simple, fast and fun. It combines a clean, simple HTTP request/response API with a powerful object mapping system that reduces the amount of code you need to write to get stuff done.

Specifically, that means

  • A simple, high level HTTP request / response system.
  • Core Data support.
  • Database Seeding.
  • Framework level support for switching servers & environments (development/production/staging).
  • An object mapping system.
  • Pluggable parsing layer.

Code is on github and there’s a tutorial here — looks like it’s well worth looking into for your next web-centered project!

h/t: @Dylan_Beadle!

… and ManiacDev just posted about it too.

UPDATE:

Continuing the above-mentioned tutorial: iOS SDK: Advanced RestKit Development

Continue Reading →
1

Cloud Syncing

So if you’re doing productivity applications, chances are that sooner or later you’re going to run into the question of how to sync your data files across multiple devices and/or platforms. A particularly good example of a category that finds that a compelling problem is task managers. Here’s a couple posts with worthwhile discourse on the subject:

To Sync or not to Sync

Discusses all the options the Today Todo people considered/observed others using:

  • Do it yourself – ie, Appigo’s Todo built on Moki Mobility.
  • MobileMe
  • Google Calendar
  • Google Docs
  • Evernote
  • File based sync – ie, Omnifocus syncs to MobileMe or a WebDAV folder
  • Dropbox

We’re inclined to think that the advantages of using Dropbox are reasonably compelling here, particularly if you’re resource constrained in your development.

Now, on the other hand, if you’re not particularly constrained by resources, take a read through Cultured Code’s (that’s the Things people) recent thoughts on the same topic:

State of Sync, Part II

… We were so intrigued that we decided to develop a sync solution based on Git’s core ideas. Since these were general ideas anyway, we decided to create a solution that isn’t tied to the specific properties or needs of Things. Instead we wanted to create a general framework that could be integrated with any application no matter what the specific data model or sync policies of this application were.

But we didn’t stop there. If you create something new, knowing that the technology will be needed on multiple platforms, it is worth thinking about a cross platform strategy. We ended up with detailed plans to create a JavaScript-based cross-platform data model framework with Git-inspired sync built in. This strategy required substantial portions of all versions of Things to be rewritten. It was clearly the most ambitious project we ever took on. Dissatisfied with our previous attempts, we didn’t want to settle with anything short of perfection…

Indeed. Well, we certainly encourage people whose tools we rely on ourselves to take that admirable approach. Around here though, “pretty darned good given the time and money constraints” is pretty much the highest possible target, and using Dropbox for sync functionality looks like a good first order approximation to that in most circumstances.

Finally, some more worthwhile comments on the first post here,

Sync with cloud – Today ToDo

First point. Resist ALL temptation to host own service. This will invariably lead to an enormous amount of dissatisfaction with the app itself as even the slightest outage will globally affect the perception of the entire application … At least if using a third party service, the blame can be transferred…

Yes. Yes, indeed.

Continue Reading →
2

License Scripting

Continuing our recent theme of pulling together Xcode scripting-related notes in preparation for that Xcode 4 upgrade soon, here’s a handy little Ruby script you might wish to take a look at for tips:

An Xcode 3 script which will insert a New BSD License comment at the head of a file. Place the caret at the top of your file (or select an existing header comment) and run the script via the Xcode script menu…

As usual, if you have any comments on changes needed to work with Xcode 4, please let us know!

Continue Reading →
1
Page 40 of 90 «...1020303839404142...»