You have a request ? Contact Us Join Us

Working with Data in iOS | Coursera Quiz Answers

Coursera: Meta iOS Developer Certificate. Get answers for "Working with Data in iOS" quizzes and exams. Up-to-date, reliable, and comprehensive.
Estimated read time: 51 min
Coursera: Working with Data in iOS
Working with Data in iOS | Coursera Meta

This course provides an introduction to the essential principles of data handling in iOS. You will gain a deeper understanding of API processes and concepts, examine data formats that facilitate data transfer between servers and devices, and learn how to manage data in Swift using Core Data. By the conclusion of this course, you will be able to demonstrate a practical understanding of how Swift applications interact over the web, implement asynchronous programming techniques in Swift, and employ various methods to effectively use the Core Data framework in a Swift application. Designed for intermediate learners aiming to prepare for a career in iOS development, this course requires an advanced grasp of Swift programming and a working knowledge of APIs.


Notice!
Always refer to the module on your for the most accurate and up-to-date information.


Module Quiz: Introduction to REST APIs

1. Select the name that follows best practice for naming an API URI.
  • /customers/{user id}/phoneNumber
  • /customer/16/phoneNumber
  • /Customer/phoneNumber
  • /customers/16/phone number
2. Which of the following is a recommended approach when implementing data filtering in API design?
  • Using a query string parameter.
  • Using a request body.
  • Using a custom header.
  • Using a separate API endpoint.
3. What are the key differences between the HTTP PUT and PATCH methods?
  • PUT can update multiple resources at once, while PATCH can only update one at a time.
  • PUT is used for creating new resources, while PATCH is used for updating existing ones.
  • PUT requires the client to send a complete representation of the resource, whilePATCH only requires the client to send the changes.
4. What is the difference between authentication and authorization in terms of securing a project?
  • Authentication checks if the user can enter the system while authorization checks if the authenticated user has the appropriate privilege to perform a task.
  • Authentication checks if the user has the appropriate privilege to perform a task while authorization checks if the user can enter the system.
  • Both authentication and authorization perform the same functions and the terms are used interchangeably.
5. What is the difference between HTTP status codes 4xx and 5xx in terms of HTTP request responses?
  • 4xx status codes indicate successful requests, while 5xx status codes indicate unsuccessful requests.
  • 4xx status codes indicate server side errors, while 5xx status codes indicate client side errors.
  • 4xx status codes indicate client side errors, while 5xx status codes indicate server side errors.
6. When requesting XML content from a server, which of the following headers in the HTTP request are valid for the Accept header?
  • application/xml
  • html/xml
  • application/xhtml
  • html/xhtml
7. Which of the following statements about Insomnia is true?
  • Insomnia is a RESTful web service.
  • Insomnia is a programming language used for server side web development.
  • Insomnia is a browser extension used for creating and managing HTTP requests.
  • Insomnia is a REST API client used to test and debug RESTful APIs.
8. Which of the following statements best describes the role of authentication in a REST API?
  • REST API requires clients to authenticate using a client certificate.
  • REST API stores user authentication data on the server.
  • REST API uses encryption to secure sensitive data in transit.
  • REST API employs a stateless authentication mechanism.
9. What are the benefits of using a REST API for system integration, and how does it handle resources and state information?
  • REST API utilizes standard HTTP methods, making it easy to integrate with different systems and programming languages.
  • REST API manages state information using sessions and cookies.
  • REST API requires a specific data format for resource representation, such as XML or JSON.
10. What does the HTTP 404 status code signify when it communicates to a client?
  • The server could not find the requested resource.
  • The server encountered an error while processing the request.
  • The client's request was invalid and could not be processed by the server. 

1. True or False: Special characters like "I" or "^" are recommended when defining your endpoints to improve security. 
  • True 
  • False 
2. Which of the following is a recommended approach when implementing data filtering in API design?
  • Using a query string parameter.
  • Using a request body.
  • Using a custom header.
  • Using a separate API endpoint.
