← Back to Swift Course | Chapter 1: Setup & Basics | Lesson 1 of 7

Swift परिचय

Swift Apple द्वारा बनाई एक friendly programming language है जो आपको computer या phone को बिल्कुल बताने देती है कि step by step क्या करना है।

What is Swift?

Swift एक general-purpose, compiled programming language है जिसे Apple ने Objective-C के एक modern replacement के रूप में बनाया। यह C जैसी compiled language की performance को modern languages की safety features के साथ combine करती है, जैसे strong typing और optionals जो crashes की एक पूरी category रोकते हैं।

Note: basic Swift try करने के लिए आपको Mac या Xcode की ज़रूरत नहीं -- open-source Swift toolchain Linux पर भी चलती है।

उदाहरण: What is Swift?

markup
print("Swift is a modern programming language")
print("It is safe, fast, and expressive")

Why Swift Was Created

Apple ने Objective-C में long-standing pain points fix करने के लिए Swift introduce किया, जैसे unsafe pointers और verbose syntax।

Swift strong type safety, missing values explicitly handle करने के लिए optionals, और कहीं ज़्यादा साफ़ syntax जोड़ती है, जबकि demanding applications के लिए काफी तेज़ रहती है।

उदाहरण: Why Swift Was Created

markup
// Declare a constant `goals`, set to `["safety", "speed", "expressiveness"]`
let goals = ["safety", "speed", "expressiveness"]
// Loop over `goals`, binding each item to `goal`
for goal in goals {
    // Print "Design goal: \(goal)" to the console
    print("Design goal: \(goal)")
}

Where Swift Is Used

Swift iOS, iPadOS, macOS, watchOS, और tvOS apps को power करती है, लेकिन यह Apple के platforms से आगे server-side frameworks और general scripting में भी बढ़ी है इसके open-source toolchain के कारण।

Companies इसे mobile apps से लेकर backend services तक हर चीज़ के लिए उपयोग करती हैं।

उदाहरण: Where Swift Is Used

markup
// Declare a constant `usedFor`, set to `[("iOS apps", "Instagram, Airbnb"), ("Backend", "Vapor servers"), ("Scripting", "automation tools")]`
let usedFor = [("iOS apps", "Instagram, Airbnb"), ("Backend", "Vapor servers"), ("Scripting", "automation tools")]
for (area, example) in usedFor {
    // Print "\(area): \(example)" to the console
    print("\(area): \(example)")
}

Compiled, Not Interpreted

Python या JavaScript के विपरीत, Swift source code चलने से पहले optimized machine code में ahead of time compile किया जाता है। यह compiler को आपका program execute होने से पहले ही type errors और दूसरी गलतियां पकड़ने देता है, और fast-running binaries produce करता है।

Note: swift file.swift चलाना एक step में compile और run करता है, यही कारण है कि यह scripting जैसा लगता है भले ही Swift compiled है।

उदाहरण: Compiled, Not Interpreted

markup
print("This code is compiled before it runs")
print("The compiler already checked it for errors")
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह मान लेना कि Swift सिर्फ iPhone apps बनाने के लिए काम करती है और इसे plain command-line programs या servers के लिए उपयोग नहीं किया जा सकता।
  2. Swift को Objective-C के साथ confuse करना; Swift अपनी खुद की syntax वाली एक पूरी तरह अलग, नई language है।
  3. यह सोचना कि Swift code को हमेशा Xcode के अंदर चलना चाहिए; यह swift command से एक terminal से भी चल सकता है।
चैप्टर सारांश
  • Swift एक modern, open-source, compiled language है जिसे Apple ने बनाया और 2014 में release किया।
  • यह safe (compile time पर गलतियां पकड़ते हुए), fast (native machine code में compile होते हुए), और expressive होने के लिए design की गई है।
  • Swift iOS/macOS apps के लिए उपयोग होती है, लेकिन server-side code, command-line tools, और scripting के लिए भी।
  • Swift code swift command के साथ एक standalone script के रूप में चल सकता है, बिना एक पूरे app project की ज़रूरत के।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.