Posts Tagged ‘xcode’

CentOS Git server and OS X Client

Screen Shot 2012 01 07 at 11.41.36 CentOS Git server and OS X Client

Why?

One of the things we needed to establish for Cistec App Development was some sort of remote version control. Up until now we’d been using the world renowned Dropbox for working on our projects but it had several issues (updated in realtime, so if you attempted to compile after a colleague made a typo..).

After some googling to decide between the two version control systems Xcode will integrate with (SVN and Git) we went with Git thanks to some strong opinions on StackOverflow.

Read more

Set decimal places from variable in Objective C

I recently needed to create a function that took an NSString as the input number and then another to specify the number of decimal places it was to be returned with and I thought I’d share. (in reality it expanded to also handle any multiplication and division I needed also).

It’s quite short but the awkwardness was in getting StringWithFormat to output what I needed.

+(NSString *) returnNumber:(NSString *)numberIn toDecimalPlaces:(NSString *)decimalPlaces
{
    // Assign the right number of decimal places:
    decimalPlaces = [NSString stringWithFormat:@"%%.%@f", decimalPlaces];
    NSString* result = [NSString stringWithFormat:decimalPlaces, numberIn];
 
    return result;
}

Here’s the expanded function managing everything I needed at the time:

+(NSString *) multiplyThenDivide:(NSString *)numberIn by:(NSString *)multiplicationFactorIn divideBy:(NSString *)divisionFactor toDecimalPlaces:(NSString *)decimalPlaces
{
    // Make arguments into floats so we can do operations on them:
    float numberInFloat = [numberIn floatValue];
    float multiplicationInFloat = [multiplicationFactorIn floatValue];
 
    // Do those operations:
    float resultFloat = numberInFloat * multiplicationInFloat;
    resultFloat = resultFloat / 100;
 
    // Assign the right number of decimal places:
    decimalPlaces = [NSString stringWithFormat:@"%%.%@f", decimalPlaces];
    NSString* result = [NSString stringWithFormat:decimalPlaces, resultFloat];
 
    return result;
}

By no means a master class, but hopefully it’ll help someone at some point.

Return top