Basic structure for Nit apps on iOS

Introduced classes

extern class AppDelegate

ios :: AppDelegate

Application interface to the iOS system
extern class UIApplication

ios :: UIApplication

Graphical application to which events are sent

Redefined classes

redef class App

ios :: app $ App

App subclasses are cross-platform applications
redef class Sys

ios :: app $ Sys

The main class of the program.

All class definitions

redef class App

ios :: app $ App

App subclasses are cross-platform applications
extern class AppDelegate

ios $ AppDelegate

Application interface to the iOS system
redef class Sys

ios :: app $ Sys

The main class of the program.
extern class UIApplication

ios $ UIApplication

Graphical application to which events are sent
package_diagram ios::app app ios::platform platform ios::app->ios::platform app app ios::app->app core core ios::platform->core app->core serialization serialization app->serialization pthreads pthreads app->pthreads json json app->json android android app->android ...core ... ...core->core ...serialization ... ...serialization->serialization ...pthreads ... ...pthreads->pthreads ...json ... ...json->json ...android ... ...android->android ios::ios ios ios::ios->ios::app ios::glkit glkit ios::glkit->ios::ios ios::http_request http_request ios::http_request->ios::ios ios::hello_ios hello_ios ios::hello_ios->ios::ios ios::uikit uikit ios::uikit->ios::ios ios::glkit... ... ios::glkit...->ios::glkit ios::http_request... ... ios::http_request...->ios::http_request ios::hello_ios... ... ios::hello_ios...->ios::hello_ios ios::uikit... ... ios::uikit...->ios::uikit

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module app_base

app :: app_base

Base of the app.nit framework, defines App
module array

core :: array

This module introduces the standard array structure.
module assets

app :: assets

Portable services to load resources from the assets folder
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module list

core :: list

This module handle double linked lists
module math

core :: math

Mathematical operations
module native

core :: native

Native structures for text and bytes
module numeric

core :: numeric

Advanced services for Numeric types
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O

Parents

module app

app :: app

app.nit is a framework to create cross-platform applications
module platform

ios :: platform

Triggers compilation for the iOS platform

Children

module ios

ios :: ios

iOS platform support

Descendants

module a_star-m

a_star-m

module display_ios

gamnit :: display_ios

Gamnit display implementation for iOS
module gamnit_ios

gamnit :: gamnit_ios

Support services for gamnit on iOS
module glkit

ios :: glkit

GLKit services to create an OpenGL ES context on iOS
module hello_ios

ios :: hello_ios

Simple iOS app with a single label
module http_request

ios :: http_request

Implementation of app::http_request for iOS
module input_ios

gamnit :: input_ios

Gamnit event support for iOS
module ui

ios :: ui

Implementation of app::ui for iOS
module uikit

ios :: uikit

File generated by objcwrapper
# Basic structure for Nit apps on iOS
module app

import platform
import ::app

in "ObjC Header" `{
	#import <UIKit/UIKit.h>

	// Our interface to the iOS system
	@interface AppDelegate: UIResponder <UIApplicationDelegate>

		// The main window
		@property (strong, nonatomic) UIWindow *window;
	@end
`}

in "ObjC" `{

	// Global reference to the App from app.nit
	App app_nit_ios_app;

	// Our own C argc and argv
	int app_nit_ios_argc;
	char **app_nit_ios_argv;

	@implementation AppDelegate

	- (BOOL)application:(UIApplication *)application
		willFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

		// Set aside `application` to be used from Nit
		App_ui_application__assign(app_nit_ios_app, application);
		App_app_delegate__assign(app_nit_ios_app, self);

		// Complete the callback
		return App_will_finish_launching_with_options(app_nit_ios_app);
	}

	- (BOOL)application:(UIApplication *)application
		didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

		return App_did_finish_launching_with_options(app_nit_ios_app);
	}

	- (void)applicationWillResignActive:(UIApplication *)application {
		App_will_resign_active(app_nit_ios_app);
	}

	- (void)applicationDidEnterBackground:(UIApplication *)application {
		App_did_enter_background(app_nit_ios_app);
	}

	- (void)applicationWillEnterForeground:(UIApplication *)application {
		App_will_enter_foreground(app_nit_ios_app);
	}

	- (void)applicationDidBecomeActive:(UIApplication *)application {
		App_did_become_active(app_nit_ios_app);
	}

	- (void)applicationWillTerminate:(UIApplication *)application {
		App_will_terminate(app_nit_ios_app);
	}

	@end
`}

