1.16: Swift Examples
- Page ID
- 10595
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)
Overview
Swift is a general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. for iOS, macOS, watchOS, tvOS, and Linux. Apple intended Swift to support many core concepts associated with Objective-C, but in a “safer” way, making it easier to catch software bugs. Swift was introduced in 2014.[1]
Swift is a popular programming language for the Apple platforms it supports, but it lacks support for Microsoft Windows environments.[2].
Example
Hello World
// This program displays "Hello world!" // // References: // https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/GuidedTour.html print("Hello world!")
Output
Hello world!
Discussion
Each code element represents:[3]
//
begins a commentprint()
calls the print function"Hello world!"
is the literal string to be displayed
Swift IDEs
There are several free cloud-based and local IDEs available to begin coding in Swift. Check with your instructor or do your own research for recommendations.
Cloud-Based IDEs
- GDB Online
- IBM Swift Sandbox
- Ideone
- iSwift
- paiza.IO
- repl.it
Local IDEs
- AppCode
- Atom
- Xcode
References
- Wikiversity: Computer Programming
-
Swift (programming language)
↵
-
TIOBE: Index
↵
-
Wikibooks: Programming Fundamentals/Hello World
↵