Swift (プログラミング言語 )
![]() Swiftのロゴ | |
パラダイム |
![]() |
---|---|
2014 | |
クリス・ラトナー、Apple ![]() | |
5.10.1 / 2024 | |
| |
Rust、Haskell、Ruby、Objective-C、Python、C Sharp、CLU、C++、Java、Scala、Smalltalk、Groovy、D![]() | |
プラットフォーム |
macOS、iOS、Linux、Microsoft Windows 10、iPadOS、tvOS、watchOS、Microsoft Windows、visionOS ![]() |
ライセンス |
Apache-2.0、Apache License ![]() |
ウェブサイト | |
swift ![]() |
Swift(スウィフト)は、AppleのiOSおよびmacOS、Linux、Windowsで
Swiftは、
Swiftは、マルチパラダイムのコンパイラプログラミング
LLVMコンパイラが
歴史 [編集 ]
Swiftは2010
その
2014
2015
WWDC 2016の
2017
2017
2019
WWDC 2019にて、Appleのプラットフォーム
2019
2020
2020
2021
2024
特徴 [編集 ]
AppleはSwiftの
- モダン
- クロージャやタプル、ジェネリックプログラミング、Optional
型 の採用 などが挙 げられる。 安全 静的 な型 チェック、変数 の初期 化 の強制 、数値 型 のオーバーフローの検査 、自動 参照 カウントによるメモリ管理 などが挙 げられる。
また、if文 のブレースの省略 禁止 、switch-case文 は明示 的 に指定 されない限 りフォールスルーしないなど、既存 のプログラミング言語 において記述 ミスによるバグが発生 しやすかった部分 を文法 的 に解決 している。- インタラクティブ
- Swiftはコンパイラ
言語 でありながら、インタプリタとしてスクリプトを実行 することも可能 で、対話 実行 環境 (REPL) も用意 されている。
Swiftと同時 に発表 されたXcodeバージョン6では、コードの実行 結果 をグラフィカルに確認 しながら開発 できるPlaygroundsが実装 された。
クレイグ・フェデリギは、Swiftの
サンプルコード[編集 ]
Hello World[編集 ]
print( "Hello, World!" ) // これだけで動 いて、Hello, World! と出力 される。
他 [編集 ]
/*
* コメントはCスタイルの複 数 行 コメントと…
*/
// C++スタイルの一 行 コメントの双方 をサポートしている
// var name: Type = value でType型 の変数 nameを宣言 し、valueで初期 化 する
var explicitDouble: Double = 70 // 70.0
/// 型 が省略 された場合 は、型 推論 により初期 値 の型 が適用 される
var implicitInteger = 70 // Int
var implicitDouble = 70.0 // Double
// let name:Type = value でType型 の定数 nameにvalueを設定 する。
// 型 推論 可能 な場合 、型 の表記 は省略 できる。
let theAnswer = 42
// 識別子 にはたいていのUnicode文字 を用 いることができる。
let リンゴの数 = 3
let みかんの数 = 5
// 文字 列 リテラル"..."の中 にある\(expr)には、式 exprの内容 が展開 される
let リンゴ説明 = "私 は\(リンゴの数 )個 のリンゴを持 っている。" // ”私 は3個 のリンゴを持 っている。"
let 果物 説明 = "私 は\(リンゴの数 + みかんの数 )個 の果物 を持 っている。" //"私 は8個 の果物 を持 っている。"
// Swiftでは辞書 も組 み込 みでサポートされている。
// 以下 は Dictionary<String, Int> 型 の定数 辞書 の定義 の一 例 である。
let people = ["Anna": 67, "Bety": 8, "Jack": 33, "Sam": 25]
// 辞書 の内容 の列挙 は for (key, value) in dict { ... }
for (name, age) in people {
print("\(name) is \(age) years old.")
}
// メソッドや関数 は "func"文法 を使 って宣言 する。
// パラメータ名 の付 け方 に注意 。-> で戻 り値 の型 を宣言 する
func sayHello(to personName: String) -> String {
let greeting = "こんにちは、" + personName + "さん"
return greeting
}
// "こんにちは、サーバーさん"を出力
print(sayHello(to: "サーバー"))
メモリ管理 (Automatic Reference Counting)[編集 ]
![]() |
Swiftではrelease
、retain
を
weak
、unowned
が
相互 運用 性 [編集 ]
![]() |
SwiftはCocoaやObjective-Cをシームレスに
モジュールとしてアクセス
import Foundation
UITableView *myTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
Swift
let myTableView: UITableView = UITableView(frame: .zero, style: .Grouped)
Xcode 6
C言語 APIとの互換 [編集 ]
![]() |
SwiftからLibcを
puts("Hello from libc")
let fd = open("/tmp/scratch.txt", O_WRONLY|O_CREAT, 0o666)
if fd < 0 {
perror("could not open /tmp/scratch.txt")
} else {
let text = "Hello World"
write(fd, text, strlen(text))
close(fd)
}
その他 の実装 、開発 [編集 ]
Swift 2.2から、Ubuntuディストリビューション
Swiftがオープンソース
Androidで
2020
注釈 [編集 ]
出典 [編集 ]
- ^
出典 URL: https://github.com/apple/swift/releases/tag/swift-5.10.1-RELEASE,出版 日 : 2024年 6月 5日 - ^ a b c Williams, Owen (2014
年 6月 2日 ). “Apple announces Swift, a new programming language for iOS”. The Next Web. 2014年 6月 2日 閲覧 。 - ^ Protocol-oriented Programming in Swift. Apple Inc. YouTube.
- ^ “Introducing Swift”. Apple. 2014
年 6月 2日 閲覧 。 - ^ Chris Lattner's Homepage (2020
年 6月 24日 ) - ^ Swift Has Reached 1.0 - Swift Blog - Apple Developer
- ^ Swift Playgrounds、App Storeで
提供 開始 - ^ Swift Playgrounds、さらに5か
国 語 に対応 - ^ Swift 3.1 Released! - swoft.org (2017
年 3月 27日 ) - ^ [swift-evolution Update on the Swift Project Lead] - Chris Lattner (2017
年 1月 10日 ) - ^ Swift 4.0 Released! - Ted Kremenek (2017
年 9月 19日 ) - ^ “「Xcode」をMac App Storeで”. Mac App Store. 2018
年 4月 2日 閲覧 。 - ^ Xcode 10 includes Swift 4.2, which compiles your software more quickly, helps you deliver faster apps, and generates even smaller binaries. “Xcode 10” (
英語 ). Developer. 2018年 6月 12日 閲覧 。 - ^ “Swift.org - Swift 5 Released!” (
英語 ). 2020年 3月 18日 閲覧 。 - ^ “Introducing SwiftUI: Building Your First App - WWDC 2019 - Videos - Apple Developer” (
英語 ). 2020年 3月 23日 閲覧 。 - ^ “Swift.org - Swift 5.1 Released!” (
英語 ). 2020年 11月2日 閲覧 。 - ^ “Swift.org - Swift 5.2 Released!” (
英語 ). 2020年 11月25日 閲覧 。 - ^ “Swift.org - Swift 5.3 released!” (
英語 ). 2021年 4月 13日 閲覧 。 - ^ “Introducing Swift on Windows” (
英語 ). 2020年 11月2日 閲覧 。 - ^ Hudson, Paul (2021
年 6月 6日 ). “What's new in Swift 5.5?”. HackingWithSwift.com. Hacking with Swift. 2021年 7月 29日 閲覧 。 - ^ “Swift.org - Swift 5.10 Released” (
英語 ). 2024年 4月 11日 閲覧 。 - ^ kojima (1970
年 1月 1日 ). “Swiftとは?フリーランスの仕事 内容 や年収 、案件 を獲得 するための方法 を解説 !”. xhours - フリーランスエンジニア向 けの求人 ・案件 検索 サイト. 2023年 12月28日 閲覧 。 - ^ “Automatic Reference Counting — The Swift Programming Language (Swift 5.2)” (
英語 ). 2020年 5月 25日 閲覧 。 - ^ “Using Swift with Cocoa and Objective-C” (HTML). Apple Inc.. 2014
年 9月 2日 閲覧 。 - ^ “Importing Objective-C into Swift”. Apple Inc.. 2020
年 6月 22日 閲覧 。 - ^ “Importing Swift into Objective-C”. Apple Inc.. 2020
年 6月 22日 閲覧 。 - ^ “Migrating Your Objective-C Code to Swift”. Apple Inc.. 2020
年 6月 22日 閲覧 。 - ^ “Swift.org - Download Swift”. 2020
年 11月2日 閲覧 。 - ^ “IBM brings Swift to the cloud, releases web framework Kitura written in Apple’s programming language”. 2020
年 3月 23日 閲覧 。 - ^ Inc., Apple. “Server APIs Work Group”. Swift.org 2020
年 5月 25日 閲覧 。 - ^ “Swift for Android: Our Experience and Tools”. 2021
年 3月 24日 閲覧 。 - ^ “Swift.org - Introducing Swift AWS Lambda Runtime” 2020
年 9月 24日 閲覧 。
外部 リンク[編集 ]
- Swift.org - Welcome to Swift.org
公式 ウェブサイト - Swift - Apple Developer
- The Swift Programming Language (Swift 4), Apple Inc. (2017
年 9月 19日 ) - Using Swift with Cocoa and Objective-C, Apple Inc. (2014)
- iOS Standard Library, Apple Inc. (2014)
- Swift
公式 BLOG , Apple Inc. (2014) - Run Swift - iSwift Playground
- Online Swift Playground - Online Swift Playground
- Swift Playgrounds - Apple