Introduction
Welcome to the PersianSwift documentation! PersianSwift is a powerful Swift library that offers a range of functionalities for working with the Persian language. Whether you need to manipulate Persian dates, convert Persian text to English, or handle other language-specific operations, PersianSwift has got you covered.
Installation
Follow the steps below to install PersianSwift in your project:
- Open Xcode and navigate to your project’s directory.
- Go to File > Swift Packages > Add Package Dependency.
- In the search field, enter “PersianSwift” and select the package from the results.
- Specify the desired version or branch, and click Next.
- Choose the target where you want to add PersianSwift, and click Finish.
Usage
After installing PersianSwift, follow the steps below to start utilizing its features:
- Import the
PersianSwift
module into your Swift file:
“`swift
import PersianSwift
“`
- You can now use PersianSwift’s functionalities in your code. Here are a few examples:
“`swift
// Example 1: Convert Persian digits to English
let persianNumber = “۱۲۳۴۵”
let englishNumber = persianNumber.persianDigitsToEnglish // Output: “12345”
// Example 2: Convert Persian date to Gregorian (English) date
let persianDate = “۱۳۹۹/۰۴/۲۰”
let gregorianDate = persianDate.convertToGregorianDate() // Output: “2020-07-10”
// Example 3: Check if a string contains Persian text
let inputText = “آیا این متن حاوی کاراکترهای فارسی است؟”
let containsPersian = inputText.containsPersianCharacters // Output: true
“`
Features
PersianSwift offers a variety of features to simplify Persian language operations. Here are some key features:
- Persian-to-English Conversion: Convert Persian digits to English for easier processing.
- Date Conversion: Convert Persian dates to the Gregorian (English) calendar format.
- Text Manipulation: Check for and manipulate Persian text, such as checking if a string contains Persian characters.
- Customization: Configure PersianSwift settings for your specific needs.
API Reference
Below is a list of the available classes and methods in PersianSwift:
String
: Extensions for working with Persian text.persianDigitsToEnglish
: Converts Persian digits to English.containsPersianCharacters
: Checks if a string contains Persian characters.- More methods…
Date
: Persian-to-Gregorian date conversion.convertToGregorianDate()
: Converts a Persian date to the Gregorian (English) calendar format.convertToPersianDate()
: Converts a Gregorian date to the Persian calendar format.- More methods…
Settings
: PersianSwift configuration settings.digitSystem
: The currently active digit system (Persian or English).- More settings…
Conclusion
Congratulations! You’re now equipped with the knowledge to integrate PersianSwift into your Swift projects and utilize its powerful Persian language functionalities. For more details, refer to the API reference above or explore the PersianSwift GitHub repository.