So this question is to help me better understand the inner workings of the Cocoa-touch framework and it may seem like a very simple question.
If you were to create a command line tool using Xcode, for example, using Core Data, Xcode generates methods in the "main.m" file that take in parameters in parentheses rather than the colon that is indicative of Objective-C. For example the following is the generated method declaration
static NSManagedObjectContext *managedObjectContext()
But, there is still Objective-C messages being sent inside the methods. For example,
NSString *path = [[[NSProcessInfo processInfo] arguments] objectAtIndex:0];
path = [path stringByDeletingPathExtension];
NSURL *modelURL = [NSURL fileURLWithPath:[path stringByAppendingPathExtension:@"momd"]];
model = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
Is this because the main.m file is a C/C++ file and not a Objective-C file, even though they share the same file extensions? Thanks for any insight!
The declaration:
static NSManagedObjectContext *managedObjectContext();
is a C function which can be declared and defined within Objective-C source files without problem. However you cannot do the opposite of declaring Objective-C classes and methods within a C source file; for example this is illegal:
myfile.c:
@interface MyObject
- (int)nothing:(int)value
{
return value;
}
@end