# Application interface to the iOS system
extern class AppDelegate in "ObjC" `{ AppDelegate * `}
end

# Graphical application to which events are sent
extern class UIApplication in "ObjC" `{ UIApplication * `}
end

redef class App

	# Main graphical application
	var ui_application: UIApplication

	# Application interface to the iOS system
	var app_delegate: AppDelegate

	# Copy back to C the command line arguments
	#
	# Nit extracts the first arguments from the `args` sequence,
	# so we need to add it back. That's why Nit's `args` is smaller than in C.
	private fun register_args(program_name: CString, argc: Int,
	argv: Sequence[String]) import Sequence[String].[], String.to_cstring in "ObjC" `{
		app_nit_ios_argc = (int)(argc+1);

		// TODO copy or pin the strings when needed
		app_nit_ios_argv = malloc(argc * sizeof(char*));
		app_nit_ios_argv[0] = program_name;
		for (int i = 0; i < argc; i ++) {
			String arg = Sequence_of_String__index(argv, i);
			app_nit_ios_argv[i+1] = String_to_cstring(arg);
		}
	`}

	# Register `self` globally in C so it can be retrieved from iOS callbacks
	private fun register_globally in "ObjC" `{
		App_incr_ref(self);
		app_nit_ios_app = self;
	`}

	# Entry point to the iOS framework
	private fun ui_application_main: Bool import did_finish_launching_with_options,
	will_finish_launching_with_options,
	will_resign_active, did_enter_background, will_enter_foreground,
	did_become_active, will_terminate, ui_application=, app_delegate= in "ObjC" `{

		@autoreleasepool {
			return UIApplicationMain(app_nit_ios_argc, app_nit_ios_argv,
				nil, NSStringFromClass([AppDelegate class]));
		}
	`}

	# The application is about to launch
	#
	# Redef this method to set the very first custom code to be executed.
	fun will_finish_launching_with_options: Bool do return true

	# The application just launched but is not yet displayed to the user
	#
	# Redef this method to customize the behavior.
	fun did_finish_launching_with_options: Bool
	do
		on_create
		on_restore_state
		return true
	end

	# The application is about to move from active to inactive state
	#
	# This can occur for certain types of temporary interruptions
	# (such as an incoming phone call or SMS message) or when the
	# user quits the application and it begins the transition to
	# the background state.
	#
	# Redef this method to pause ongoing tasks, disable timers, and
	# throttle down OpenGL ES frame rates. Games should use this
	# method to pause.
	fun will_resign_active do on_pause

	# The application just left foreground it can be suspended at any time
	#
	# Redef this method to release shared resources, save user data,
	# invalidate timers, and store application state to restore your
	# application to its current state in case it is terminated later.
	#
	# If your application supports background execution, this method
	# is called instead of `will_terminate` when the user quits.
	fun did_enter_background
	do
		on_save_state
		on_stop
	end

	# The application will enter the foreground
	#
	# Called as part of the transition from the background to the
	# inactive state.
	#
	# Redef to undo changes made on entering the background.
	fun will_enter_foreground do on_restart

	# The application just became active
	#
	# Redef to restart any tasks that were paused (or not yet started) while
	# the application was inactive. If the application was previously
	# in the background, optionally refresh the user interface.
	fun did_become_active do on_resume

	# The application is about to terminate (from a state other than suspended)
	#
	# Redef to save data if appropriate.
	fun will_terminate
	do
		# Usually a forced termination by the system
		on_save_state
		on_pause
		on_stop
	end
end

app.register_args(program_name.to_cstring, args.length, args)
app.register_globally

var ret = app.ui_application_main
exit if ret then 0 else 1
lib/ios/app.nit:15,1--206,25