Memory Leaks, Properties and Assignment

Posted by banane on August 18th, 2010 — in iphone dev

I’m working on a game that has a game board, that is relatively small array of 4-array objects; a “poor-man’s matrix”. This array, which changes, persists throughout the game view controller, so it’s a property, with the retain attribute. I got the game functional, but recognized a lot of memory leaks when setting up the array.
Given this header file:

  1. @property (nonatomic, retain) NSMutableArray *changingArray;

Basically, I was doing this:
Bad/Wrong way to do it

  1. -(void)someMethod{
  2.    myChangingArray = [[NSMutableArray alloc] initWithObjects: obj1, obj2, obj3, nil];
  3. }

Since I know you want to know, this is the right way to do it:

  1. -(void)someMethod{
  2.   NSMutableArray *tmpArray = [[NSMutableArray alloc] initWithObjects:obj1, obj2, obj3, nil];
  3.   self.changingArray = tmpArray;
  4.   [tmpMArray release];
  5. }

I have literally read these guidelines about 5 times, from Apple: Practical Memory Management I guess I didn’t really get it, because what sunk in for me was Erica Sadun’s The iPhone Developer’s Cookbook, p. 113 “… for normal (non-autorelease) objects, release the property after assigning it. ” That sounds so antithetical to what you want to do- keep a persistent object throughout the class. What it means is that you create a temporary object and once it’s got the right definition, assign it to the property. Because it is persistent, it already exists and you can’t initialize it. So instead, you create another object and copy it over. Most of the documentation and blog posts out there are about regular, easy to release quick and dirty variables, not retained properties. Hope this helps.

Share and Enjoy:
  • Digg
  • Facebook
  • del.icio.us
  • Google Bookmarks
  • StumbleUpon
  • TwitThis
  • YahooMyWeb

Biking to Pier 38

Posted by banane on August 9th, 2010 — in fitness, nostalgia, south bay

Ferry Building

Pull up pant leg, check lights, and generally warm up while biking on flat blocks near Powell, Mason, Chestnut, Francisco, untitil you need to go by the Post Office relay station, eying the 45 on the way to the MUNI depot. Merge quickly onto Bay St., battle Marina girls driving their Audis to the Bay Bridge. Right turn on Embarcadero. Stand on pedals as bike jitters over grate covers. Hunker down for 5 miles of blazing by parked cars. One scary moment whizzing past Market St. hoping pedestrians don’t try to jaywalk and step right in front of my bike. I cross 4 lanes and the MUNI tracks at Howard, to the Embarcadero footpath, largely empty now, and cruise a few blocks zig-zagging amongst joggers and walkers. Finally, pull up to PIer 38, the incubator space for venture funds. Remember to turn all my lights off.

I figured out halfway through the 5 week program at Women 2.0 StartupLabs that I could carve out some alone time at Peets on Ferry Building- and then rest my large au lait where the water bottle is supposed to be, with minimal spill.

Biking from Cupertino to Palo Alto in ’94 I managed a similar coffee rest: between my brake cables I could jam a latte to-go cup.

Why don’t bikes have cup holders?

And last anecdote: my fingers got seriously frosted biking home one night. They were huge and red and swolen. They hadn’t been that way in the dozen or so times skiing this winter or in the Ukraine in -20. So, verifiably, biking home in “summer” in SF is colder.

Share and Enjoy:
  • Digg
  • Facebook
  • del.icio.us
  • Google Bookmarks
  • StumbleUpon
  • TwitThis
  • YahooMyWeb

UITableViewCell AccessoryType Toggling

Posted by banane on August 9th, 2010 — in iphone dev

I recently battled with this feature: to create a toggling checkmark on a UITableViewCell, between two different cells. Here is the solution, in brief.

The tableview loads from an array that contains arrays- each array is a section. The one in question contains two values – the option values, @”A” and @”B”. We’ll call it optionArray.

