- عنوان کتاب: SwiftUI Cookbook Build Modern iOS Apps with Practical Recipes and Hands-On Sample Projects
- نویسنده: Juan C. Catalan
- حوزه: برنامهنویسی IOS
- تعداد صفحه: 952
- زبان اصلی: انگلیسی
- نوع فایل: pdf
- حجم فایل: 10.7 مگابایت
SwiftUI روشی مدرن برای ساخت رابطهای کاربری در تمامی پلتفرمهای اپل است. نحو (syntax) توصیفی آن به ما اجازه میدهد مشخص کنیم که رابط کاربری در هر وضعیت (state) خاص باید چگونه به نظر برسد؛ سپس این فریمورک با تغییر آن وضعیت، صفحه را بهطور خودکار بهروزرسانی و همگامسازی میکند. این کتاب مبانی SwiftUI را پوشش میدهد؛ از نماها (views)، چیدمان (layout) و ناوبری گرفته تا مدیریت وضعیت، ذخیرهسازی دادهها، شبکهسازی، ترسیم، انیمیشن و مصورسازی دادهها. همچنین به ویژگیهایی میپردازد که اپل در iOS 26 و iOS 27 معرفی کرده است، نظیر طراحی «Liquid Glass»، نمای وب (Web View) بومی، ویرایش متن پیشرفته (Rich Text)، کانتینرهای با قابلیت تغییر ترتیب، نمودارهای سهبعدی و فریمورک «Foundation Models». این ویرایش چهارم کاملاً برای iOS 27، Xcode 27 و Swift 6.4 بهروزرسانی شده و متن آن بهطور کامل جدید است. از میان ۵۴ اپلیکیشن نمونهی ارائهشده، تنها دو مورد از ویرایش سوم باقی ماندهاند که آنها نیز برای iOS 27 بهروز شدهاند. من از زمان iOS 3 مشغول ساخت اپلیکیشنهای iOS بودهام و بخش عمدهای از این سالها را صرف طراحی رابطهای کاربری با استفاده از UIKit کردهام. به محض اینکه اپل در سال ۲۰۱۹ از SwiftUI رونمایی کرد، استفاده از آن را آغاز کردم و از سال ۲۰۲۲ در اپلیکیشنهای تجاری (Production) از آن بهره میبرم. امروزه در تمام پروژههایم از SwiftUI استفاده میکنم و پس از هفت سال بهروزرسانیهای سالانه، معتقدم که این بهترین روش (و نه صرفاً جدیدترین روش) برای ساخت اپلیکیشن در پلتفرمهای اپل است. توجه ویژهای به تعامل میان SwiftUI و سایر بخشهای کدِ اپلیکیشن شده است: جریان دادهها (Data Flow) با استفاده از فریمورک Observation و Combine، ذخیرهسازی دادهها با SwiftData، شبکهسازی با الگوی async/await، و همچنین عیبیابی (Debugging)، تحلیل عملکرد (Profiling) و تستنویسی با استفاده از Xcode و ابزار Instruments. این کتاب شامل ۶۱ راهکار عملی (Recipes) است که بر پایه اپلیکیشنهای نمونه و کاربردی تدوین شدهاند و سرشار از تکنیکهایی هستند که من شخصاً در پروژههایم به کار میبرم. با مطالعه این کتاب میآموزید چگونه اپلیکیشنهایی بسازید که هم از نظر بصری جذاب باشند و هم برای همه کاربران (از جمله افراد دارای معلولیت) قابل دسترس؛ این موارد شامل طیف وسیعی از پروژهها، از لیستهای ساده گرفته تا نمودارهای تعاملی و قابلیتهایی مبتنی بر «Apple Intelligence» میشود. هنگام برنامهریزی برای این ویرایش، هدفم این بود که کتاب هم برای کسی که اولین نمای SwiftUI خود را مینویسد مفید باشد و هم برای توسعهدهندهای باتجربه که به دنبال راهکاری برای یک مسئله خاص میگردد. به همین دلیل، با اینکه این کتاب همچنان یک «کتاب دستورالعمل» (Cookbook) است، ۱۵ فصل آن را در سه بخشِ مرحلهبهمرحله تنظیم کردهام: اصول ساخت نماها (Views)، جریان دادهها در یک برنامه، و رابطهای برنامهنویسی (API) پیشرفتهای که باعث متمایز شدن یک برنامه میشوند. اگر در کار با SwiftUI تازهکار هستید، میتوانید کتاب را از ابتدا تا انتها مطالعه کنید؛ چرا که هر بخش بر پایه بخش پیشین خود بنا شده است. اگر توسعهدهندهای باتجربه هستید، میتوانید مستقیماً به سراغ هر فصل یا دستورالعملی (Recipe) که میخواهید بروید؛ ارجاعات متقابل نیز شما را به دستورالعملهایی هدایت میکنند که مفاهیمِ زیربناییِ آن مبحث را معرفی کردهاند. هر دستورالعمل بر مجموعه کوچکی از APIها تمرکز دارد و یک برنامه کاربردیِ عملی پیرامون آنها میسازد؛ بدین ترتیب میتوانید پیش از ترکیب چندین مفهوم در برنامههای خود، هر یک را بهطور کامل درک کنید. من SwiftUI را به همان شیوهای آموزش میدهم که خودم با آن کار میکنم: با باز نگه داشتن «بوم پیشنمایش» (Preview Canvas)، تغییر دادن یک مورد در هر لحظه و مشاهده نتیجه آن. اکثر دستورالعملها از همین روال پیروی میکنند؛ عادتی که امیدوارم شما نیز آن را در پیش بگیرید. این ویرایش همچنین پاسخی است به بازخوردهایی که خوانندگان و منتقدان درباره نسخههای پیشین ارائه دادند. در نسخههای قبلی، گاهی کدها در برخی مراحل کامپایل نمیشدند تا زمانی که در مرحلهای بعدی، بخشِ جاافتاده اضافه میشد؛ اما در این ویرایش، پروژه در پایانِ هر مرحله در وضعیتی قرار دارد که کاملاً قابل کامپایل و اجراست. از آنجا که منتقدان خواسته بودند در یک نگاه متوجه شوند هر مرحله چه خطوطی را به کد اضافه میکند، اکنون در تمام قطعهکدهایی که شامل کدهای مراحل پیشین هستند، خطوط جدید بهصورت «پررنگ» (Bold) مشخص شدهاند. همچنین برای خوانندگانی که میخواهند کار خود را بررسی کنند، مخزن (Repository) همراهِ کتاب اکنون شامل فایلهایی برای هر مرحله است که وضعیت برنامه را در نقاط عطفِ دستورالعمل نشان میدهند؛ قابلیتی که در نسخههای پیشین وجود نداشت. تصمیم گرفتم در این ویرایش بر iOS تمرکز کنم. نسخه قبلی چندین پلتفرم را پوشش میداد، اما به تجربه دریافتهام که توسعهدهندگان در یک محیطِ واحد و منسجم، سریعتر میآموزند. زمانی که بر SwiftUI در iOS مسلط شوید، تطبیق مهارتهایتان با iPadOS، macOS، watchOS، tvOS و visionOS بسیار ساده خواهد بود، زیرا این فریمورک و الگوهای «اعلامی» (Declarative) آن در تمامی پلتفرمهای اپل مشترک هستند. این ویرایش همچنین در زمانی منتشر میشود که هوش مصنوعی در حال دگرگون کردن شیوه کدنویسی ماست. Xcode 27 هوش برنامهنویسی را در فضای کاری ایجاد میکند: میتوانیم از مدلی مانند ChatGPT یا Claude در مورد کد خود بپرسیم، یا وظیفهای را به عاملی بسپاریم که فایلها را ویرایش کند، برنامه را بسازد و خطاهای خود را برطرف کند. من در کار خودم، از جمله در تهیه این کتاب، از دستیاران برنامهنویسی هوش مصنوعی استفاده میکنم، همانطور که در بخش «استفاده از هوش مصنوعی در نوشتن این کتاب» در ادامه این مقدمه توضیح میدهم. آنها من را سریعتر کردهاند، اما درک SwiftUI را کماهمیتتر نکردهاند. هنوز کسی باید تصمیم بگیرد چه چیزی بسازد، قضاوت کند که آیا کد تولید شده صحیح، بهروز و قابل دسترس است یا خیر، و بفهمد که چرا یک نما در لحظه نامناسب بهروزرسانی میشود یا یک لیست stu_ers هنگام پیمایش. آن شخص شما هستید و دستور العملهای این کتاب به شما درک انجام این کار را با اطمینان میدهد. هوش مصنوعی همچنین در برنامههایی که میسازیم ظاهر میشود: فصل آخر ویژگیهای Apple Intelligence را با چارچوبهای Foundation Models و Image Playground به برنامههای SwiftUI اضافه میکند. در طول سالها، من بسیاری از توسعهدهندگان را راهنمایی کردهام و سوالاتی که از من میپرسند به ندرت در مورد عملکرد API است. آنها درباره زمان استفاده از آن و اینکه چرا یک رویکرد بهتر از دیگری است، صحبت میکنند.
SwiftUI is the modern way to build user interfaces for all Apple platforms. Its declarative syntax lets us describe what an interface should look like for any given state, and the framework keeps the screen in sync as that state changes. This book covers the foundations of SwiftUI, from views, layout, and navigation to state management, persistence, networking, drawing, animation, and data visualization, together with the features Apple introduced in iOS 26 and iOS 27, such as the Liquid Glass design, the native web view, rich text editing, reorderable containers, 3D charts, and the Foundation Models framework. This fourth edition is fully updated for iOS 27, Xcode 27, and Swift 6.4, and its text is entirely new. Of its 54 sample apps, only two come from the third edition, and both have been updated for iOS 27. I have been building iOS apps since the days of iOS 3, and I spent most of those years writing user interfaces in UIKit. I started using SwiftUI as soon as Apple released it in 2019, and I have used it in production apps since 2022. Today I use it in every project I work on, and after seven years of annual updates, I consider it the best way to build apps for Apple platforms, not just the newest one. Particular a_ention is given to the interaction between SwiftUI and the rest of an app’s code: data flow with the Observation framework and Combine, persistence with SwiftData, networking with async/await, and debugging, profiling, and testing with Xcode and Instruments. With 61 recipes built around working sample apps and packed with the practices I use in my own projects, you’ll learn how to build visually compelling, accessible apps, from simple lists to interactive charts and features powered by Apple Intelligence. When I planned this edition, I wanted it to work as well for someone writing their first SwiftUI view as for an experienced developer looking for a single recipe. That is why, although it is still a cookbook, I organized its 15 chapters into three progressive parts: the essentials of building views, the flow of data through an app, and the advanced APIs that make an app stand out. If you are new to SwiftUI, you can read the book from beginning to end, and each part builds on the one before it. If you are an experienced developer, you can jump straight to any chapter or recipe, and cross-references point back to the recipes that introduce the concepts it relies on. Each recipe focuses on a small set of APIs and builds a working app around them, so you can understand each concept thoroughly before combining several of them in your own apps. I teach SwiftUI the way I work with it: with the preview canvas open, changing one thing at a time and watching the result. Most recipes follow that rhythm, and it is a habit I hope you will take with you. This edition also responds to what readers and reviewers told me about the previous ones. In earlier editions, some steps did not compile until a later step added the missing piece; in this edition, every step leaves the project in a state that compiles and runs. Reviewers asked to see at a glance which lines a step adds, so those lines are now set in bold in every snippet that shows code from earlier steps. And for readers who want to check their work, the companion repository now includes step files that show each app at the milestones of its recipe, something the previous editions did not have. I chose to focus this edition on iOS. The previous edition covered several platforms, and I have found that developers learn faster in one consistent environment. Once you master SwiftUI on iOS, adapting your skills to iPadOS, macOS, watchOS, tvOS, and visionOS is straightforward, because the framework and its declarative pa_erns are shared across all Apple platforms. This edition also arrives at a time when AI is changing how we write code. Xcode 27 builds coding intelligence into the workspace: we can ask a model such as ChatGPT or Claude about our code, or hand a task to an agent that edits files, builds the app, and fixes its own errors. I use AI coding assistants in my own work, including in preparing this book, as I explain in the Use of AI in the writing of this book section later in this preface. They have made me faster, but they have not made understanding SwiftUI any less important. Someone still has to decide what to build, judge whether the generated code is correct, current, and accessible, and find out why a view updates at the wrong moment or a list stu_ers as it scrolls. That someone is you, and the recipes in this book give you the understanding to do it with confidence. AI also appears inside the apps we build: the last chapter adds Apple Intelligence features to SwiftUI apps with the Foundation Models and Image Playground frameworks. Over the years, I have mentored many developers, and the questions they ask me are rarely about what an API does; they are about when to use it and why one approach is be_er than another. In writing this cookbook, I wanted to answer those questions the way I would explain them to a teammate working on the same project. I hope it helps you enjoy building apps with SwiftUI as much as I do.
این کتاب را میتوانید از لینک زیر بصورت رایگان دانلود کنید:
Download: SwiftUI Cookbook

نظرات کاربران