← Back to Swift Course | Chapter 14: Standard Library & Best Practices | Lesson 5 of 7

Swift Package Manager का परिचय

Swift Package Manager एक tool है जो आपके project के code को organize करता है और इसे काम करने के लिए चाहिए कोई बाहरी libraries download करता है।
Syntax
swift
swift package init --type executable
swift build
swift run
swift test

Initializing a New Package

swift package init एक नया package skeleton बनाता है, जिसमें एक Package.swift manifest और एक starter source file शामिल है।

उदाहरण: Initializing a New Package

bash
swift package init --type executable

⚠️ Run this in your own terminal or Node.js environment.

Building and Running a Package

swift build किसी package के सभी targets compile करता है, और swift run build करता है (अगर ज़रूरत हो) और फिर इसका main executable target execute करता है।

उदाहरण: Building and Running a Package

bash
swift build
swift run

⚠️ Run this in your own terminal or Node.js environment.

Running Tests

swift test package के manifest में declared सभी test targets compile और चलाता है, pass/fail results report करते हुए।

उदाहरण: Running Tests

bash
swift test

⚠️ Run this in your own terminal or Node.js environment.

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. बिना एक Package.swift manifest file वाले folder में swift build या swift run चलाने की कोशिश करना; SPM को यह जानने के लिए यह file चाहिए कि project कैसे build करना है।
  2. किसी package के products (जो दूसरे packages import कर सकते हैं) को इसके targets (असल में compile हो रहे source modules) के साथ confuse करना।
  3. यह भूल जाना कि swift test convention से specifically Tests पर खत्म होने वाला एक target ढूंढता है, package के testing setup से मेल खाते हुए।
चैप्टर सारांश
  • swift package init एक नया package scaffold करता है, एक Package.swift manifest generate करते हुए।
  • Package.swift package का नाम, dependencies, targets, और products declare करता है।
  • swift build package compile करता है, और swift run एक executable target build और execute करता है।
  • swift test package के test targets चलाता है।
🔒

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.