We will create a dictionary that holds the user’s last selected values.
optionArray = [[NSArray alloc] initWithObjects:@”A”, @”B”,nil];
selectionDictionary = [[NSMutableDictionary alloc] initWithCapacity:1];
[selectionDictionary setObject:@"A" forKey:@"option1"];

I'm loading the tableview from an object called "sectionArray", which contains a single array, the optionArray. I also have an array called "secitonTitleArray", which just includes labels for the table. You probably are loading your table from Core Data or another data system. The way I'm doing it isn't recommended- it's simply for the example.

  1. sectionArray = [[NSArray alloc] initWithObjects:optionArray], [nil];
  2. sectionTitleArray = [[NSarray alloc] initWithObjects:@"Option1"];
  1. First, let's draw the table. In the "CellForRowAtIndexPath" method, check your datasource and add the checkmark in the valid (default or stored) value:
    1. NSString *selectedValueString =  [selectionDictionary objectForKey:@"option1"];
    2. cell.textLabel.text =selectedValueString;
  2. We'll use a simple if statement to determine if this is the user's stored, selected object, and draw the accessory type, if so. It's easier to compare numbers (vs. strings) so let's get the index of the selected string in the optionArray, and compare it to the one being drawn (indexpath.row)
    1. NSInteger selectionIndex = [optionArray  indexOfObject:selectedValueStr];
  3. So for @"A", since it is the first element in the array, that's 0. If we are drawing the A cell, this will qualify. Draw the accessory type:
    1. if( selectionIndex == indexPath.row ){
    2.                         cell.accessoryType = UITableViewCellAccessoryCheckmark;
    3.                 } else {
    4.                         cell.accessoryType = UITableViewCellAccessoryNone;
    5.                 }

OK, that's great for drawing the checkmark on the right cell. Let's do the interactive bit now- toggling from cell to cell based on the user's touch.

  1. In the tableview's delegate methods-- "didSelectRowAtIndexPath"-- you will various cases. Since this is interpreted each time, for each cell, we need to create various cases. Since we're managing comparisons more easily with integers, let's get the relevant indexpath.rows/indexes, of each object:
    1. NSInteger selectedValueIndex = [optionArray indexofObject:selectedValueString];
    2. // note, that is the index in the optionArray. There is another index - what the user has selected, that is passed as an argument in this method -  "indexPath.row".
    1. if selecting already selected cell, return, i.e. do nothing
      1. if (selectedValueIndex == indexPath.row) {
      2.         return;
      3. }
    2. Since we've passed this point, we know that what they've selected was the old selected cell. So indexpath.row is essentially not going to be the checked value ("new") in the end state of this routine. Sorry to berate this issue, but the use of "new and old" in most posted examples confused me. Old means, I believe, "was checked but won't be based on the user's interaction."
      1. NSIndexPath *oldIndexPath = [NSIndexPath indexPathForRow:selectedValueIndex inSection:indexPath.section];

      Remember the section- that was my problem for a bit. It is important when you're grabbing indexPaths from the aTableView array to tell it which sub-array (section) to look at.

    3. We've figured out which is the old and which is the new. So to continue, we need to create cell objects, so we can access the accessoryTypes (the checkmark).
      1. UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
      2.                 UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:oldIndexPath];
    4. Now, we are going to draw the carets to the cell. This is pretty clear - if it's checked, it's no longer checked. If it wasn't checked, it is now.
      1. if (newCell.accessoryType == UITableViewCellAccessoryNone) {
      2.                         newCell.accessoryType = UITableViewCellAccessoryCheckmark;
      3.                         [sectionArray setObject:newCell.textLabel.text forKey:@"option1"];
      4.                 }              
      5.                
      6.                 if (oldCell.accessoryType == UITableViewCellAccessoryCheckmark) {
      7.                         oldCell.accessoryType = UITableViewCellAccessoryNone;
      8.                 }
    5. You may have noticed an assignment above. In the "if-checked-switch-to-unchecked" if statement, we have updated our tableView's datasource with the user's choice. It's interesting that the UIKit's attributes don't inform the datasource.
    6. Not done yet! Add "[aTableView reloadData] to the ViewDidAppear and ViewDidLoad, to reflect the user's changes.
    Share and Enjoy:
    • Digg
    • Facebook
    • del.icio.us
    • Google Bookmarks
    • StumbleUpon
    • TwitThis
    • YahooMyWeb