3. Which of the following statements describe differences between HTTP PUT and PATCH methods? Select all that apply.
  • A PUT call replaces the complete resource, while the PATCH call only updates some parts.
  • A PATCH request deals with a single record. 
  • A PUT request can deal with multiple resources.
4. What is the difference between authentication and authorization in terms of securing a project?
  • Authentication checks if the user has the appropriate privilege to perform a task while authorization checks if the user can enter the system.
  • Authentication checks if the user can enter the system while authorization checks if the authenticated user has the appropriate privilege to perform a task.
  • Both authentication and authorization perform the same functions and the terms are used interchangeably.
5. When designing an API, which of the following HTTP status codes should be returned when a resource is not found?
  • 400
  • 200
  • 404
  • 500
6. Which of the following are valid Accept headers for requesting XML content? Select all that apply.
  • application/xml
  • text/xml
  • code/xml
  • application/x xml 
  • application/xml content
7. Which of the following statements are valid for Insomnia? Select all that apply. 
  • Insomnia can send different types of payloads.
  • Insomnia is a REST API Client.
  • Insomnia has a command line tool.
  • Insomnia has a mobile client.
  • Insomnia is cross platform. 
8. What is the primary purpose of authentication in a REST API?
  • To verify the identity of the client and provide access to protected resources.
  • To store client state information on the server.
  • To establish a secure connection between the client and server.
  • To encrypt data in transit between the client and server.
9. What are the main advantages of using REST API in application development, and how does it handle representation of resources and states?
  • REST API requires the use of XML for its simplicity and versatility.
  • REST API promotes a tightly coupled system design, where the server and the client are inseparable.
  • REST API uses standard HTTP methods, such as GET, POST, PUT, and DELETE, to perform operations on various systems.
10. What does the HTTP 404 status code signify when it communicates to a client?
  • The server could not find the requested resource.
  • The client's request was invalid and could not be processed by the server.
  • The server encountered an error while processing the request.

Module Quiz: REST APIs

1. What is the purpose of the URLSession data task in fetching images using Swift?
  • To store image data in memory.
  • To convert JSON data into Swift objects.
  • To represent image files using the UIImage class.
  • To download and retrieve image data from a server.
2. What is JSON, and how is it used in Swift?
  • A protocol used to secure network communications.
  • An object oriented database used for storing and retrieving data.
  • A data format used to structure and transmit data from a server to an application.
  • A programming language used for creating mobile apps.
3. Which of the following best describes the main use case of JSON format?
  • Creating graphical user interfaces for mobile applications.
  • Storing and retrieving data from an object oriented database.
  • Structuring and transmitting data between a server and an application.
4. What is the primary use of URLSession in Swift?
  • To manage different HTTP requests and data transfer tasks.
  • To create and manage database connections.
  • To manage user sessions and authentication tokens.
5. What is the role of URLSessionTask in the URL session API of Swift?
  • To provide a common interface for creating, managing, and executing tasks that transfer data to or from a server.
  • To convert data between different data formats.
  • To create a network connection between the device and server.
6. Which of the following URLSession methods creates a URLSessionDataTask?
  • dataTask
  • createDataTask
  • newDataTask
7. True or False: When creating a new URLSessionTask, you must retain a reference to it.
  • True
  • False
8. What will the output of the following code be?
let session = URLSession.shared
let task = session.dataTask(with: URL(www.littleLemon.com)!) { (data, response, error) in
    if let error = error {
        print("Error: \(error)")
    } else {
        print("Task completed")
    }
}
task.resume()
  • Code will not run due to an error.
  • Nothing will output to the console.
  • Task completed
9. Can the following JSON String be decoded into the given Swift object as is? 
let jsonString = """
{
 "username": "jappleseed"
}
"""
struct User: Decodable {
 let username: String
}
  • Yes, the full_name key will be automatically available in the Swift object.
  • No
  • Yes, but the data will be missing.
  • Yes
