// Minimal iOS/UIKit window — the UIKit object graph a real app builds: a `UIWindow`
// sized to the screen, a root `UIViewController`, then `makeKeyAndVisible`. Bound
// through D's built-in `extern(Objective-C)` + `@selector` (same mechanism the
// objective-d package wraps). See ../index.md (the iOS/UIKit OS-API survey).
//
// > [!IMPORTANT] A real iOS app is launched by `UIApplicationMain`, which
// > instantiates an **app-delegate Objective-C class**. D's interop can *call*
// > Objective-C but cannot *define* new Objective-C classes, so a pure-D UIKit app
// > can't supply the delegate — the delegate is normally written in Objective-C or
// > Swift and calls into D. This file therefore demonstrates the UIKit bindings and
// > the window/VC construction; it is **cross-compiled for the iOS Simulator** for
// > verification (`ldc2 -mtriple=arm64-apple-ios<ver>-simulator`). A full Simulator
// > run (app bundle + `simctl`) is documented in the survey as a manual step.
module (module) appapp;
import (package) corecore.(module) core.attributeThis module contains UDA's (User Defined Attributes) either used in
the runtime or special UDA's recognized by compiler.
Attribute Name, Linkage, Description
gnuAbiTag, C++,
Declares an ABI tag on a C++ symbol.
mustuse,,
Ensures that values of a struct or union type are not discarded.
optional, Objective-C,
Makes an Objective-C interface method optional.
selector, Objective-C,
Attaches an Objective-C selector to a method.
standalone,,
Marks a shared module constructor as not depending on any
other module constructor being run first.
weak,,
Specifies that a global symbol should be emitted with weak linkage.
Source
core/attribute.d
attribute : selector;
import (package) corecore.(package) core.stdcstdc.(module) core.stdc.stdioD header file for C99 <stdio.h>
pubs.opengroup.org/onlinepubs/009695399/basedefs/stdio.h.html, stdio.h
Source
core/stdc/stdio.d
stdio : (alias) app.printf = int core.stdc.stdio.printf(scope const(char*) format, scope const ...) nothrow @nogcprintf;
// Core Graphics geometry (CGFloat == double on 64-bit arm).
extern (C) struct (struct) app.CGPointCGPoint
{
double (field) double app.CGPoint.xx, (field) double app.CGPoint.yy;
}
extern (C) struct (struct) app.CGSizeCGSize
{
double (field) double app.CGSize.widthwidth, (field) double app.CGSize.heightheight;
}
extern (C) struct (struct) app.CGRectCGRect
{
(struct) app.CGPointCGPoint (field) app.CGPoint app.CGRect.originorigin;
(struct) app.CGSizeCGSize (field) app.CGSize app.CGRect.sizesize;
}
extern (Objective-C):
extern class (class) app.NSObjectNSObject
{
}
extern class (class) app.UIResponderUIResponder : (class) app.NSObjectNSObject
{
}
extern class (class) app.UIScreenUIScreen : (class) app.NSObjectNSObject
{
static (class) app.UIScreenUIScreen app.UIScreen app.UIScreen.mainScreen()mainScreen() @selector("mainScreen");
(struct) app.CGRectCGRect app.CGRect app.UIScreen.bounds()bounds() @selector("bounds");
}
extern class (class) app.UIViewControllerUIViewController : (class) app.UIResponderUIResponder
{
static (class) app.UIViewControllerUIViewController app.UIViewController app.UIViewController.alloc()alloc() @selector("alloc");
(class) app.UIViewControllerUIViewController app.UIViewController app.UIViewController.init()init() @selector("init");
}
extern class (class) app.UIWindowUIWindow : (class) app.UIResponderUIResponder
{
static (class) app.UIWindowUIWindow app.UIWindow app.UIWindow.alloc()alloc() @selector("alloc");
(class) app.UIWindowUIWindow app.UIWindow app.UIWindow.initWithFrame(app.CGRect frame)initWithFrame((struct) app.CGRectCGRect (parameter) app.CGRect frameframe) @selector("initWithFrame:");
void void app.UIWindow.setRootViewController(app.UIViewController vc)setRootViewController((class) app.UIViewControllerUIViewController (parameter) app.UIViewController vcvc) @selector("setRootViewController:");
void void app.UIWindow.makeKeyAndVisible()makeKeyAndVisible() @selector("makeKeyAndVisible");
}
extern (D): // back to D linkage
int int D main()main()
{
// Build the minimal UIKit window/VC graph. On the Simulator this is driven from
// an Objective-C app delegate (see the note above); here it exercises the
// bindings and is cross-compiled for the iOS Simulator target.
(unresolved type) CGRectCGRect _error_ boundsbounds = UIScreen.UIScreen.mainScreenmainScreen().UIScreen.mainScreen().boundsbounds();
(unresolved type) UIWindowUIWindow _error_ winwin = UIWindow.UIWindow.allocalloc().UIWindow.alloc().initWithFrameinitWithFrame(bounds);
(unresolved type) UIViewControllerUIViewController _error_ rootroot = UIViewController.UIViewController.allocalloc().UIViewController.alloc().initinit();
win.win.setRootViewControllersetRootViewController(root);
win.win.makeKeyAndVisiblemakeKeyAndVisible();
printf("ok: built a UIWindow + root UIViewController (%.0fx%.0f)\n",
bounds.bounds.sizesize.bounds.size.widthwidth, bounds.bounds.sizesize.bounds.size.heightheight);
return 0;
}