Teaching Kids to Program

Posted by banane on June 22nd, 2010 — in technology

OK, I sat down my niece and nephew before bed, and we had a little period of Intro to Programming. It lasted about 15 minutes. Not their fault at all. I talked to my sister-the-educator about it later and she nodded knowingly. I wasn’t prepared. So I’ve written up the final-state program here. It’s a simple Ruby command line question that has a loop. My niece, who is 9, asked all the right questions. “What are you doing?” being the main one.

Note to self that VI is probably not the best tool, especially as its tiny and doesn’t use the mouse. When I opened BBEdit with all of its colors and bells and whistles, that got a smile.

This is the same niece that has helped me with Cootie Catcher and understands the concept of an iPhone emulator, so she’s already got a head start.

  1. puts "What is your name?"
  2. name = gets.chomp
  3. puts "Hello " + name + "\nYou are awesome\n"
  4. puts "Ask me a question."
  5.  
  6. question = gets.chomp
  7.  
  8. puts "You want me to answer: " + question + "?"
  9. response = gets.chomp
  10. response == "No" ? a= "Why not?" : a=  "Giraffe"
  11. puts a
  12. while(response == "No")
  13.   b = gets.chomp
  14.   puts b
  15.   response = gets.chomp
  16. end
Share and Enjoy:
  • Digg
  • Facebook
  • del.icio.us
  • Google Bookmarks
  • StumbleUpon
  • TwitThis
  • YahooMyWeb

Ephemera Demo

Posted by banane on June 20th, 2010 — in iphone dev

This is the live presentation of our iPad app, Ephemera, from hack/hackers event a month ago. Thanks so much to Rich for the filming and editing! It’s *so nice* to be able to listen to the judges without the panic of being onstage, I have to say. It’s kind of painful to see such a skeletal version of the app, but hey, you have to start somewhere.

More on Ephemera:
Pumping Up Ephemera
Ephemera iPad App

Share and Enjoy:
  • Digg
  • Facebook
  • del.icio.us
  • Google Bookmarks
  • StumbleUpon
  • TwitThis
  • YahooMyWeb

Pumping Up Ephemera

Posted by banane on June 14th, 2010 — in iphone dev

So doing some work lately on Ephemera- that’s the iPad app that consolidates local museum media on a Google Maps interface, so you can get a timeline view of your city.

What have I done?

- Created the timeline! Now you can scroll over time and view all of the media.

- Click over to the detail view of the pinpoint on the map- we didn’t have time to get that going before. It’s basically making a link in the annotation. The hard part, that kept hitching me up, is that the button has to either be the simple style, or the completely configured one, incuding image, which I didn’t have.

- Web data transfer, from a hosted Rails site. I setup the site on here, banane.com, and now my admin can curate the collection. When you launch your iPad app, it goes out and gets the new data on the server. This is a pretty rough cut and there’s some vital features missing… but it’s a frame upon which to build, so to speak.

Funny, getting the Rails server up took about 10 minutes. The NSXMLParser, to interpret the XML request, a few hours. That’ll get faster, but still.

More on Ephemera: Ephemera, the iPad App

Share and Enjoy:
  • Digg
  • Facebook
  • del.icio.us
  • Google Bookmarks
  • StumbleUpon
  • TwitThis
  • YahooMyWeb

Ephemera: iPad App

Posted by banane on May 24th, 2010 — in iphone dev

