April 13th, 2009 Rusty
To make a custom View appear following a button click, I was trying to animate the appearance of a UIView using the following code.
CGRect tempFrame = portfolioAddView.frame; // Get the current frame.
tempFrame.size.height = 0.0f; // Hide the view by collapsing height
portfolioAddView.frame = tempFrame; // set the new frame
[UIView beginAnimations:nil context: @”some-identifier-used-by-a-delegate-if-set” ]; // Tell UIView we’re ready to start animations.
[UIView setAnimationDelegate: self ]; // Set the delegate (Only needed if you need to use the animationDid… selectors)
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut ];
[UIView setAnimationDuration: 0.4f ]; // Set the duration to 4/10ths of a second.
tempFrame = portfolioAddView.frame; // Get the current frame.
tempFrame.size.height = 120.0f; // open up the height
portfolioAddView.frame = tempFrame; // set the new frame
[UIView commitAnimations]; // Animate!
It worked fine for showing the view but when I tried the reverse, animate the height collapse, the child UIViews remained visible.
I found a property that solved that problem
[portfolioAddView setClipsToBounds:YES];
Now, when I animate the height to 0 (zero), the children are hidden by the collapsed view.
Posted in iPhone SDK | 1 Comment »
December 16th, 2008 Rusty
This is not intended to be any sort of platform war. I love what Apple has done to mobile and I hope Android can catch up. On a whim, I thought I’d browse some Android documentation to see what’s up on that side of the revolution
Performance Advice
It took me quite some time to get my hands around memory management on the iPhone. I finally got it but spent many long, long days staring at EXC_BAD_ACCESS messages in the debugger before I finally learned how to create zombies and back up in the stack to try to find the object that was deallocated prematurely or the caller who needed it. There’s quite a bit of proprietary convention to learn with cocoa on the iPhone. I read the memory management papers and purchased >$100 worth of programming in Obj C books to get through it.
Google just spells it out, how novel! Check out this Android Performance Tips page. I read it and thought, immediately, “why in the hell didn’t Apple just puplish something like this? Just spell it out. Tell your developers (yes, we are now your developers), “do this, don’t do that.” We’ll swallow the pill and do as we’re told. We want to get on to more important things.
What are the performance optimizations for iPhone?
A while back I read that caching things that you get from storage such as DB and Web is the key. I’m requesting JSON from web services, parsing into object graphs, and caching the data using a singleton pattern. There is one instance of the data graph and I load it when its needed, release it either when the app closes or when memory alerts are sent, and use it for all other queries. At some point I’ll probably need to keep subsets in memory but, for now, it works great. Today I completed setting up a relatively complicated hierarchical structure of data in objects with parent child relationships. I was very careful to only allocate on instance of any entity instance and reference that instance from wherever it was prudent. I was pretty liberal with my structure and references, assuming that pointers aren’t very expensive and there is no difference between looping through a bunch of flat arrays or traversing an object graph. Then I read the Google advice and it made me curious: is the iPhone similar? I tried to find a similar document on Apples developer site but all I found were guides on how to set up Instruments and measure memory. There was lots of self stroking for the awesome tools you were now going to have to learn. There were copious misspellings and grammar mistakes (do they even proof read?). I honestly think they were about to launch the sdk and someone said, “shite! We’re going to need some documentation!” Then another cat said, “nah, if they think they are worthy of being Apple developers, they’re going to have to figure it out on their own.”
Java vs Obj C
I think Apple made a great choice using their proprietary C extension language. Java is far too heavy for what its been purposed for. I think the article makes valid points but necessity will soon require an advancement in speed and power on mobile devices, just to keep up with iPhone.
Ferrari or Chevy
Programming in Obj C is like owning a Ferrari. You can’t fix it yourself, its very difficult/expensive to maintain, performance and capability out prioritize usability, accessibility and utility. On the other hand it butters your bread when you’ve got it firing on all cylinders. Java is like a chevy: parts are readily available, its easy to fix, all the engines are the same and well documented - but it weighs too much, guzzles resources and isn’t something you expect to impress the ladies.
Microsoft on the iPhone
Microsoft launches SeaDragon for the iPhone. Its nifty but not anything that I think I’ll use with regularity. What I did find interesting (relieving even), is the following: in describing the experience of developing for the iPhone, Tim Huckaby, CEO of solution provider InterKnowlogy, describes the programming interface for the iPhone as “nightmarish” compared to .Net,
I know someone will be pissed off about that statement but he’s right. I’m getting better at it but I still retun to Visual Studio with love in my heart. I even pimped my theme just because I enjoy using Visual Studio so damn much
Posted in iPhone SDK | 1 Comment »
December 11th, 2008 Rusty
Short, sweet, to the point
http://www.lemonteam.com/blog/2008/12/setting-up-subversion-15-on-xcode/
Follow the recipe there. XCode will now work just fine with Svn 1.5
Posted in Mac, iPhone SDK | No Comments »
November 22nd, 2008 Rusty
When I read Apple’s article, I found it to be completely invalid. This article is at least accurate. However, assumptions are made that you know what they hell they are talking about. This post helped me quite a bit to understand what that “.gdbinit” file is and how to fix my mistyped “echo ” >> .gdbinit”Moving on, then…If you are a ruby fan, Dr. Nic rocks the down under. I started with this but tried to organize my class directory structure and messed up compatibility. Additionally, I am learning ruby so this was stacking a learning curve on top of a learning curve which created some sort of twisted double helix inverted unto itself. So for the less skilled who want everything in a single esoteric language (Obj c), XCode ships with OCUnit. Unfortunately, setting it up is similar in complexity to cloning hairless cats in the presence of a pitbull so there is a nice helper project from, who else, google.I had a couple of confusing points (more than usual) so I will share for other noob’s benefit.read wiki tutorial: iPhoneUnitTesting Where the HELL is the build log?
Successful… Wonderful. WTF is the build log? Click on the word “Successful” down thar at the bottom of the project window and you’ll get
Hmm, still no “build log”…Hey! That bar between the Editor and the Overview has some buttons. Start mashing those maybe?
There’s our huckleberry!Now you see this:
And there’s the line I was looking for: Executed 0 tests, with 0 failures (0 unexpected) in 0.001 (0.001) secondsTwice, no less!Awesome… Two days lost trying to set up testing but that will be earned back ten fold as this app moves from learning experience with relatively exciting product to truly engaging, innovative exploitation of revolutionary technology�
Tags: OCUnit, XCode
Posted in iPhone SDK | 1 Comment »
October 29th, 2008 Rusty
I’ve certainly done my share of complaining while I developed an application for the iPhone. I can honestly say that I’ve come from completely lost to comfortable on the platform and gained valuable skills and insight during the process. It was not easy. I am fortunate that my company is founded on the ideal of bringing technology into finance to produce valuable tools and the iPhone is an obvious vehicle for that.
Apple Support was Awesome
Credit where credit is due, right? While resources were difficult to find and the NDA made things very complicated, when I contact Apple with questions or issues, they always responded and helped me get through my roadblocks. I had a few problems with the App Signing process and exchanged several emails with Apple support. The responses were thorough and thoughtful. In the end, these very complicated requirements were overcome and I was able to focus on development.
The Submission Process was a Breeze
Relatively speaking, submitting the completed release was pretty straight forward. Of course, I’d learned the Apple way by then and knew where to look for the guidance I needed. The only thing that was confusing was the SWIFT code for our bank. This is simply an international standard for identifying a financial institution and you can usually find it by checking out your banks website. We also called our bank and they were able to confirm the code.
Review was FAST
I don’t want to set any unrealistic expectations for anyone but let me just say that review and approval of my app could not have been faster. I’m sure it helped that our app was well tested and had a clear purpose. We also followed Apples UI guidelines carefully and tried to make it as natural to the iPhone as possible. Needless to say, you can now purchase "StockRazor by Ockham Research"
Posted in iPhone, iPhone SDK | No Comments »
October 21st, 2008 Rusty
Short and to the point. Either start your application by carefully designing for rotation, or don’t rotate. If you use a UITabBarController, each UIViewController that is associated with a tab will be asked shouldAutorotateToInterfaceOrientation. If any of them return “NO”, then its no. Furthermore, it is next to impossible (as of this writing) to force orientation on a View when navigating from a different View that supports an alternate orientation. For example, if your list navigates to a detail page that supports landscape and then the user navigates up to your list that does not - too bad. To avoid hours and hours of pain and anguish trying to correct for rotation and resizing issues, I have two suggestions: 1) design and test constantly from the very beginning OR 2) Don’t rotate.
In My app, I wanted to show a different view entirely, from my detail view, when the phone was turned to landscape. That should have been really easy, or so I thought. My other Views were not auto-resizing according to the documentation, and no code I could come up with would cause layout to display correctly in all cases, so I was eventually forced to suppress navigation when the landscape view was shown. That should have been really easy, or so I thought. When I rotated with the navigation and tool bar present, everything was displaying perfectly. Unfortunately, navigating to another view resulted in failure to resize and reformat. If I hid the tab bar using hidesBottomBarWhenPushed, returning to portrait caused the view to just vanish. I easily wasted 40 hours on the whole of this problem.
My solution, in the end, was to use a modal view by calling [self presentModalViewController:myViewController animated:YES];. This way, the modal view is shown on top of navigation. I can dismiss this view and everything remains where it should be (actually, it rotates back, but correctly). Now I can display a landscape view without exposing other views to this orientation. Keep in mind that any view associated with a tab on the tab bar can cancel rotation. Therefore, I set a bool to indicate whether the view has focus in viewDidAppear and viewDidDisappear, respectively. Using this bool, I can return YES when not focused assuming the other views prevent navigation back to the view that doesn’t play ball in that aspect.
I am pleased to announce that my app is finally ready for submission and I think its useful and of very high quality. I am not, however, even remotely excited to build another. I am actually looking forward to taking a break from the iPhone platform. I’ll be grateful when Apple brings the sdk up a notch in its quality, consistency and usefulness. The device is completely ground-breaking and a marvel of engineering. The development platform is not
Posted in iPhone SDK | No Comments »
October 21st, 2008 Rusty
I searched quickly for this on Google but like most iPhone resources, nothing turned up. Â Eventually, I did find a place to change it. Â In fact, I found two places - both equally counter-intuitive.
In XCode…Â
You can either select Menu: Â Project > Edit Active Target “your app name”
Or you can right click (ctrl click) on the target beneath the “Targets” node in  your project tree and choose “get info”
From there, click the “build” tab. Â Scroll down to “Packaging”.
Change “Product Name”
Posted in iPhone SDK | No Comments »
October 14th, 2008 Rusty
Atlanta iPhone Developer MeetupMy second (the fourth?) Atlanta iPhone Developer meetup was a success tonight.  Forgive me for forgetting names, I’m getting old. We had an excellent presentation using xml web services to populate a UITableView with search results from Amazon linked to a UIWebView.  I liked how (Brian?)  walked step by step through how the code interacts with the Cocoa framework.  I think he stated it well that you play a game of “Whose in charge?” using View Controllers.  You set up some outlets and actions and then wait for the user to trigger an event that’s tied to an action that you defined.  Once that action is invoked, you have the ball.  ice analogy for IB.Where’s the Documentation? Several people asked me to post some links to a few things I mentioned while stroking my   showing off my app.  While I haven’t done anything profound, I have applied my experience in enterprise development to iPhone app development.  I feel the examples you find today are lacking in strong design fundamentals.  I suppose, in an effort to baseline simple concepts, Apple opted to present the flea’s eye view in order to demonstrate specific solutions to granular problems.  That’s fine but I still want to sprinkle a little awesome in my app.This Again? Common cross cutting concerns: data transfer, persistence, caching, authentication, remoting. OK.  We’ve been here before.  How do we sove these common and prevasive software problems?  One at a time.Data Persistence I have something that I want to save.  What are my options?  I could send it via a web service call to my server, where I have the code that manages such things. or I could store it locally.  I want both.  Locally, I have file system access and SQLite.  I like SQL.  That’s personal but I prefer to stuff text in a DB rather than to file.  I am a big fan of theRepository Pattern.  My repository is going to accomplish both for me.  When I say “load” it will first look for a local copy and then try to update from the server.  Same thing for saving.  Considering that I’m jumping across language and platform boundaries and need to refer to the same data constructs across these disparities, we need something consistent between them.  Xml works but its verbose and tedious.  SOAP killed the internet star so we’re going with JSON.Here’s JSON in a nutshell.If <person><name><first>rusty</first><last>zarse</last></name></person>Then {”person”:{ “name”:{ “first”:”rusty”,”last”:”zarse” } } } Why is this better?  Its shorter (no closing tag, let typing) and its more consistent (should “first” be an attribute or an element? aw bugger)Part of my inspiration for pursuing a JSON solution was my first experience with the iPhone Xml parser.  Its germane and, frankly, annoying.  Here’s how to install JSON for the iPhone. and here’s how to use JSON for the iPhone.Got it, Keep itNow that we’ve retrieved our JSON, let’s cache it to avoid unnecessary or impossible return trips to the server.  I LOVE SQL.  However, I have no desire to write object mapping SQL.  None.  Zero.  EntropyDB sounds nifty!  Note:  (big note) this version doe NOT INSTALL on the iPhone device.  Sorry for the shout but it caused me some lost time.  However, there is a device friendly build of EntropyDB  that does not work in the sim.  Its not in the files section of the Gogle code project and is near impossible to find.  Regardless, the library woks well enough to be worth the trouble of renaming the files to switch from simulator to device.   Entropy will serialize your object and save it to SQLite.  I a not enough of an expert to explain exactly how.  The fact that it’s meeting my business need without worrying out exactly how is testament to why its a valuable utility.  The Google project author indicates he intends to charge a license fee.  Pay it and don’t waste your time writing repetitive SQL unless that’s  fun stuff for you.What , no Code?I prefer code when I read tech blogs.  Sorry.  I’m lazy tonight.  I you would absolutely LOVE some code examples: comment or email me.  I’ll ablige.I’ll post more when I can…  Â
Posted in iPhone SDK | 1 Comment »
September 24th, 2008 Rusty
My brilliant tidbit of iPhone SDK advice today is to ignore the message that xCode gives you when compilation fails and just accept that something is messed up and now you need to put on your utility boots and start digging.
There aren’t very many different compiler error messages, so “syntax error before” should be read as “start here and work back”
My issue today was that I had a circular reference. The problem manifested itself as the above error message. The actual line where the build result console pointed me to had absolutely nothing to do with the problem.
How DID I find the problem? I started deleting s#&@. I started from the line that was listed in the compiler error. I’d delete that line, build. The “syntax error before” would go away but now I had an undeclared variable. I’d delete an #import. build. AFter going to lunch and proceeding with this approach for about two hours, I deleted an #import in a file three imports away and 80 errors suddenly popped up. Yep every single one of them “syntax error before”.
The solution was simple but not very exciting. leave the #import in the “.m” file unless it is part of the interface.
So there is my second tidbit today: don’t #import anything into you “.h” that your “.h” don’t need.
Posted in iPhone SDK | No Comments »
September 14th, 2008 Rusty
On this one, I’ll be short and sweet. Read Apples memory management paper.
Objective C memory management, simplified - or - head, meet wall. repeat.
Here are the golden rules that I’ve discovered to overcome the EXC_BAD_ACCESS monster.
- When you create a pointer, its just a pointer. for example: NSString *someString; There’s nothing there yet. When you assign value, you have a pointer to some allocated memory space. This is true in all programming languages, we just tend to forget as many modern languages abstract this away from us.
- If you reference something that you received from a method, don’t release it. for example:
NSArray* resultSet = [entropyRepository queryWithClass: classType];
I didn’t allocate or create that array, its not mine to release. When my pointer goes out of scope, it will decrement the reference count. Whoever created it is ultimately responsible for its release. It may be auto-released or the creator may have a dealloc method. However, if you release it, somewhere down the line, the originator may try to access it and you’ll get "EXC_BAD_ACCESS". Unfortunately, this error will occur sometime in the future, long after you’ve made your mistake. This was happening to me when the autorelease pool was being processed and I’d already released that array when I was done with it. Ooops. There went a week of "head, meet wall. repeat".
- If you use "alloc", you need to release the referenced memory. Basically, "alloc" is, "initialize this memory space for me." If you don’t release it, it’ll just sit there, forever and ever… You can opt to use autorelease or you can explicitly send a release message.
- In addition to alloc, methods used to get a reference that "create" an object using a method whose name begins with “alloc” or “new” or contains “copy” are yours to release. This rubs me as hack-a-logical as it leaves so much up to naming conventions. But, whatever…
Posted in Programming, iPhone SDK | 3 Comments »