I have no experience in objective C, so I'm having trouble with some of the notation. In my "AppDelegate.swift" file, there is a "@UIMainApplication" at the top. What does this mean?
Also, if possible, could you please give me the "equivalent" statement (if it exists) in C++?
Thanks.
The @... represents an attribute, from SWIFT documentation: Attributes provide more information about a declaration or type. There are two kinds of attributes in Swift, those that apply to declarations and those that apply to types.
Note. The remainder operator ( % ) is also known as a modulo operator in other languages. However, its behavior in Swift for negative numbers means that, strictly speaking, it's a remainder rather than a modulo operation.
The underscore indicates that there is no external parameter name for the function. Apple's Swift Documentation talks about this concept in terms of when you're writing your own functions.
Sep 21, 2015 at 16:56. In Swift 2, the hashtag (#) for second and onward parameters are kind of implicitly there to tell the external label and local name, unless you suppress the need of external label with underscore (_).
Well, you picked a rather complicated one. The @
merely means that this is an attribute - a special marker or signal to the compiler, as Apple explains here. But @UIApplicationMain
is a particularly profound attribute! It substitutes for the entire UIApplicationMain
implementation that lies at the heart of a C / Objective-C application, in the main.m file (as I explain here):
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil,
NSStringFromClass([AppDelegate class]));
}
}
That is the main entry point of the app, implementing the entire launch-and-run code that is the running application. You can do something like that in Swift — a main.swift file with the Swift equivalent of that code — but Swift saves you the trouble by letting you designate your app delegate class with the @UIApplicationMain
attribute.
If you start a project as an Objective-C or Objective-C++ project, the template will give you a main file containing the main
implementation, so there's no need to do anything special in this regard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With