Unit 16: Question Bot 2 Flashcards
Cell
in a table view, it displays a single item from the data collection
Data Source
used via table view to find out what information it should display and how it should display it
Table View
a type of UI that displays several items or records in rows and columns on the screen
Additional Notes
Contains a list of messages forming a conversation, messages entered by the user, a “thinking” indicator, and an entry area where the user can type a question
A scrolling list of items is known as a __________
Table view
To create a question, please write this:
Let question = Message(date: Date (), text: “Do you know the way to Cupertino?”, type: .question)
Please check out the diagram on pg. 99
MessageCount (property) should have a value of 1 instead of 0
E.g., let messageCount = 1
Add (question: )
Add (answer: )
messageCount += 1
Index 0 -> question
Index 1 -> answer
Working with Indexes
To show the other questions whilst the app is “thinking”, please replace it with this code:
If index % 2 == 0 {
return Message (date: Date (), text: "Question" \ (index / 2)", type: .question) } else { return Message (date: Date(), text: "Answer \ (index / 2)", type: .answer) }
Exploring the Project
The files that make up the app are collected into groups. You’ll only be working with the files in the Model group for this project. Feel free to explore the other files, but don’t worry if you see things you don’t understand. This project has been organized so you can concentrate just on the areas you’ve been learning about so far.
Here’s a summary of what the other files in the project are for, in the order they’re shown in the project navigator:
UI
Main.storyboard: The interface of the app, including the layout of
the screens.
LaunchScreen.storyboard: The screen displayed when the app is first launched—an empty white screen.
ThinkingCell.swift: A specialized cell for showing the app is thinking.
ConversationCell.swift: A specialized cell for showing a message in
the conversation.
AskCell.swift: A specialized cell for allowing the user to type in a question.
”
Assets.xcassets
The asset catalog holding all of the images used in
the app.
ConversationViewController.swift
The main view controller for the app. This class is responsible for the list view and handling updates when the user asks questions. It’s the most complicated file in the project, and contains a lot of code you haven’t learned about yet.
Model
Details are provided in subsequent cards
AppDelegate.swift
Part of the standard app template, normally used
to handle events such as the app being launched.
Info.plist
Part of the standard app template, holding information
about the app itself.
The main Swift file inside the Model Group
Message.swift
Message.swift
The app will show you a conversation between you and a robot. This file describes the things that can make up a conversation.