温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.apple.com/swift
点击访问原文链接

Swift - Apple Developer

Swift - Apple Developer ' /> View in English

Apple Developer Get Started Explore Get Started Overview Learn Apple Developer Program Stay Updated Latest News Hello Developer Platforms Explore Platforms Apple Platforms iOS iPadOS macOS tvOS visionOS watchOS App Store Featured Design Distribution Games Accessories Web Home CarPlay Technologies Explore Technologies Overview Xcode Swift SwiftUI Featured Accessibility App Intents Apple Intelligence Games Machine Learning & AI Security Xcode Cloud Community Explore Community Overview Meet with Apple events Community-driven events Developer Forums Open Source Featured WWDC Swift Student Challenge Developer Stories App Store Awards Apple Design Awards Apple Developer Centers Documentation Explore Documentation Documentation Library Technology Overviews Sample Code Human Interface Guidelines Videos Release Notes Featured Updates iOS iPadOS macOS watchOS visionOS tvOS Xcode Downloads Explore Downloads All Downloads Operating Systems Applications Design Resources Featured Xcode TestFlight Fonts SF Symbols Icon Composer Support Explore Support Overview Help Guides Developer Forums Feedback Assistant Contact Us Featured Account Help App Review Guidelines App Store Connect Help Upcoming Requirements Agreements and Guidelines System Status Quick Links Events News Forums Sample Code Videos   Swift Open Menu Close Menu Overview What’s New Get Started Resources

Expressive

Concise code, powerful results With an expressive, easy-to-read syntax, Swift empowers new developers to quickly understand core programming concepts. And with resources like the Develop in Swift Tutorials, Swift Coding Clubs, and Swift Playground, it’s never been easier to get started with Swift as your first programming language.

Learn more about Swift education resources from Apple

Experienced developers can also quickly dive in and take advantage of the power and safety of Swift, with the comfort of familiar modern features used in other programming languages.

struct Player { var name: String var highScore: Int = 0 var history: [Int] = [] init(_ name: String) { self.name = name } } var player = Player("Tomas")

Declare new types with modern, straightforward syntax, provide default values for instance properties, and define custom initializers.

extension Player { mutating func updateScore(_ newScore: Int) { history.append(newScore) if highScore newScore { print("\(newScore)! A new high score for \(name)! 🎉") highScore = newScore } } } player.updateScore(50) // Prints "50! A new high score for Tomas! 🎉" // player.highScore == 50

Add functionality to existing types with extensions, and cut down on boilerplate code with custom string interpolations.

extension Player: Codable, Equatable {} import Foundation let encoder = JSONEncoder() try encoder.encode(player) print(player) // Prints "Player(name: "Tomas", highScore: 50, history: [50])"

Perform powerful custom transformations using streamlined closures.

let players = getPlayers() // Sort players, with best high scores first let ranked = players.sorted(by: { player1, player2 in player1.highScore > player2.highScore }) // Create an array with only the players’ names let rankedNames = ranked.map { $0.name } // ["Erin", "Rosana", "Tomas"]

Quickly extend your custom types to take advantage of powerful language features, such as automatic JSON encoding and decoding.

Fast

Optimized for Apple platforms From its earliest conception, Swift was built to be fast. Using the incredibly high-performance LLVM compiler technology, Swift code is transformed into optimized machine code that gets the most out of modern hardware. The syntax and standard library have also been tuned to make the most obvious way to write your code also perform the best whether it runs in the watch on your wrist or across a cluster of servers. And Swift is the best choice to succeed C++. It includes low-level primitives such as types, flow control, and operators, and provides object-oriented features such as classes, protocols, and generics.

Safe

Straightforward safety Swift eliminates entire classes of unsafe code. Variables are always initialized before use, arrays and integers are checked for overflow, memory is automatically managed, and potential data races can be spotted at compile time. And Swift heavily leverages value types, especially for commonly used types like Arrays and Dictionaries. This means that when you make a copy of something with that type, you know it won’t be modified elsewhere.

Swift also provides a safe way to handle missing values in your code. With optionals, you can explicitly declare when a value may be missing, or nil. And with tools like the if let, guard let, and ?? syntaxes, you can safely check these values before trying to return them, avoiding any surprises or crashes when a nil value is returned.