10. What is the difference between JSONSerialization and JSONDecoder in Swift?
  • JSONDecoder is used to encode and decode JSON data, while JSONSerialization is only used to decode JSON data into Swift objects
  • JSONSerialization is used to encode and decode JSON data, while JSONDecoder is only used to decode JSON data into Swift objects.
  • There is no difference; they both serve the same purpose of encoding and decoding JSON data.

1. A ______ is a data task that downloads files such as images, as data that will be stored into memory.
  • UIImage
  • URLSession
  • Decodable
2. What is the purpose of JSON in iOS development?
  • To optimize the performance of mobile apps.
  • To create user interfaces for mobile apps.
  • To exchange data between servers and devices in a structured format.
  • To perform server side scripting for web applications.
3. Which of the following best describes the main use case of JSON format?
  • Structuring and transmitting data between a server and an application.
  • Storing and retrieving data from an object oriented database.
  • Creating graphical user interfaces for mobile applications.
4. What is the primary use of URLSession in Swift?
  • To manage user sessions and authentication tokens.
  • To manage different HTTP requests and data transfer tasks.
  • To create and manage database connections.
5. Which of the following statements best describes the functionality of URLSessionTask in Swift?
  • It is a class used for parsing JSON data received from a server.
  • It is a data structure used for storing URL request information.
  • It provides methods for transferring data between a client and a server using a URL session.
6. Which of the following URLSession methods creates a URLSessionDownloadTask?
  • createDownloadTask
  • newDownloadTask
  • downloadTask
7. True or False: When creating a new URLSessionTask, you must retain a reference to it.
  • True
  • False
