Search icon
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
iOS 17 Programming for Beginners - Eighth Edition

You're reading from  iOS 17 Programming for Beginners - Eighth Edition

Product type Book
Published in Oct 2023
Publisher Packt
ISBN-13 9781837630561
Pages 604 pages
Edition 8th Edition
Languages
Author (1):
Ahmad Sahar Ahmad Sahar
Profile icon Ahmad Sahar

Table of Contents (34) Chapters

Preface 1. Part 1: Swift
2. Exploring Xcode 3. Simple Values and Types 4. Conditionals and Optionals 5. Range Operators and Loops 6. Collection Types 7. Functions and Closures 8. Classes, Structures, and Enumerations 9. Protocols, Extensions, and Error Handling 10. Swift Concurrency 11. Part 2: Design
12. Setting Up the User Interface 13. Building Your User Interface 14. Finishing Up Your User Interface 15. Modifying App Screens 16. Part 3: Code
17. Getting Started with MVC and Table Views 18. Getting Data into Table Views 19. Passing Data between View Controllers 20. Getting Started with Core Location and MapKit 21. Getting Started with JSON Files 22. Getting Started with Custom Views 23. Getting Started with the Camera and Photo Library 24. Getting Started with Search 25. Getting Started with Collection Views 26. Part 4: Features
27. Getting Started with SwiftData 28. Getting Started with SwiftUI 29. Getting Started with Widgets 30. Getting Started with visionOS 31. Testing and Submitting Your App to the App Store 32. Other Books You May Enjoy
33. Index

Creating sample data

As you saw in Chapter 14, Getting Started with MVC and Table Views, you can use an array as the data source for a table view. You will now create a structure that has an array property containing three sample journal entries.

Click the JournalEntry file in the Project navigator, and type in the following after the JournalEntry class declaration:

// MARK: - Sample data
struct SampleJournalEntryData {
  var journalEntries: [JournalEntry] = []
  mutating func createSampleJournalEntryData() {
    let photo1 = UIImage(systemName: "sun.max")
    let photo2 = UIImage(systemName: "cloud")
    let photo3 = UIImage(systemName: "cloud.sun")
    guard let journalEntry1 =  JournalEntry(rating: 5, title: "Good", body:
    "Today is a good day", photo: photo1) else {
      fatalError("Unable to instantiate journalEntry1")
    }
    guard let journalEntry2 = JournalEntry(rating: 0, title: "Bad", body...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}