Entries in iphone development (4)

5:32PM

Closed Application Stores are a User's Best Friend

Recently, there has been a lot of rhetoric regarding the closed Apple App Store found on the iPhone and the (underwhelming) iPad

Some people say that a closed App Store is bad for developers, not giving them freedom, and furthermore, the users do not have the freedom to install what they want.  This is somewhat true -to develop apps natively on the iPhone you must use Objective-C (although there are alternatives out there, such as Appcelerator or Novell's Mono-Touch).  

However, some say that that a closed application store is good for developers and consumers, because they allow for the developer's publicity, and the consumer doesn't have to worry about nasty bugs or programs that steal information.

The point of a closed App store is looking at a computer as an appliance rather than a computer.  The appliance style of thought requires a set of activities that the computer is allowed to do, rather than allowing the user to understand these commands.

While this seems bad for the user and the developer, I do believe this is the computer will end up being an appliance.  I believe this is best for the user and the developer.

A closed application store (and thus the computer as an appliance) means that for the most part, the user is safe from installing bad software, and thus ties the developer's hands behind their back to prevent them from coming out with shoddy software.  In fact, I honestly believe that Apple should tighten their app store even more to prevent subpar or buggy software from coming in.  I do believe that some of their rejections are complete nightmarish though (such as blocking a dictionary app for having naughty language).  

In the end, the user is not only safe, but also saves time - no more researching on what applications are the king in the sea of subpar apps (for an example of this, take a look at the sea of CD Burning software that is available for Windows).  Furthermore, it just works.  There's no need to worry about installation (a process that really needs to die) or worry whether or not what you downloaded is actually a rogue antivirus. 

I also believe that this is good for developers.  Yes, it removes them from having complete freedom, but that can actually pay off.  It inspires creativity from solving the additional problem of not being able to access the file system, for instance, as well as inspires more education to make their applications up to snuff.  This would increase the quality of developers, and inspire more competition in the marketplace, especially regarding price.  Furthermore, the tools are right there. For instance, with the iPad, you need to use 

I am, however, not going to engage in the doublespeak that I've seen regarding how a closed app store actually gives developers or users more freedom.  It doesn't, but it does make users more secure, and it makes developers produce high quality apps (in a perfect universe).

For instance, I asked my father to go and download Microsoft Security Essentials on his new laptop.  He asked what it was, I said it was an antivirus.  He downloaded an antivirus, but it was the infamous Antivirus 2008.  Now when I go back home, I not only get to deal with that infection, but any other infection he picked up while not having an antivirus on.  What I should've said was go to Ninite and told him to download MSE there.  While Ninite is not an app store, it's a repository of apps that are chosen by the owners of the site, and probably the best compromise of what is out there - safe, reliable apps that are chosen to be there because they are of high quality.

1:15PM

How To Draw Two Strings Correctly With CGContextRef

When you are developing an iPhone application, and not even a string appears, that can be extremely frusterating.

So, here is how I ended up doing it. If there is a better way, please let me know at laneshill@gmail.com.

Let me begin with my problems, and some explanation.

What we wanted in our iPhone game is that we wanted a score to be displayed in the middle, and display bonus messages that pop up when a player scores.

We wanted to use have different alpha values for each string, and have each string be red - meaning, we can't use NSString's built in function, as that'll display it only in black.

My first attempt at coding this, the bonus messages would appear correct (albeit gigantic - a font with a size 2.0 would take up a good quarter of the screen), but the actual score itself would be upside down.

Usually, what would happen is that the actual score itself would usually be upside down, or wonky in some way, and the bonus messages would always be right side up.

However, after exploring documentation I came across a CGContextSetTextMatrix type which would be able to reverse the score text problem.

First time I tried it, it didn't work. However, if you move the declaration for CGAffineTransform (which is what you use with CGContextSetMatrix) and CGContextSetMatrix to before you select the font and set the colors and the drawing mode, it works.

So, our final code ends up looking like this:

Couple of problems though - for one thing, it looks like the font and color stays the same, although it's different.  As a result, bonus messages do not fade out gracefully.

So, in conclusion, if you're having trouble drawing two strings correctly and one is mirrored and the other is correct, use CGContextSetTextMatrix, and that should fix you up.

10:46AM

Hello, Biden: My First iPhone App

My post about geek culture is coming tomarrow.  

I'm going to let you in on my test iPhone application, called simply "Biden".  It's based off of a graphics demo I did for the Android, while mucking around with that SDK.  

As you can see, it's a pretty simple application - all it does is generate different blocks of 20x20 Joe Bidens.  There are three pictures used, and essentially an NSMutableArray of strings is created at run time and then is drawn.

There is no interactivity (although, perhaps in the future, I'll make a draggable "Giant Biden"), and the text at the bottom doesn't change.

I had two troubles in creating the application - the first one was that the NSMutableArray is created at run time when the View is created.  I realized that I had to implement initWithCoder in order to make it work out, instead of the default initWithNIBName. It makes sense, because the view doesn't have a corresponding XIB file. I'm still not sure what a coder is, but that's alright - it works.

The second problem was that I couldn't draw the Bidens and the string at the bottom at the same time.  I first tried using CGContexts to draw the string, but this didn't work out, so for this demo app, I simply used the basic string drawing technique.

I eventually figured out how to draw two strings at the same time with CGContexts, and I will write a post about that before the end of the day.

Note: This post is not meant to be an endorsement of any party or politician whatsoever.  Also, this application was simple - it was finished several weeks before, and it is literally my first iPhone application.

8:31AM

My Thoughts About iPhone Development Part 2: XCode

XCode is the worst first-party IDE I have ever used.  If Apple complains about Microsoft stealing from them, than maybe they should steal some concepts (ie most concepts) of Visual Studio into XCode.  

First, because I like to be a positive person, some positive things about XCode.  

First of all, it's intellisense feature is really good, although I'd prefer a drop down box.  It'll also give you (inline, too) all the arguments of the function you are typing.  Just click and type (I would prefer tab support for this, but whatever).  

It also makes it easy to get started - simply choose a project template, and if you make a new class, choose what your class's superclass.  Easy!  Simple!

And by the time you are ready to debug your program, this simplicity turns into complete and utter madness.  The way that XCode handles breakpoints and debugging is ridiculous and completely un-Apple, a company known for simple and easy design.  Breakpoints, simply don't stick half the time, and like to randomly stop working.  Breakpoints are COMPLEX in XCode, with different options for what to do with the breakpoint.  If I want to set a breakpoint in the first place, I just want to the code to stop so that I may see some variables.  That's it.  I don't want to log it and continue, I want it to STOP.  

The debugger in XCode is essentially a stock version of GDB.  This isn't so bad - GDB is actually can be fun to use, and can understand C commands.  It can't understand Objective-C command.  Finding out the string value of a NSString is practically impossible, and the frontend of the debugger doesn't help - it gives you memory locations!  If I was a robot, perhaps that'd help, but noooo, I'm not a robot, I want some human readable-ness, for Christ's sake.

In speaking of debugging, let's talk about errors.  XCode likes to hide warnings after building, even though you are staring right at one.  The errors themselves are very vague.  Have an "expected specifier list"?  You're missing an import somewhere.  How the hell do I know that?  From trial and error!  You then have to look at your code and look for that one little class you forgot to import.

Got an "expected ')' in class BlahBlahBlah'?  Then it could be either you missed a semicolon/brace in one of the files you imported, or it could be a cyclical import which is a problem that #import was supposed to resolve!  You can add a random @class declaration, and these problems go away!  Why!?  How the hell do I know!  

Even gcc can tell you that you are missing an import or a declaration, and it can even tell you what class it is (such as "blahblah not resolved").

Even worse, it counts the same error mulitple time.  Have a file with an error that's imported 8 times?  Well, that's 8 errors!

If there's a runtime error, the error you get can be different, even if it's the same problem.  The two common ones I've seen is _EXC_BAD_ACCESS (which is pretty much a seg fault), or _TERMINATED_DUE_TO_UNCAUGHT_EXCEPTION, which can be various different things.  Sometimes, gdb or XCode won't tell that your program crashed - sometimes, you have to click the REPORT button on the little "Your program crashed!" dialog box to get an exception.

Also, unlike Eclipse or most varieties of Visual Studio (except maybe Visual C++...I can't remember if it has this feature), you can't find out more information about errors.  Double click an error, you get nothing.  On these other IDEs, you can actuwally learn about possible causes for these errors.  With XCode, you have to search for it on the internet, and often get heresay and bad information (more info on that in part 3).

Like Apple's crown jewel, Objective-C, and unlike the rest of OSX, XCode is an inconsistent program in the term of opening a window in the program itself or out of the program.  Sometimes, you double click, and the code pops in the little code pane.  Sometimes it pops up in a new window, and then gets lost when you try to open a new code in a new window.  If you try to double click the new code, it'll either open it in the preview pane, or it opens it in an entirely new window!  Sometimes, there can be the same exact code in the XCode window and in a window right in front of it!  There's no easy to switch betwen an open window in XCode without using Expose, unlike many other OSX programs (like TextEdit, we like tabs, Apple!).

That's why I think XCode is a bad IDE, and why Apple should steal more features from Visual Studio products (especially Visual C#, the best IDE I have ever used).  If it wasn't for XCode's complete and utter waste of space as an IDE, I would probably appreciate iPhone development better.  But because if you want some semblence of an easy time developing for the iPhone, you have to use XCode.  I'd rather not develop for the iPhone for any personal projects, thank you very much.