My project partner Stacy Bond (that’s Bond, Stacy Bond) and I built and presented our iPad app at Hack/Hackers Unite this weekend. Our project? “Ephemera” an overlay of the map of SF with local trivia/history.

The app locates you, and shows all of the annotations for local treasures around you. You can also click over to look at the treasures, instead of clicking on each ephemeron.* Using MapKit framework. We load it up with all of the trivia for SF (currently). Future developments may include a time-slider to view a location over time. Code is available at: http://code.google.com/p/secretcity/

Historical sources for the ephemera: SF Historical Society.

* Points for knowing the singular of ephemera!!

Share and Enjoy:
  • Digg
  • Facebook
  • del.icio.us
  • Google Bookmarks
  • StumbleUpon
  • TwitThis
  • YahooMyWeb

Hack/Hackers Unite: We Will Judge Your Play

Posted by banane on May 24th, 2010 — in feminism, technology

So I recently attended, at KQED, a “Hacks/Hackers Unite” project: get iPad developers and journalists together to tell a story. I struggled, pretty much entirely through the weekend, to be enthusiastic. I had to seriously rally the second day to attend. I’m not sure why it wasn’t as inspirational and energetic, focused, fun, etc. as the iPadDevCamp, She’s Geeky, shdh, RailsBridge, MySQL meetups, Ruby-SF, or the other myriad of tech conferences I attend. I’m a big fan of getting tech folks more involved with other aspects of our culture- from journalism, museums, education, politics, etc. – so I really wanted it to work. Here are some unstructured thoughts, and sorry if I offend you in advance. I’m trying to figure out what it was that didn’t work… so that I can promote it to some other great institutions that would benefit from some techie brainstorming in mobile apps. Also, since I was given a lot of unsolicited feedback (snap), I’m wondering if it’s just an OK thing to do in media circles?

First the Positive:
I liked the people that were there- I enjoyed the techies as well as the non-techies. The demos were (as usual) totally inspiring and fun. The creativity of inventors is always something amazing to behold. So not quite sure what wasn’t in the mix. I have a feeling it’s about the format and the organization.

- Really rich content for every demo. Usually at these things you see tools and utilities or “the next Twitter/FourSquare/Yelp.” Here, we got some amazing photographs and writing. Top caliber.
- Very diverse – very interesting people – really no stereotypes, and everyone had a very deep content hobby or interest
- I almost think, because everyone was such a great communicator, they expected everyone to be good at it, which we know with Geeks, that’s not true. So simple instructions and clear announcements were lacking.
- In SF!

Areas to Improve
The funny thing about un-conferences: the “un” in “conference” isn’t about lack of organization or structure- it’s about *who* is making the structure. The community, the group, or the individual, determines the importance and focus of the content. Basically let the participants focus entirely on their projects- and organize the hell out of everything so it’s not an issue with them. This weekend was more of a unstructured hackfest, with a scary judging panel at the end. It was almost the worst of both worlds- sometimes this works: Play! We will judge your play! And sometimes, notsomuch if there are too many odd hurdles in the way… floating deadlines, petri dishes, odd judging panels.. lack of conference focus… disorganization… and “they” will judge your play. Who are “they”? Why were “they” chosen?

In assessing areas to work on, it’s more helpful for me to focus on what works. Kaliya of She’s Geeky runs an AWESOME un-conference. The Raven and Dom of iPadDevCamp/iPhoneDevCamp have a stellar way of demo’ing apps – 3 stations and volunteers queuing up folks. Kaliya and Raven has a staff of about 3-5 people helping her organize it. I think that’s the irony – that it does take a lot of work. Yes, they are shoestring and run on a budget with tons of volunteers. They’ve been going on for years (this was KQED’s first) and the volunteers were organizers by nature and didn’t work on their own projects nor blog about the event while it was going on.

