pathInDocumentDirectory C-function


#1

Hi,

I was just wondering why the pathInDocumentDirectory was written as a c function and not just return a NSString from a objective-c class that creates the path?

Thanks
Jon


#2

That’s because C functions are not tied to any class and thus can be invoked easily from anywhere in your code.

All you need for a C function is a declaration and of course a definition for it (somewhere.)

The other alternative is to wrap all your C functions as class methods in a class.

Free-standing C functions:

long nextPrimeAfter (long);
...

long nextPrimeAfter (long number)
{
...
}
...

Wrapped C functions:

@interface Primes: (NSObject)
+(long)nextPrimeAfter:(long)number;
...
@end
...

@implementation Primes
+(long)nextPrimeAfter:(long)number
{
...
}
...
@end

#3

Thanks for that.

I’m still newish to this and I came straight to Obj-C without an previous C experience so I don’t fully understand the ‘whys’ of doing certain things.

Cheers
Jon