You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Notifications You must be signed in to change notification settings
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Go to fileThis is the code repository for iOS 17 Programming for Beginners, Eighth Edition, published by Packt. Unlock the world of iOS development with Swift 5.9, Xcode 15, and iOS 17 – your path to App Store success The author of this book is - Ahmad Sahar
In a world with nearly 2 million apps on the App Store, the demand for skilled iOS developers has never been higher. "iOS 17 Programming for Beginners, Eighth Edition" is your gateway to this lucrative and dynamic field. This hands-on guide is tailored for those who are new to iOS and takes you on a journey from learning the Swift language to crafting your own app and seeing it thrive on the App Store. Our approach is hands-on and practical. Each chapter is designed to be a stepping stone in your development journey, providing step-by-step tutorials, real-life examples, and clear explanations of complex concepts. As you progress, you'll not only be skilled in Swift but also incorporate cutting-edge technologies into your apps. You'll learn how to publish your creations and harness the power of iOS 17 through a straightforward and easy to program example app divided into manageable parts. By the time you've completed this book, you'll possess the skills and knowledge to not only develop and publish captivating apps but also leverage online resources to continually enhance your app development prowess.
This book covers the following exciting features:
If you feel this book is for you, get your copy today!
This book has been completely revised for iOS 17, macOS 14.0 Sonoma, Xcode 15, and Swift 5.9. Part 4 of this book also covers the latest technologies introduced by Apple during WWDC 2023, which are SwiftData, SwiftUI, widgets, and visionOS.
To complete all the exercises in this book, you will need:
To check if your Mac supports macOS 14.0 Sonoma, see this link: https://www.apple.com/my/macos/ sonoma/. If your Mac is supported, you can update macOS using Software Update in System Preferences.
To get the latest version of Xcode, you can download it from the Apple App Store. Most of the exercises can be completed without an Apple Developer account and use the iOS Simulator. If you wish to test the app you are developing on an actual iOS device, you will need a free or paid Apple Developer account, and the following chapters require a paid Apple Developer account:
Instructions on how to get a paid Apple Developer account are in Chapter 27, Testing and Submitting Your App to the App Store.
Chapter 1 serves as a introduction to Xcode, the essential tool for developing iOS applications. Readers are guided through the process of downloading and installing Xcode from the App Store. The chapter provides an in-depth exploration of the Xcode user interface, allowing readers to become familiar with its various components. Practical hands-on experience is emphasized as readers create their first iOS app and execute it within the Simulator. Furthermore, the chapter instructs how to connect an actual iOS device to Xcode using a USB cable, enabling the deployment of the developed app directly onto the device for real-time testing.
Key Insights:
Chapter 2 delves into the fundamentals of the Swift programming language. Readers are introduced to Swift playgrounds, providing an interactive platform to experiment with Swift code and instantly observe the results. The chapter covers the representation and storage of various data types in Swift, including numbers, Boolean values, and strings. Crucial Swift features such as type inference and type safety are explored, enabling concise and error-resistant coding practices. Additionally, readers learn about constants, variables, operators, and how to perform operations on numbers and strings. The chapter emphasizes troubleshooting techniques, teaching readers how to identify and fix errors by utilizing the Debug area and print() statements effectively.
Key Insights:
Chapter 3 equips readers with essential programming concepts, delving into conditional statements and optionals in Swift. Building upon the foundational knowledge acquired in the previous chapters, this section addresses the need for programs to execute different instructions based on specific conditions. Readers gain a deep understanding of how to implement if and switch statements, empowering them to create programs that respond dynamically to varying scenarios. Additionally, the chapter introduces the concept of optionals, addressing the challenge of handling variables that may or may not have a value initially. Through this, readers learn about optional binding, a crucial skill enabling the execution of instructions only if a variable holds a value, enhancing their ability to manage diverse data states effectively.
Key Insights:
Chapter 4 focuses on two vital programming constructs: range operators and loops. Readers delve into understanding the intricacies of range operators, crucial tools for representing a range of values by specifying start and end points. This chapter illuminates the closed and half-open range operators, enabling readers to efficiently define numerical ranges. Additionally, the chapter delves into the diverse loop types: for-in, while, and repeat-while. For-in loops empower programmers to iterate a set of statements for a predetermined number of times, while the while and repeat-while loops provide the flexibility to repeat statements based on specific conditions, enhancing the control flow in Swift programs.
Key Insights:
Chapter 5 delves into fundamental data structures in Swift, namely arrays, dictionaries, and sets, enabling developers to store and manipulate collections of values efficiently. Understanding arrays provides knowledge about managing ordered lists of items, crucial for scenarios like creating shopping lists or storing any sequenced data. Moreover, the chapter delves into dictionaries, which empower programmers to manage unordered key-value pairs, beneficial for applications like contact lists. Lastly, developers learn about sets, offering insights into managing distinct, unordered values, akin to organizing unique elements like genres in a movie list.
Key Insights:
Chapter 6 delves into the essential concepts of functions and closures, enabling you to encapsulate multiple instructions under a single, identifiable name. By structuring your code this way, you enhance readability and maintainability. By the end of this chapter, readers gain a comprehensive understanding of functions, including nested functions, functions serving as return types, and functions employed as arguments. Additionally, they learn about the guard statement, a vital tool for enhancing code reliability. Understanding these foundational concepts is pivotal for any Swift developer aiming to write clear, concise, and maintainable code.
Key Insights:
This chapter introduces classes and structures as tools to consolidate disparate components, allowing developers to group constants and variables into coherent entities. The chapter explores class creation, initialization, and subclassing. It also highlights the distinction between reference types and value types. Furthermore, the chapter introduces enumerations, providing a mechanism to group related values together, enhancing the organization of data within programs. By the chapter's conclusion, readers gain a comprehensive understanding of creating, initializing, and manipulating classes, structures, and enumerations.
Key Insights:
This chapter delves into advanced concepts crucial for robust Swift programming: protocols, extensions, and error handling. Protocols are introduced as essential blueprints, defining methods, properties, and requirements that can be adopted by classes, structures, or enumerations. Extensions are explored as powerful tools to enhance existing types with new functionality, promoting code organization and modularity.
Key Insights:
Chapter 9 delves into the realm of Swift concurrency, a crucial addition introduced in Swift 5.5, enabling developers to create more readable and comprehensible concurrent code. The chapter begins by introducing the fundamental concepts of Swift concurrency, laying the groundwork for understanding asynchronous and parallel programming. An existing app without concurrency is analyzed, highlighting the challenges it faces. The chapter then demonstrates the implementation of concurrency using async/await, offering clear insights into how to enhance app efficiency. Furthermore, the use of async-let is explored, providing developers with the tools to optimize their applications.
Key Insights:
Chapter 10 starts with a detailed tour of the JRNL app's screens and user interactions. The chapter emphasizes hands-on learning by guiding readers through the process of recreating the app's user interface using Interface Builder. Specifically, it covers setting up a tab bar controller scene, configuring button titles and icons, and integrating navigation controllers for seamless navigation between the Journal List and Map screens. By the end of this chapter, readers not only grasp fundamental iOS development terminology but also acquire practical skills in using Interface Builder to configure essential UI elements, setting the stage for further UI development.
Key Insights:
In this chapter, readers delve deeper into building the JRNL app's user interface. Following the groundwork laid in the previous chapter, this section focuses on the Journal List screen. The existing Xcode project is modified to integrate a table view displaying ten empty cells, each representing a potential journal entry. This chapter implements user interactions, such as a button that triggers the display of the "Add New Journal Entry" screen, demonstrating the modal presentation of view controllers. Through this hands-on process, readers gain practical experience in connecting storyboard elements to view controllers, configuring table view cells, and handling modal presentations.
Key Insights:
Chapter 12 marks the culmination of the JRNL app's basic user interface setup. Building upon the groundwork established in the previous chapters, the focus is on integrating the remaining essential screens outlined in the app tour. Specifically, readers learn to configure the Journal Entry Detail screen, which appears when a table view cell in the Journal List screen is tapped. Static table view cells are employed to create a structured layout. Attention is given to the Map screen, where a map view is implemented. Through this chapter, readers master the implementation of segues, static table views, and map views, pivotal elements for any iOS app's user interface.
Key Insights:
Chapter 13 meticulously refines the app's user interface using Interface Builder. This chapter focuses on the intricate adjustments made to the Journal List, Add New Journal Entry, and Journal Entry Detail screens to precisely align with the intended design. The chapter underscores the importance of constraints and precise element positioning, providing readers with the skills to craft polished interfaces compatible across various devices. With these modifications, the app's foundation is set.
Key Insights:
Chapter 14 marks the beginning of Part 3 of the book, where the focus shifts from UI design to app functionality. The chapter delves into the fundamental Model-View-Controller (MVC) design pattern, explaining the intricate interactions between different components of an app. Readers gain insights into creating a table view programmatically, a departure from using storyboards, and understand the nuances between these two approaches. The chapter emphasizes hands-on learning by revisiting the Journal List screen's table view, providing a side-by-side comparison of the programmatic and storyboard-based implementations.
Key Insights:
Chapter 15 follows the foundation laid in the previous chapter by delving into the practical steps needed to populate a table view with data. With the Journal List screen currently displaying empty cells, the chapter focuses on implementing the model objects essential to present a list of journal entries. Readers are introduced to the concept of model objects and their significance in app development. A Swift class is crafted to accommodate journal entry instances, while a structure is established with an array property to store sample journal entries. This array is subsequently employed as the data source for the table view within the Journal List screen.
Key Insights:
Chapter 16 provides crucial insights into data management within view controllers. Building on the foundation set in the previous chapter, readers learn how to effectively pass data from one view controller to another. The chapter starts by guiding readers through the implementation of a view controller for the Add New Journal Entry screen. Through detailed code explanations, readers understand how to pass data from this screen to the Journal List screen. The chapter also covers removing entries from a table view, exploring text field and text view delegate methods, and passing data from the Journal List screen to the Journal Entry Detail screen.
Key Insights:
Chapter 17 delves into the fundamental concepts of working with Core Location and MapKit in iOS app development The chapter commences by enabling users to add their current location to a new journal entry within the Add New Journal Entry screen. Subsequently, a MapViewController class is introduced, configured to display a custom map region centered around the user's location. Furthermore, the JournalEntry class is enhanced to conform to the MKAnnotation protocol, allowing journal entries to be represented as map annotations. Pins are displayed for each journal entry within the specified map region, featuring interactive callouts and buttons that lead users to the Journal Entry Detail screen upon interaction. Lastly, the chapter guides readers in modifying the JournalEntryViewController class to exhibit map snapshots for journal entries.
Key Insights:
Chapter 18 helps readers to begin storing and retrieving user data with JSON files. The problem of newly added journal entries not appearing on the Map screen and the loss of journal entries when quitting the app is tackled through the creation of a singleton, SharedData. This singleton class serves as a centralized data repository, providing journal entry data to both the Journal List and Map screens. To ensure data persistence, the chapter guides readers in modifying the JournalEntry class to be compatible with the JSON format. Methods for saving journal entry data when adding or deleting entries, as well as loading data when the app starts up, are implemented.
Key Insights:
Chapter 19 enhances the JRNL app's functionality by introducing a new user interface element: custom views. The chapter covers the creation of custom views and integrating them into the app's user interface. By the chapter's conclusion, developers have acquired the expertise to design and implement custom views tailored to their specific app requirements, paving the way for more engaging and user-friendly interfaces.
Key Insights:
Chapter 20 continues the development of the JRNL app by focusing on a another new feature: importing photos from a device's camera or photo library. The chapter covers essential steps, such as implementing tap gesture recognizers and configuring image picker controllers. By adhering to the UIImagePickerControllerDelegate protocol, developers learn how to capture photos from the camera or photo library and resize them effectively before integration. By utlizing these techniques, developers can enhance their own applications with photo import functionalities.
Key Insights:
Chapter 21 focuses on enhancing user experience by implementing a search bar on the Journal List screen. This chapter detailed the process of modifying the JournalListViewController class to display the search bar, ensuring that the app responds dynamically to user input. With the completion of the search bar implementation, this chapter marks the conclusion of Part 3. Developers have successfully learned how to implement fundamental features such as interactive image integration, user permissions, and search functionalities. The completion of the JRNL app provides a comprehensive understanding of creating an iOS application. As developers move forward, they are well-equipped to explore advanced topics and incorporate cutting-edge features introduced in iOS 17.
Key Insights:
Chapter 22 focuses on optimizing the JRNL app for larger screens, such as those on iPads or Macs. This transformation involves replacing the existing table view with a collection view in the Journal List screen. The chapter explores the dynamic adaptation of the app's interface based on size classes, allowing for varying numbers of columns and flexible collection view cell sizes. By the end of this chapter, developers are equipped with the knowledge of collection views, understanding how to utilize collection view delegate and data source protocols, and adeptly modifying the app's interface based on diverse screen sizes.
Key Insights:
In Chapter 23, developers are introduced to Apple's SwiftData framework, unveiled at the 2023 World Wide Developer Conference. Unlike previous methods requiring external editors, SwiftData allows developers to define and manipulate data models directly using Swift code. First, developers learn about the framework's core components and understand its advantages. They then modify the existing JournalEntry class to align with SwiftData requirements and adapt the JournalListViewController class accordingly. Through this process, developers implement SwiftData functionalities, enabling the app to read, write, and delete journal entries persistently. By the chapter's end, developers acquire essential skills to integrate SwiftData into their own applications, ensuring data persistence and continuity across app launches.
Key Insights:
Chapter 24 delves into SwiftUI, Apple's cutting-edge technology for app development. Unlike the traditional approach of storyboards, SwiftUI employs a declarative Swift syntax and integrates seamlessly with new Xcode design tools, enabling developers to create user interfaces more intuitively. The chapter guides readers through the process of building a simplified version of the JRNL app using SwiftUI. By creating a new SwiftUI Xcode project, developers learn to construct the Journal List and Journal Entry Detail screens. They start by configuring SwiftUI views for the Journal List, integrate model objects, and establish smooth navigation between screens. Additionally, the chapter demonstrates the integration of MapKit for SwiftUI, teaching developers how to incorporate dynamic map views within the Journal Entry Detail screen.
Key Insights:
In this chapter, developers are introduced to widgets through Apple's WidgetKit framework. WidgetKit, unveiled during WWDC 2020, has expanded its reach to new platforms including Mac desktops, iPad Lock screens, iPhone StandBy mode, and the Apple Watch Smart Stack. The chapter guides readers through the process of creating a widget for their JRNL project, enabling users to access relevant content directly from their device's Home and Lock Screens. The customization aspect is explored, allowing developers to tailor the widget's appearance according to their app's aesthetic.
Key Insights:
In this chapter, developers are introduced to Apple's visionOS platform, unveiled during the World Wide Developer Conference in 2023. visionOS powers the Apple Vision Pro, a mixed-reality headset, revolutionizing app development through spatial computing. Spatial computing redefines user interaction, immersing apps within a virtual space where digital elements blend with the real world. Users navigate this realm using methods such as eye tracking, hand gestures, and voice input. The chapter guides developers through the process of adapting their app to run on visionOS, emphasizing the importance of handling platform differences in the codebase. Developers learn techniques to enhance their app's appearance for visionOS and integrate 3D objects using SwiftUI and UIKit.
Key Insights:
In the final chapter of the book, readers are guided through the crucial process of testing and submitting their apps to the App Store. The chapter emphasizes the transition from testing apps on personal devices to the formal submission process required for public availability on the App Store. Practical insights are provided on conducting internal and external testing, ensuring the app's functionality and user experience are thoroughly evaluated. By the end of this chapter, readers are well-equipped with the knowledge and skills needed to test, submit, and manage their apps on the App Store.
Key Insights:
You can get more engaged on the discord server for more latest updates and discussions in the community at Discord
If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost. Simply click on the link to claim your free PDF. Free-Ebook
We also provide a PDF file that has color images of the screenshots/diagrams used in this book at GraphicBundle
Ahmad Sahar is a trainer, presenter, and consultant at Tomafuwi Productions, specializing in conducting training courses for macOS and iOS, macOS Support Essentials certification courses, and iOS Development courses. He is a member of the DevCon iOS and MyCocoaHeads online communities in Malaysia and has conducted presentations and talks for both groups. In his spare time, he likes building and programming LEGO Mindstorms robots.