if let bestPlayer = players.highestScoringPlayer() { recordHolder = """ The record holder is \(bestPlayer.name),\ with a high score of \(bestPlayer.highScore)! """ } else { recordHolder = "No games have been played yet." } print(recordHolder) // The record holder is Erin, with a high score of 271! let highestScore = players.highestScoringPlayer()?.highScore ?? 0 // highestScore == 271

Features such as optional binding, optional chaining, and nil coalescing let you work safely and efficiently with optional values.

Adaptable

From microcontrollers to servers Swift is efficient enough to be used in constrained environments like embedded devices, and powerful enough to scale all the way up to servers and cloud infrastructure.

Go small with Embedded Swift Explore the Swift on Server ecosystem

Interoperable

Bring Swift to your existing projects You can create an entirely new application with Swift today, or begin using Swift code to implement new features and functionality in your app. Swift code coexists alongside your Objective-C and C++ files in the same project, with access to your Objective-C and C++ APIs, making it easy to adopt.

Safely mix C, C++, and Swift

And with the swift-java interoperability project, you can bring Swift code directly into your Java programs, and vice versa — allowing you to adopt Swift at your own pace, and write safe and performant code that interoperates between these two runtimes.

Explore Swift and Java interoperability

Swift

Swift is a powerful and intuitive programming language for all Apple platforms. It’s easy to get started using Swift, with a concise-yet-expressive syntax and modern features you’ll love. Swift code is safe by design and produces software that runs lightning fast.

Get to know Swift

Expressive

Concise code, powerful results More about this tile

Fast

Optimized for Apple platforms More about this tile

Safe

Straightforward safety More about this tile

Adaptable

From microcontrollers to servers More about this tile

Interoperable

Bring Swift to your existing projects More about this tile Discover what’s new in Swift Dive into the latest key features and capabilities of the Swift language. New to Swift? Get started with our Swift Pathway, an easy-to-navigate collection of resources to get started. Developer stories Coding in the kitchen How Devin Davies whipped up the tasty recipe app Crouton. Read more How Things came to server-side Swift Find out how the Cultured Code team gave its engines a tune-up. Read more It’s always sunny for Flipping Hues Learn how these Apple Developer Academy alums are tracking the sun and the moon with Swift. Read more Meet with Apple Sharpen your skills through in-person and online activities around the world. Explore the schedule Resources Dive into Swift tools, documentation, sample code, videos, and more. Explore and download resources Explore more

Explore frameworks, tools, and programs – all built for developing with Swift.

Swift SwiftData Swift Testing Swift Charts Swift Playground Swift is developed in the open. To learn more about the open-source Swift project and community, visit Swift.org.

Developer Footer Swift Platforms Open Menu Close Menu iOS iPadOS macOS tvOS visionOS watchOS App Store Tools Open Menu Close Menu Swift SwiftUI Swift Playground TestFlight Xcode Xcode Cloud Icon Composer SF Symbols Technologies Open Menu Close Menu Accessibility Accessories Apple Intelligence Audio & Video Augmented Reality Business Design Distribution Education Games Health & Fitness In-App Purchase Localization Maps & Location Machine Learning & AI Security Safari & Web Resources Open Menu Close Menu Documentation Downloads Sample Code Videos Support Open Menu Close Menu Help Guides & Articles Contact Us Forums Feedback & Bug Reporting System Status Account Open Menu Close Menu Apple Developer App Store Connect Certificates, IDs, & Profiles Feedback Assistant Programs Open Menu Close Menu Apple Developer Program Apple Developer Enterprise Program App Store Small Business Program MFi Program Mini Apps Partner Program News Partner Program Video Partner Program Security Bounty Program Security Research Device Program Events Open Menu Close Menu Meet with Apple Apple Developer Centers App Store Awards Apple Design Awards Apple Developer Academies WWDC Read the latest news Get the Apple Developer app. Light Dark Auto Copyright © 2026 Apple Inc. All rights reserved. Terms of Use Privacy Policy Agreements and Guidelines

智能索引记录