Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Entry point
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Swift=== When run in an [[Xcode]] Playground,<ref>Not to be confused with [https://www.apple.com/swift/playgrounds/ Swift Playgrounds] {{Webarchive|url=https://web.archive.org/web/20220708182700/https://www.apple.com/swift/playgrounds/ |date=2022-07-08 }}, an Apple-developed iPad app for learning the Swift programming language.</ref> [[Swift (programming language)|Swift]] behaves like a scripting language, executing statements from top to bottom; top-level code is allowed. <syntaxhighlight lang="swift"> // HelloWorld.playground let hello = "hello" let world = "world" let helloWorld = hello + " " + world print(helloWorld) // hello world </syntaxhighlight> [[Cocoa (API)|Cocoa]]- and [[Cocoa Touch]]-based applications written in Swift are usually initialized with the <code>@NSApplicationMain</code> and <code>@UIApplicationMain</code> attributes, respectively. Those attributes are equivalent in their purpose to the <code>main.m</code> file in [[Objective-C]] projects: they implicitly declare the <code>main</code> function that calls <code>UIApplicationMain(_:_:_:_:)</code><ref>{{Cite web|url=https://developer.apple.com/documentation/uikit/1622933-uiapplicationmain|title=UIApplicationMain(_:_:_:_:) β UIKit|website=Apple Developer Documentation|access-date=2019-01-12|archive-date=2019-01-12|archive-url=https://web.archive.org/web/20190112195043/https://developer.apple.com/documentation/uikit/1622933-uiapplicationmain|url-status=live}}</ref> which creates an instance of <code>UIApplication</code>.<ref>{{Cite web|url=https://developer.apple.com/documentation/uikit/uiapplication|title=UIApplication β UIKit|website=Apple Developer Documentation|access-date=2019-01-12|archive-date=2019-01-13|archive-url=https://web.archive.org/web/20190113062642/https://developer.apple.com/documentation/uikit/uiapplication|url-status=live}}</ref> The following code is the default way to initialize a Cocoa Touch-based [[iOS]] app and declare its application delegate.<syntaxhighlight lang="swift"> // AppDelegate.swift import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { return true } } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)