What I Learnt Building 6 Real Estate iPhone Apps

I’ve built the following real estate related apps over the last few months. All of them are Singapore centric except for the rental yield calculator and the mortgage calculator.

  1. Progressive Payment CalculatorĀ 
  2. SG Stamp Duty Calculator
  3. Loan Affordability Calculator
  4. Property Tax Calculator
  5. Rental Yield Calculator
  6. Mortgage Calculator

Takeaways

  • When dealing with currency operations, just bite the bullet and use NSDecimalNumber. You’ll save yourself a lot of grief further down the road
  • Always try to use NSNumberFormatter for converting from NSNumber to NSString or the other way round. Don’t do things like self.label.text = @”$0.00″. Instead, do self.label.text = [self.formatter stringFromNumber:self.number] where self.formatter is a NSNumberFormatter property. Here’s how I instantiate my property.
    - (NSNumberFormatter *)formatter {
        if (!_formatter) {
            _formatter = [[NSNumberFormatter alloc] init];
            _formatter.numberStyle = NSNumberFormatterCurrencyStyle;
            _formatter.locale = [NSLocale currentLocale];
            _formatter.generatesDecimalNumbers = YES;
            [_formatter setLenient:YES];
        }
        return _formatter;
    }
  • If you’re dealing with percentages and you find yourself having to multiply/divide 100 at certain parts of your code, there’s a good chance you’re doing it wrong. Use NSNumberFormatterPercentStyle for NSNumberFormatter. Always work with the decimal form of your percent before formatting it for display at the final step.
  • Always test your app by changing the default region to another country which doesn’t have $ as it’s currency symbol. You can do so by going to Settings > General > International > Region Format. If you’re using NSNumberFormatter correctly, you should be safe.
  • Currency input sanitization can be annoying. Your sanitizer needs to handle the situations where
    • User input with currency symbol
    • User input without currency symbol

    as it was in my case. The initial input from the user doesn’t contain currency symbols. Once the formatter is applied and displayed, subsequent changes to the textfield will involve a currency symbol. It is probably worth noting that [self.formatter numberFromString:self.label.text] requires self.label.text to be in a format that contains the currency symbol otherwise it will return nil. This makes it annoying for the initial input where there isn’t a currency symbol and subsequent inputs where there is.
    My workaround for that is to enforce the currency symbol all the time. I use this little snippet to do so