Monday, October 27, 2014

Why a single quote can crash your app

I don't know how many of you use NSPredicate, but you should. It's a great way to filter your data.
In one of my apps, I needed to use a predicate on a list of names that was previously saved to core data. 
It was a very simple section of code:

  NSString *predicateString = [NSString stringWithFormat:@"phoneName =='%@'",withPhoneNameString];
  NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateString];

  [fetchRequest setPredicate:predicate];



The issue was that when I scrolled thru the list, the app crashed.

It was not difficulte tracking down the problem - a single quote character (') at the end of the "withPhoneNameString" (this is something that some last names in Hebrew have).

When the predicate (@"phoneName =='%@'") is used , the single quote in the name takes the place of the string in the predicate definition. 

The solution was also quite simple:

 NSString *predicateString;
    
    //take out the ' char at the end of the name
    
    if ([[withPhoneNameString substringFromIndex:withPhoneNameString.length-1]       isEqualToString:@"'"]) { 

        NSString *newString = 
        [withPhoneNameString substringToIndex:[withPhoneNameString length] -1];

        predicateString = [NSString stringWithFormat:@"phoneName LIKE '%@*'",newString];

    }else{
        
        predicateString = [NSString stringWithFormat:@"phoneName =='%@'",withPhoneNameString];

   }
    
    NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateString];

    [fetchRequest setPredicate:predicate];





Thursday, June 5, 2014

The side of Swift you haven't heard

Like most Apple fans, I was following the WWDC 2014 keynote via Macrumors.
The first thing I did when I saw that Apple was changing the programming language used to write iOS applications, was Google "swift". 
I honestly can't remember if swift-lang.org was the first or second result, but I do remember that after an hour, when I ran Google search again, it was the last one in the first page. 

I also remember getting a comment from a friend on LinkedIn after I changed my title from HW engineer to iOS developer. Apparently he is a profit (he posted it a day before the keynote). 





Monday, March 24, 2014

Do I really need a Mac

As an iOS developer, the first question you will probably ask your self is:
"What do I need to write iOS applications?"


We'll, when the wonderful site appcoda says "Get a Mac" as the first step in the Pre-requisites, you get the feeling there is no way around it. 

However, a service called MacinCloud may be a solution. It was brought to my attention at the beginning of my iOS course. 
This site allows you to rent a Mac. It is great if you want to get a feel for OSX and how to use a Mac, and also for starting iOS development. 

I tried it out for a month at $20 (which gets you 3 hours daily use). 
Working with an online service can be frustrating (especially having to copy my files to Dropbox) but it was definitely worth it in order to understand that, if I am going to be serious about developing iOS applications, I need a Mac. 

Bottom line - Get a Mac. 


Saturday, March 22, 2014

In the beginning...

For the past 10 year I have been a board design engineer. 
Furthermore, for all my life (as I can remember), I have been interested in hardware (taking apart any broken electrical device, learning electronics in school and working as a battery technician in the IAF). 

Due to recent changes in the job market, I am starting a transition to iOS development.