Maybe it’s something about how technology folks appreciate perhaps a non-chaotic setting whereas media folks work well in the self-named “bull pen”. Perhaps techies are a coddled lot who expect silence, ability to focus, their sugar/starch of choice on hand, and an appreciative clap on the back at the end of the day. I’m not sure. I just know I love it. My short list of feedback:

  • We had a single build environment which caused a lot of last-minute anxiety. Not only was the build engineer also competing, but it was poorly communicated and an odd/unusual/not-recommended way to deploy demos
  • Stay on top of the coffee situation
  • Clear the chairs out from under the project paper- so folks can dawdle and read and form groups
  • Clear chairs- clear areas to work- clear trash, etc. or announce to people to do that if it gets messy
  • Keep conversations at a minimum and away from working developers- including interviews, cameras, etc
  • There was some craziness regarding t-shirt giveaways, which usually aren’t that complicated.
  • Judge feedback- This is a tough one. Take care with your judging panel. More on this later.
  • Petri Dish- all content is not for free- privacy is a *big deal* to developers, and constant snapping of photos/liveblogging/twittering during a dev camp, esp. by a high profile broadcaster may not be appreciated- in the least ask permission and do it rarely (to developers) And in many, (she’sgeeky) not at all , or for some (iPhoneDevCamp) do at select times.
  • I learned, approximately 1/2 hour into it, that the “iPad” in the “hack/hackers unite” title of the conference, was for hype. Big fail. If you think that, fine, but telling a developer who is into the iPad, and devoted her weekend to it, that the whole thing could have been without the iPad?

I talked to some techies about why they came. We found out about it through the same software development list, had gone to some similar events and conferences together so I think I can generally state that they’re of my mindset. They were clear about avoiding journalists that simply wanted free developers. Also, they came because they wanted to break out of the tech-specific conferences that are so tool- and-next-big-thing oriented. The content is fun, and it’s so rich. There was an aura of desperation and bitterness, and while I understood it, it’s a bit naive to think that the technology sector hasn’t also been hit some blows recently- the recession, outsourcing, and also having to find “the next big thing”, or the countless start-ups that go bust, etc. It’s a scary topic for many non-technologists, and techies were there to meet them in the middle. And most non-tech folks I talked to were happy to learn and pick up, as well as contribute their skills.

I can’t tell you how many official-looking KQED folks walked up to me *while I was working* and not only asked for a demo but wanted to give me (unsolicited) feedback. Also, media folks who interrupted me talking to someone. Standing in front of me, or otherwise doing this rude conversational behavior. I can’t tell you how many times this happened, with different people. I met some very gracious and nice folks- Tim Olson head of Interactive, took me on a *very cool* tour of the soundstudios and server rooms of KQED. My project partner Stacy knew everyone- as well as famous NPR personality we ran into in the elevator, the technologist reporter Laura Sydell. (I logged it mentally as my brother-in-law has a game: how may NPR personalities have you met… and I will now outrank him.) The rudeness of the media folks made me think that we were simply filling a void, and weren’t unique in ourselves. That, along with the iPad slur, dampened my enthusiasm quite a bit.

Judging: I’ve setup judging panels before, and it’s very difficult, not just because you are dealing with Big Personalities, but also because you need to pick people whose opinions, the random geek attendant will respect. That’s why, in this kind of setup, I’d recommend peer-judging vs. “big personality” especially if there’s only 2 (of the tech field). They ended up having interesting feedback, but still, if I’d have known who they were I wouldn’t have come, because of the judging format, and the televised nature.

I’m writing this because I really want this to work in the future. So I’m sorry if I’ve offended folks, but I’d love for other organizations to tap into the richness of geekery in the SF Bay, and it can be done, well. KQED has forged ahead for us in this. They’ve broken the ice. I’m also fascinated with access to communities such as the rich iPad software development groups. Access, in terms of women and minorities and other marginalized populations. In talking to the organizers, they were shocked at the lack of diversity in tech events- oddly my project partner and I had met at She’s Geeky. There were no other female techs at this event, as far as I could survey. I am very interested in making communities like this- tech and journalist- more open to different kinds of people who will feel comfortable and accepted, so making it a hyped (but in a cool way),clear and easy, instructional format is key to this effort. Still, I won’t sugarcoat it, there were areas for improvement.

