This module contains UDA's (User Defined Attributes) either used in the runtime or special UDA's recognized by compiler.
Use this attribute to attach an Objective-C selector to a method.
This is a special compiler recognized attribute, it has several requirements, which all will be enforced by the compiler:
extern(Objective-C).
extern (Objective-C)
class NSObject
{
this() @selector("init");
static NSObject alloc() @selector("alloc");
NSObject initWithUTF8String(in char* str) @selector("initWithUTF8String:");
ObjcObject copyScriptingValue(ObjcObject value, NSString key, NSDictionary properties)
@selector("copyScriptingValue:forKey:withProperties:");
}
Use this attribute to make an Objective-C interface method optional.
An optional method is a method that does not have to be implemented in the class that implements the interface. To safely call an optional method, a runtime check should be performed to make sure the receiver implements the method.
This is a special compiler recognized attribute, it has several requirements, which all will be enforced by the compiler:
extern (Objective-C) import core.attribute : optional, selector;
extern (Objective-C):
struct objc_selector;
alias SEL = objc_selector*;
SEL sel_registerName(in char* str);
extern class NSObject
{
bool respondsToSelector(SEL sel) @selector("respondsToSelector:");
}
interface Foo
{
@optional void foo() @selector("foo");
@optional void bar() @selector("bar");
}
class Bar : NSObject
{
static Bar alloc() @selector("alloc");
Bar init() @selector("init");
void bar() @selector("bar")
{
}
}
extern (D) void main()
{
auto bar = Bar.alloc.init;
if (bar.respondsToSelector(sel_registerName("bar")))
bar.bar();
}
Use this attribute to declare an ABI tag on a C++ symbol.
ABI tag is an attribute introduced by the GNU C++ compiler. It modifies the mangled name of the symbol to incorporate the tag name, in order to distinguish from an earlier version with a different ABI.
This is a special compiler recognized attribute, it has a few requirements, which all will be enforced by the compiler:
extern(C++) symbol (struct, class, enum, function, and their templated counterparts). gnuAbiTag("c", "b", "a") will appear as @gnuAbiTag("a", "b", "c"). // ---- foo.cpp
struct [[gnu::abi_tag ("tag1", "tag2")]] Tagged1_2
{
struct [[gnu::abi_tag ("tag3")]] Tagged3
{
[[gnu::abi_tag ("tag4")]]
int Tagged4 () { return 42; }
}
}
Tagged1_2 inst1;
// ---- foo.d
@gnuAbiTag("tag1", "tag2") struct Tagged1_2
{
// Notice the repetition
@gnuAbiTag("tag1", "tag2", "tag3") struct Tagged3
{
@gnuAbiTag("tag1", "tag2", "tag3", "tag4") int Tagged4 ();
}
}
extern __gshared Tagged1_2 inst1;
© 1999–2021 The D Language Foundation
Licensed under the Boost License 1.0.
https://dlang.org/phobos/core_attribute.html