8. What will the output of the following code be? 
task.resume()
}
   }
    print("Task completed")
   } else {
    print("Error: \(error)")
   if let error = error {
let task = session.dataTask(with: URL(string: "www.littleLemon.com")!) { (data, response, error) in
let session = URLSession.shared
  • Nothing will output to the console.
  • Code will not run due to an error.
  • Task completed
9. Can the following JSON String be decoded into the given Swift object as is?
let jsonString = """
{
 "username": "jappleseed"
}
"""
struct User: Decodable {
 let username: String
}
  • Yes, the username key will be automatically available in the Swift object.
  • Yes
  • No
  • Yes, but the data will be missing.
10. What Swift protocol must be implemented to decode JSON data using the JSONDecoder?
  • Decoding protocol
  • Decodable protocol
  • Decoder protocol

Module Quiz: Data in Swift

1. Suppose your data model contains two entities; Dessert and Customer. Dessert contains properties called name, size, and price, and a one to many relationship with Customer called consumedBy. Customer has a property called fullName and an inverse one to many relationship with Dessert.
Let’s say Little Lemon wants to create a new entry in the Dessert entity for their anniversary dessert and assign it to a customer called John Doe.
Which code will accomplish this? 

  • let customer = Customer(context: viewContext)
    customer.name = "John Doe"
    let profiterole = Dessert(context: viewContext)
    profiterole.name = "Anniversary Surprise Dessert"
    profiterole.size = "Special"
    profiterole.price = 3.99
    profiterole.consumedBy = customer
  • let customer = Customer(context: viewContext)
    customer.fullName = "John Doe"
    let profiterole = Dessert(context: viewContext)
    profiterole.name = "Anniversary Surprise Dessert"
    profiterole.size = "Special"
    profiterole.price = 3.99
    profiterole.consumedBy = [customer]
  • let customer = Customer({context: viewContext})
    customer.name = "John Doe"
    let profiterole = Dessert({context: viewContext})
    profiterole.name = "Anniversary Surprise Dessert"
    profiterole.size = "Special"
    profiterole.price = 3.99
    profiterole.consumedBy = {{customer}}
2. Which of the following is one of the main Core Data functionalities?
  • Allowing communication between different databases within an application.
  • Allowing communication between the user interface and the network.
  • Restricting communication between the user interface and the database.
  • Allowing bi directional communication between the user interface and the database.
3. In Core Data, what is a one to many relationship?
  • A relationship between two entities where each instance of the first entity can be related to only one instance of the second entity.
  • A relationship between two entities where one instance of the first entity can be related to multiple instances of the second entity. 
  • A relationship between three entities where each instance of the first entity can be related to multiple instances of the second and third entities.
  • A relationship between two entities where one instance of the first entity can only be related to one instance of the second entity.
4. How does reading and writing to Core Data work?
  • All reading and writing to Core Data happens through an NSManagedObjectContext. That’s correct! The NSManagedObjectContext is responsible for tracking changes to managed objects and persisting those changes to the persistent store.
  • Reading and writing to Core Data happens through an NSPersistentStoreCoordinator.
  • Reading and writing to Core Data happens through an NSManagedObjectModel.
  • Reading and writing to Core Data happens directly to the persistent store.
5. What are the advantages of creating your own NSManagedObject classes? Select all that apply.
  • You can make calls that are not possible without custom classes.
  • You can customize and optimize read and write operations and save time typing.
  • You can make the code clear.
6. What is the primary function of a Core Data context?
  • The primary function of a Core Data context is to display data to the user interface.
  • The primary function of a Core Data context is to manage network requests for data.
  • To manage a collection of managed objects and track changes made to them, including persisting those changes to a persistent store.
  • The primary function of a Core Data context is to execute fetch requests on the managed object model.
7. Which of the following statements accurately describes a Core Data entity?
  • A Core Data entity is a subclass of the NSManagedObject class.
  • A Core Data entity is a subclass of the NSObject class.
  • A Core Data entity is a subclass of the NSManagedObjectModel class.
  • A Core Data entity is a subclass of the UIViewController class.
8. Which of the following statements is true? Select all that apply:
  • Before creating custom classes for NSManagedObject entities, you must disable their Codegen properties in the Data Model Editor.
  • Core Data faults are objects that are duplicates of regular objects retrieved from an entity. 
  • There are three phases required to create a Core Data context and pass it to a view: creating the context in the main app struct, passing it to the view and retrieving it in the receiving view.
9. What does a one to one relationship between two Core Data entities mean?
  • Multiple objects in an entity link to multiple objects in another entity.
  • One object in an entity links to multiple objects in another entity.
  • Multiple objects in an entity link to one object in another entity.
  • One object in an entity links to exactly one object in another entity.
10. Suppose you have a list of all desserts in a Dessert entity that you would like to retrieve in alphabetical order. Which of the following would be the correct syntax?
 @FetchRequest(
  sortDescriptors: [
  NSSortDescriptor(key: "name",
        ascending: true,
        selector: #selector(NSString.localizedCaseInsensitiveCompare))
  ],
  animation: .default
)
private var desserts: FetchedResults<Dessert>

@FetchRequest(
  sortDescriptors: [
    NSSortDescriptor(key: "name", 
            ascending: false, 
            selector: #selector(NSString.localizedCaseInsensitiveCompare))
  ], 
  animation: .default
private var desserts: FetchedResults<Dessert>

@FetchRequest(
  sortDescriptors: [
    NSSortDescriptor(keyPath: \Dessert.name, ascending: true)
  ],
  animation: .default
)
private var desserts: FetchedResults<Dessert>


Final Graded Quiz: Working with Data in iOS

1. What modifier should you use in a View to run a code asynchronously to query a REST API from a remote server?
  • onAppear
  • task
  • viewDidAppear
2. Which of the following is true for Core Data relationships?
  • They are used to establish links to other entities.
  • They have their own attributes.
  • They are used to store data like names, sizes, and prices.
3. Which option creates a new entry on a Core Data entity?
  • let newDessert = Dessert(context)
  • let newDessert = Dessert(view)
  • let newDessert = Dessert(context: viewContext)
4. Which option correctly sets a one to one relationship in code?
  • newDish.fromLocation = [location]
  • newDish.fromLocation = "location"
  • newDish.fromLocation = location
5. What is the class that groups together HTTP requests like a browser tab?
  • URLSessionTask
  • NSRequests
  • URLSession
6. Which is true for the @FetchRequest API? Select all that apply:
  • It saves and retrieves data from the database.
  • You connect it to a @Binding variable and you can use it to retrieve data from a Core Data database.
  • It connects the database to the interface in real time.
7. What are compound predicates used for?
  • They are used to perform complex filtering.
  • They are used to perform complex mathematical operations like compound interest, for example.
  • They are used to perform complex sorting.
8. Which is true for sort predicates? Select all that apply.
  • They can be indifferent to uppercase and lowercase characters.
  • Multiple sort descriptors can be combined to perform complex sorting involving multiple entities.
  • Multiple sort descriptors can be combined to perform complex sorting involving just one entity.
9. Which of the following is true for filtering and sorting Core Data?
  • You must sort an entity first if you want to filter it.
  • You must filter an entity first if you want to sort it.
  • Sorting and filtering can happen simultaneously, using simple or complex predicates and sort descriptors.
10. Which is true for NSSortDescriptors or NSPredicates?
  • NSSortDescriptors can be combined to perform complex sorting using NSCompoundSort elements.
  • The %K in the predicate.
    NSPredicate(format: "(%K CONTAINS...
    Is used to replace a variable or property.
  • Used in an NSSortDescriptor, the compare method caseInsensitiveCompare performs a case insensitive comparison that is diacritic insensitive.
11. What is the purpose of the GET method in HTTP?
  • The GET method is used to retrieve data from the server without changing any data from the resource.
  • The GET method is used to authenticate users on the server.
  • The GET method is used to update data on the server.
  • The GET method is used to delete data from the server.
12. Which of the following is the correct naming convention for an API route?
  • /api/getUsersData
  • /api/users
  • /api/user/12345/getUserInfo
  • /api/fetch_user
13. What is the purpose of using HMAC in securing APIs?
  • To store user credentials in a database.
  • To check if the API call is coming from an authentic source.
  • To protect against unauthorized access from specific IP addresses.
  • To encrypt the data being transported over the internet.
14. What HTTP status code is returned when a user tries to access personal information they are not authorized to view?
  • 403   Forbidden
  • 404   Not Found
  • 401   Unauthorized
  • 200   OK
15. Which of the following reflects the order of events in the API request lifecycle?
  • Request, Routing, Processing, Response 
  • Processing, Request, Response, Routing
  • Response, Processing, Request, Routing
  • Response, Request, Routing, Processing 
16. What is the main purpose of Core Data in connecting the database with the user interface in iOS app development?
  • To manage the data model layer of an application and provide a persistency for data. 
  • To store user interface tasks in the database.
  • To create a direct connection between the database and user interface without any intermediate layers.
  • To manage the model layer objects in the user interface.
17. What is a REST API?
  • A REST API is an architectural style for designing APIs for your project that provides an easy way to communicate with the server and access the data that powers your application.
  • A REST API is a type of API that can only be accessed by developers who are familiar with its constraints.
  • A REST API is a type of API that allows developers to access back end data without any constraints.
  • A REST API is a type of API that is only used for creating production ready APIs in a short amount of time.
18. Which of the following statements is true regarding the POST request in API calls?
  • It doesn't require an HTTP request body. Instead, the API endpoint will create a new resource based on the URL parameters.
  • It can be used to create multiple resources with a single POST call, which is considered a best practice.
  • It always comes with an HTTP request body containing XML data. If the data is valid, the API endpoint will update the existing resource based on this data.
  • It always comes with an HTTP request body containing JSON or Form URL encoded data, which is also called a payload. If the data is valid, the API endpoint will create a new resource based on the data.
19. What is the primary purpose of authentication in a REST API?
  • To prevent unauthorized access to resources.
  • To encrypt data transmitted over the network.
  • To ensure that data is transmitted in a specific format.
  • To identify the user making the API request.
20. Which of the following statements is true about the difference between a PUT and a PATCH call?
  • A PATCH call replaces the complete resource, while a PUT call only updates some parts.
  • Both PUT and PATCH calls replace the complete resource.
  • A PUT call replaces the complete resource, while a PATCH call only updates some parts.
  • There is no difference between a PUT and a PATCH call.
21. What is the URLSession class in iOS?
  • URLSession is a class in iOS that provides everything developers need to make complex HTTPS networking requests.
  • URLSession is a class in iOS that provides everything developers need to make complex HTTP networking requests.
  • URLSession is a class in iOS that provides everything developers need to make simple HTTP networking requests.
  • URLSession is a class in iOS that provides everything developers need to make simple HTTPS networking requests.
22. What is the purpose of using JSONDecoder() and .decode() in the following code snippet?
  • let recipe = try! JSONDecoder().decode(Recipe.self, from: jsonData)
  • To encode a Recipe object into JSON data.
  • To convert JSON data into a binary format.
  • To read the contents of a JSON file as plain text.
  • To decode JSON data in jsonData and map it to a Recipe object.
23. What does the container.viewContext.automaticallyMergesChangesFromParent property do in the PersistenceController struct?
import CoreData
struct PersistenceController {
 static let shared = PersistenceController()
 let container: NSPersistentContainer
 init(inMemory: Bool = false) {
 container = NSPersistentContainer(name: "CoreDataState")
 if inMemory {
 container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
 }
 container.loadPersistentStores(completionHandler: { (storeDescription, error) in
 if let error = error as NSError? {
 fatalError("Unresolved error \(error), \(error.userInfo)")
 }
 })
 container.viewContext.automaticallyMergesChangesFromParent = true
 }
}
  • The container.viewContext.automaticallyMergesChangesFromParent property is used to manage in memory data stores in the Core Data framework.
  • The container.viewContext.automaticallyMergesChangesFromParent property disables automatic merging of changes made in the parent context with the view context.
  • The container.viewContext.automaticallyMergesChangesFromParent property automatically merges changes made in the parent context with the view context.
  • The container.viewContext.automaticallyMergesChangesFromParent property is used to initialize the Core Data stack in the PersistenceController struct.
24. What is the purpose of NSSortDescriptor in Core Data?
  • To specify the sort order and criteria for fetching data from the Core Data persistent store.
  • To define the format and structure of the data stored in the Core Data persistent store.
  • To define the relationships between entities and attributes in the Core Data object graph.
25. What is the Little Lemon team's preferred method of authentication when securing its API?
  • Digest based authentication
  • HMAC based authentication
  • Token based authentication
  • Basic authentication
26. What is a recommended approach for using verbs in naming REST API endpoints in Swift?
  • Avoid using verbs to represent resources, as it can be confusing.
  • Use verbs in conjunction with nouns to describe the action being performed by the endpoint.
  • Use verbs to represent resources, as it can make endpoint names more unique.
  • Use only nouns in endpoint names, as it makes them more intuitive to understand.
27. What is Hashable in iOS development?
  • Hashable is a library in Swift that allows for easy manipulation of audio and video files.
  • Hashable is a protocol in Swift that allows for efficient storage and retrieval of values in a set or dictionary.
  • Hashable is a framework in Swift that allows for easy integration of machine learning models.
  • Hashable is a class in Swift that allows for easy handling of networking tasks.
28. What format should the data be in to display the menu items in the Little Lemon app?
  • XML representing a nested structure
  • CSV representing a table structure
  • Plain text representing a list
  • JSON representing an array of objects
29. When an API needs time to process a request and cannot instantly deliver the result, what status code can the API developer use to keep returning until the result is ready?
  • 200
  • 102
  • 404
  • 500
30. What is the purpose of versioning in REST API development?
  • To ensure the client making the request does not receive potential bugs from unwanted code changes.
  • To provide a way to filter large result sets and rearrange them in ascending or descending order.
  • To limit the number of times someone can call your API in a period of time.
  • To reduce the load on your database related API calls by caching results.

Related Articles

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.