Tuesday, October 16, 2012

objective-c methods; - vs +

So you've been funning around with Objective C and while in Objective C land you've no doubt noticed these little ticks in front of your methods - and others with +

what does it all mean?

While trying to implement a way to find if a string is empty (truly empty, nil (aka null) or filled with whitespaces) I bumped into a neat solution @ http://stackoverflow.com/questions/3436173/nsstring-is-empty
 
+ (BOOL)isEmptyString:(NSString *)string {
// Returns YES if the string is nil or equal to @""
{
// Note that [string length] == 0 can be false 

// when [string // isEqualToString:@""] is true, because these are Unicode strings.

if (((NSNull *) string == [NSNull null]) || (string == nil) ) {
return YES;
}
string = [string stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];

if ([string isEqualToString:@""]) {

return YES;
}

return NO;
}
 

But what sparked up a thought here was that they were using + ClassMethod , and many times while I'm digging around for a solution many are simply -intanceMethods

so what does that mean? One way to think about it, is if I made the above function

an -instance method, then I would call it in my solution like this:

bool boolResult = [self isEmptyString:myStringVariable];


in a +class method
I create a new class (.h and .m files)
in my header:

#import <Foundation/Foundation.h>
@interface NSString (AdditionalStringFunctions)
+ (BOOL)isEmptyString:(NSString *)string;

@end

in my implementation I added the function:
#import "NSString+AdditionalStringFunctions.h"

@implementation NSString (AdditionalStringFunctions)

+ (BOOL) stringIsEmpty:(NSString *) aString {
  
    if ((NSNull *) aString == [NSNull null]) {
        return YES;
    }
  
    if (aString == nil) {
        return YES;
    } else if ([aString length] == 0) {
        return YES;
    } else {
        aString = [aString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
        if ([aString length] == 0) {
            return YES;
        }
    }
  
    return NO;
}

@end


Now I get to use it like this:

NSString *myString = [[NSString alloc] init];
myString = @"SomeString";

if([NSString stringIsEmpty:myString]) {
   NSLog(@"Your String is empty!");
}
else{
   NSLog(@"Your String is NOT empty!");
 }  


I'll take some time later to look into how to make it be more usable something like:

[myString isStringEmpty]; sort of like the length function

Thursday, October 11, 2012

Manage This!!

You've started developing iPad and iPhone apps for your company for in-house use.  You've managed to check your list and cross it twice,






  • Sign up to Enterprise Licensing at Apple?
       Check

  • Grabbed your Apple ID?
       Double Check
  • Managed to deploy your App to the enteprise?
       Check, Check, Check

  • Can push out updates?
Wait, what?

If you've bought all in to Apple's Eco-System, you can install OSX Server for a few bucks onto an existing MacMini or pre-purchase one already setup that way.  Note that if you plan to first mirror the drives (an option that has to be done manually) I suggest you DO NOT setup profile manager 2 as it's a little tempermental when things don't point just right...

Once your disk setup is ready (mirrored or not) follow the advice at this blog link to help your self to a step by step guide on how to setup your MDM server.

 the only note to make here is that the  terminal command : sudo changeip -checkhostname did not work for me, so just an FYI...

http://krypted.com/iphone/configuring-using-profile-manager-2-in-os-x-mountain-lion-server/


You can always go with a third party MDM server but those will be far more expensive and for small deployments you really can't go wrong with Apple's solution.