Share and Enjoy:
  • Digg
  • Facebook
  • del.icio.us
  • Google Bookmarks
  • StumbleUpon
  • TwitThis
  • YahooMyWeb

iPhone Projects

Posted by banane on May 20th, 2010 — in iphone dev

I have a few apps that are open source & the code is available:
CootieCatcher

http://code.google.com/p/cootiecatcher
Currently in store. This is a “teach girls to program” game, it’s a release. Using Core Data and some basic animation to create a fortune-telling game. I’m the only developer.

CootieCatcher

CootieCatcher

Le Bingueau
http://code.google.com/p/bingueau/
A bingo game to help you learn French (or any foreign language). I’m working with a French translator to provide a series of increasingly difficult dictionaries, levels, and various game boards, with animation as a reward. We’re probably 80% done on this. The upgrade plan is to introduce an iPad version for group play, and a server hosting personalized dictionaries (in other languages). I’m the only developer on this. This app is kind of complex: based on personal history, draw the game board to the level you’re at. Click a “deck” of English cards, then select the Frenchword on your game board. If you make a connection 5 down or across, and all the words are correct, move to the “win page” which has animation and analysis (for more word/vocabulary study). If you receive 3 perfect boards- no missed English words- then go up a level. If users select the wrong French word, tile is colored yellow and does not contribute to a winning pattern.

Le Bingueau

DicePad
http://code.google.com/p/ipad-gk-2010-dice/
Award-winner at iPadDevCamp 2010 for “Best New Developer”
This is a pair-programming project. My pair, Stacie Hibino, and I demo’d this for iPadDevCamp. It’s using GameKit networking. Two apps, one for server (iPad), one for client (iPhone)- detects bluetooth neighbors and waits for data from the devices. Devices, upon a substantial shake, randomize two dice objects and send the values to the iPad, where animation occurs and the two received data-dice are shown.

Notes on iPhone development- blog posts under the category, iPhone Dev.

Share and Enjoy:
  • Digg
  • Facebook
  • del.icio.us
  • Google Bookmarks
  • StumbleUpon
  • TwitThis
  • YahooMyWeb

Directory Issues with xCode Projects & SVN/Google Code

Posted by banane on May 6th, 2010 — in iphone dev, technology

I encountered this problem: getting an “already under source control” error when I tried to add my *.xcodeproj file to svn.

I was struggling with some issues after I renamed my iPhone project. I had done this before with another project. The file in question was my iPhone project file, “*.xcodeproj”. It appears as a file, but actually, it’s a directory! Everything became clear after that. In source control, within directories you will find a “.svn” file. This controls the presence of the file in the repository.

In command line, you can access the directory, and view the “.svn” file (or turn on hidden files in System Preferences, though you still can’t open the xcode file).

>svn status
? [my project].xcodeproj
>add *.codeproj
>svn: warning: ‘[my project].xcodeproj’ is already under version control
>cd [myproject].xcodeproj
>rm -rf *.svn
>cd ..
>svn add [my project].xcodeproj
A [my project].xcodeproj
A [my project].xcodeproj/me.mode1v3
A [my project].xcodeproj/me.pbxuser
A [my project].xcodeproj/project.pbxproj

I’m using Google Code- which I love more than GitHub- and otherwise have had no issue with the otherwise very straighforward environment. I haven’t set my properties in svn, and I haven’t really done anything that complex besides adding new classes to the repo.

Share and Enjoy:
  • Digg
  • Facebook
  • del.icio.us
  • Google Bookmarks
  • StumbleUpon
  • TwitThis
  • YahooMyWeb