Lists: The Data Model & Linking the UI to Code
Master iOS Data Models and UI Connections
Core iOS Development Skills You'll Build
UI-Code Connections
Learn to link interface elements with code files using outlets and actions. Master the connection process for multiple view controllers.
Data Model Design
Create robust class structures for lists and list items. Implement failsafe initializers and automatic sorting mechanisms.
Clean Code Practices
Remove unnecessary Xcode-generated code and implement proper MARK comments for better code organization and maintainability.
Tutorial Implementation Roadmap
Project Setup
Launch Xcode and open the Lists.xcodeproj file from previous exercises
Code Cleanup
Remove unnecessary generated code from view controllers and table view cells
UI Connections
Connect interface elements to code using outlets and actions for both screens
Data Model Creation
Build List and ListItem classes with proper initialization and sorting
Complete exercises 5A-5B before proceeding. If you haven't done the previous exercises, navigate to Desktop > Class Files > yourname-iOS App Dev 2 Class > Lists Ready for Data Model to access the starter project.
Begin with the text field connection, which will capture user input for new list names. In the Storyboard, ensure the Lists View Controller's Add new list text field is visible and accessible. Hold the Control key (or hold the Right mouse button) and drag from the text field directly to the Swift file, positioning your cursor immediately below this line:
class ListsVC: UIViewController {Configure the connection parameters in the popup dialog with these precise settings:
| Name: | newListNameTextField (Case sensitivity is critical in Swift!) |
| Type: | UITextField |
| Storage: | Weak |
Finalize the connection by clicking Connect (or pressing Return).
Congratulations! You've established your first outlet connection. The descriptive naming convention (newListNameTextField) follows iOS development best practices—specific, purposeful names that immediately convey functionality to any developer reading your code.
Create the Table View outlet, which your code will reference for dynamic content updates. Hold Control and drag from the Table View to your Swift code, positioning the cursor to create a new line immediately after:
@IBOutlet weak var newListNameTextField: UITextField!Set the Name parameter to listsTableView in the connection dialog and click Connect.
The Plus (+) button requires special handling because it triggers user actions rather than simply displaying data. When users tap this button to add new lists, your app must execute specific logic—this necessitates creating an action connection instead of an outlet.
Create the action connection by holding the Control key and dragging from the Plus button to your Swift file. Position your cursor beneath the viewDidLoad method's closing curly brace (}) to maintain proper code organization.
Configure the action connection with these specific parameters:
| Connection: | Action (This setting is crucial—don't overlook it!) |
| Name: | addListButtonTapped |
| Type: | Any |
Press Return to complete the action connection. Consider organizing your code spacing now for improved readability—professional iOS developers maintain consistent formatting throughout their projects.
Transition to the Table View Cell connections. In the Storyboard, click directly on the List Name label (targeting the label itself, not its background container) to select it precisely.
Switch to the appropriate file without revealing the Project Navigator. Navigate to the top of the current ListsVC.swift file and locate the file selector to the right of the word Automatic. Click on the filename dropdown and select ListTitleTVCell.swift as demonstrated below:

Create the label outlet by holding the Control key and dragging from the selected List Name label to the Swift file, positioning your cursor immediately beneath this class declaration:
class ListTitleTVCell: UITableViewCell {Set the connection Name to listTitleLabel and press Return to establish the outlet.
Your table cells require dynamic background image changes to reflect different states (as evidenced by the multiple background assets in your project's Assets folder). This visual feedback enhances user experience significantly, but requires an additional outlet for programmatic image management.
Create the background image outlet by holding the Control key and dragging from the yellow background image view to your Swift file, positioning the cursor immediately after this line:
@IBOutlet weak var listTitleLabel: UILabel!Set the connection Name to backgroundImageView and press Return to complete this outlet.
Key Takeaways
on the left margin, which indicates an active connection. Failing to properly remove broken connections will cause runtime crashes in your app.

. This confirms the connection has been severed, allowing you to safely delete the problematic code line.