14. Best Practices va Expert Tips
🚀 Tuist — Mukammal Qo‘llanma & Amaliyot
🏆 Best Practices va Expert Tips
"Expert — bu barcha xatolarni qilib bo'lgan va ulardan saboq olgan odam. Bu darslikda siz ularning tajribasini olasiz!"
1. Loyiha Tuzilmasi Best Practices
✅ TO'G'RI: Modular tuzilma
MyApp/
├── Tuist.swift
├── Tuist/
│ ├── Package.swift
│ └── ProjectDescriptionHelpers/
├── Project.swift
├── Modules/
│ ├── Core/
│ │ ├── Networking/Sources/
│ │ ├── Storage/Sources/
│ │ └── DesignSystem/Sources/
│ └── Features/
│ ├── Home/Sources/
│ ├── Profile/Sources/
│ └── Settings/Sources/
└── App/Sources/
❌ NOTO'G'RI: Barcha kod bitta papkada
MyApp/
├── Project.swift
└── Sources/ ← Barcha kod shu yerda — NOTO'G'RI!
├── HomeView.swift
├── ProfileView.swift
├── NetworkClient.swift
└── ... (100+ fayl)
Qoidalar:
| Qoida | Tushuntirish |
|---|---|
| Modul ≤ 20 fayl | Kattaroq bo'lsa — bo'ling |
| 1 modul = 1 vazifa | NetworkKit faqat network, DesignSystem faqat UI |
| Core ↔ Feature ajratish | Core — platformadan mustaqil, Feature — UI bilan |
| App — yig'uvchi | App hech qanday logika yozmaydi, faqat feature'larni yig'adi |
2. Manifest Best Practices
ProjectDescriptionHelpers Har Doim Ishlating
// ❌ NOTO'G'RI — har bir target 30+ qator
.target(
name: "HomeFeature",
destinations: .iOS,
product: .framework,
bundleId: "com.example.HomeFeature",
deploymentTargets: .iOS("16.0"),
infoPlist: .default,
sources: ["Modules/HomeFeature/Sources/**"],
// ... yana 20 qator
)
// ✅ TO'G'RI — helper bilan 3 qator
.feature(name: "HomeFeature", dependencies: [
.target(name: "CoreNetwork"),
])
BundleId Convention
// ✅ TO'G'RI — izchil naming
"com.company.appname" // App
"com.company.appname.HomeFeature" // Feature
"com.company.appname.CoreNetwork" // Core
// ❌ NOTO'G'RI — tartibsiz
"com.example.myApp"
"dev.tuist.homefeature"
"io.company.network"
Settings — .xcconfig Ishlating
// ✅ TO'G'RI — .xcconfig fayllar
settings: .settings(configurations: [
.debug(name: "Debug", xcconfig: "./xcconfigs/Debug.xcconfig"),
.release(name: "Release", xcconfig: "./xcconfigs/Release.xcconfig"),
])
// ❌ NOTO'G'RI — manifest ichida settings to'plash
settings: .settings(
base: [
"SWIFT_VERSION": "5.9",
"IPHONEOS_DEPLOYMENT_TARGET": "16.0",
"CODE_SIGN_STYLE": "Automatic",
"DEVELOPMENT_TEAM": "ABCDE12345",
// ... yana 20 ta setting
]
)
3. Dependency Best Practices
Interface'ga Bog'laning
// ✅ TO'G'RI — Interface ga bog'lanish
dependencies: [
.target(name: "ProfileInterface"),
]
// ❌ NOTO'G'RI — Source (implementation) ga bog'lanish
dependencies: [
.target(name: "ProfileFeature"),
]
Dependency Soni
Module dependency soni → tavsiya:
0-2 : ✅ Ideal
3-5 : ⚠️ Diqqat
6+ : ❌ Bo'ling!
Circular Dependency
❌ HECH QACHON circular dependency yaratmang:
A → B → A
Tuist buni xato deb beradi:
❌ Error: Found a dependency cycle: A → B → A
Yechim: Interface target orqali ajrating:
A → BInterface
B → AInterface
4. Git Best Practices
.gitignore — SHART!
# ═══════════════════════════════════
# Tuist Generated — HECH QACHON commit qilmang!
# ═══════════════════════════════════
*.xcodeproj
*.xcworkspace
Derived/
# Tuist cache va build
.tuist-bin/
Tuist/.build/
Tuist/Dependencies/
# Xcode
DerivedData/
*.xcuserdata/
*.xcscmblueprint
# macOS
.DS_Store
Branch Strategy
main (production)
└── develop
├── feature/add-payment-module ← Yangi modul
├── feature/update-home-ui ← UI o'zgartirish
└── fix/network-cache-bug ← Bug fix
5. Performance Optimization Tips
Build Time Qisqartirish
| Usul | Ta'sir | Qiyinlik |
|---|---|---|
| Binary Cache | ⭐⭐⭐⭐⭐ | Oson |
| Modullash | ⭐⭐⭐⭐ | O'rtacha |
| Kichik fayllar | ⭐⭐⭐ | Oson |
| Static → Dynamic (dev) | ⭐⭐⭐ | Oson |
| Generics kamaytirish | ⭐⭐ | Qiyin |
Compile Time Optimizatsiya
// ❌ SEKIN — murakkab type inference
let result = array.filter { $0.value > 10 }.map { transform($0) }.reduce(0, +)
// ✅ TEZ — bosqichma-bosqich
let filtered = array.filter { $0.value > 10 }
let mapped = filtered.map { transform($0) }
let result = mapped.reduce(0, +)
// ❌ SEKIN — katta dictionary literal
let dict: [String: Any] = [
"key1": value1, "key2": value2, /* ... 20+ kalit */
]
// ✅ TEZ — bosqichma-bosqich
var dict: [String: Any] = [:]
dict["key1"] = value1
dict["key2"] = value2
6. Xatoliklarni Bartaraf Etish (Troubleshooting)
"Module not found"
❌ No such module 'HomeFeature'
Sabab: Dependency Target.swift da yo'q yoki nomi noto'g'ri.
# Yechim:
tuist clean
tuist install
tuist generate
"Multiple commands produce"
❌ Multiple commands produce '.../Info.plist'
Sabab: Bir nechta target bir xil resource'ga ega.
// Yechim: Har bir target o'z Info.plist ga ega bo'lsin
infoPlist: .extendingDefault(with: [:]) // Tuist o'zi yaratadi
"Signing" xatoligi
❌ Signing requires a development team
Yechim:
settings: .settings(
base: [
"CODE_SIGN_STYLE": "Automatic",
"DEVELOPMENT_TEAM": "ABCDE12345",
]
)
Cache ishlamayapti
# Cache tozalash
tuist clean
# Full reset
rm -rf ~/.tuist/Cache
tuist cache
"Tuist.swift not found"
Sabab: Noto'g'ri papkadan tuist buyrug'i ishga tushirilgan.
Yechim: Tuist.swift bor papkaga cd qiling.
7. Jamoa Bilan Ishlash
Onboarding Checklist
Yangi dasturchi kelganda:
1. [ ] git clone {repo}
2. [ ] brew install tuist (yoki mise install)
3. [ ] tuist install
4. [ ] tuist generate
5. [ ] Cmd+R — ilova ishlaydi! 🎉
Vaqt: ~5 daqiqa (Tuistsiz: ~1 soat)
Code Review Qoidalari
PR da tekshirish kerak bo'lgan narsalar:
✅ Project.swift o'zgargan bo'lsa — dependency graph to'g'ri
✅ Yangi modul qo'shilgan bo'lsa — naming convention
✅ .xcconfig o'zgargan bo'lsa — barcha configuration
✅ Package.swift o'zgargan bo'lsa — versiya compatibility
8. Interview Savollari va Javoblari
Savol 1: Tuist nima va u qanday muammolarni hal qiladi?
Javob: Tuist — Xcode loyihalarini Swift kodi orqali yaratish va boshqarish uchun CLI vosita. U .xcodeproj fayllarni avtomatik generate qiladi va quyidagi muammolarni hal qiladi:
- Git merge conflict'larni yo'qqa chiqaradi
- Binary caching bilan build vaqtini qisqartiradi
- Dependency graph validation qiladi
- Loyiha tuzilmasini standartlashtiradi
Savol 2: Project.swift, Workspace.swift, Tuist.swift farqi nima?
Javob:
Project.swift— bitta Xcode project ta'rifi (target'lar, settings, schemes)Workspace.swift— bir nechta project'ni bitta workspace'ga birlashtirishTuist.swift— root directory marker va global Tuist konfiguratsiya
Savol 3: Static va Dynamic framework farqi nima?
Javob:
- Static — compile vaqtida asosiy binary'ga birlashtiriladi. App launch tez, lekin build sekin.
- Dynamic — runtime'da yuklanadi. Build tez (incremental), lekin app launch sekinroq.
- Tavsiya: Development da dynamic, release da static.
Savol 4: Binary Caching qanday ishlaydi?
Javob: Tuist har bir modul uchun hash hisoblab (source + dependencies + settings), o'zgarganligini aniqlaydi. O'zgarmagan modullar compile qilinmaydi — oldindan yaratilgan .xcframework binary ishlatiladi. Bu build vaqtini 10x gacha tezlashtiradi.
Savol 5: TMA (The Modular Architecture) nima?
Javob: TMA — har bir feature'ni 5 ta target'ga bo'lish patterni:
- Source — asosiy kod
- Interface — public API (protocol'lar)
- Tests — unit testlar
- Testing — mock data
- Example — demo app
Asosiy qoida: Modullar Interface'ga bog'lanadi, Source'ga emas. Bu loose coupling va tez build ta'minlaydi.
Savol 6: Xcode loyihasini Tuist'ga qanday migrate qilasiz?
Javob: Bosqichma-bosqich:
- Scaffold yaratish (Tuist.swift, Project.swift, Package.swift)
- Build settings → .xcconfig (
tuist migration settings-to-xcconfig) - SPM dependencies → Tuist/Package.swift
- Target migration tartibini aniqlash (
tuist migration list-targets) - Target'larni birma-bir migrate qilish (eng kam dependency'dan boshlab)
- Har qadam da build va test tekshirish
- Eski .xcodeproj o'chirish
Savol 7: tuist generate va tuist build farqi?
Javob:
tuist generate— Xcode project/workspace yaratadi. Xcode'da ochib run qilish uchun.tuist build— Project generate qiladi VA terminalda build qiladi (Xcode ochilmaydi). CI/CD uchun ideal.
Savol 8: ProjectDescriptionHelpers nima?
Javob: Tuist/ProjectDescriptionHelpers/ papkasidagi Swift fayllar. Barcha manifest fayllar (Project.swift, Workspace.swift) bu kodlarni import ProjectDescriptionHelpers bilan ishlatishi mumkin. DRY prinsipi — target template'lar, konstantalar, helper function'lar shu yerda yoziladi.
9. Tuist Cheat Sheet
# ═══════════════════════════════════
# ASOSIY BUYRUQLAR
# ═══════════════════════════════════
tuist init # Yangi loyiha
tuist edit # Manifest tahrirlash
tuist install # Dependencies yuklash
tuist generate # Xcode loyiha yaratish
tuist build # Terminaldan build
tuist test # Testlarni ishga tushirish
tuist clean # Cache tozalash
tuist graph # Dependency graph
# ═══════════════════════════════════
# CACHE
# ═══════════════════════════════════
tuist cache # Barcha modullarni cache'lash
tuist cache --dependencies-only # Faqat dependency'lar
# ═══════════════════════════════════
# MIGRATION
# ═══════════════════════════════════
tuist migration settings-to-xcconfig -p X.xcodeproj -x out.xcconfig
tuist migration list-targets -p X.xcodeproj
tuist migration check-empty-settings -p X.xcodeproj
# ═══════════════════════════════════
# GENERATE VARIANTS
# ═══════════════════════════════════
tuist generate # Barcha + Xcode ochish
tuist generate --no-open # Xcode ochmasdan
tuist generate HomeFeature # Faqat bitta modul
# ═══════════════════════════════════
# APP STORE
# ═══════════════════════════════════
tuist generate --no-open
xcodebuild archive -workspace X.xcworkspace -scheme X -archivePath build/X.xcarchive
xcodebuild -exportArchive -archivePath build/X.xcarchive -exportPath build/ipa -exportOptionsPlist Export.plist
Xulosa — Tuist Expert Roadmap
📍 Boshlang'ich
├── tuist init, generate, build
├── bitta Project.swift
└── basic targets
📍 O'rta daraja
├── External dependencies
├── 3-5 modul arxitektura
├── ProjectDescriptionHelpers
└── .xcconfig bilan settings
📍 Yuqori daraja
├── TMA arxitektura (5 target per module)
├── Binary caching
├── Multi-project workspace
├── CI/CD pipeline
└── Xcode loyiha migration
📍 Expert
├── Custom templates va scaffold
├── Plugins yaratish
├── Selective testing
├── Dynamic configuration
├── Performance profiling
└── Jamoani Tuist ga o'rgatish
"Siz bu darslikni tugatdingiz — tabriklaymiz! 🎉 Endi Tuist sizning qurolxonangizda. Uni har kuni ishlatib, har kuni yaxshilang. Expert bo'lishning yo'li — amaliyotdan o'tadi!"
"Remember: Every expert was once a beginner. Keep building, keep learning!" 🚀