A Property List (plist) is a file used in iOS to store structured data in key–value format. It is commonly used for simple data persistence.
👉 It stores data like:
📌 File extension: .plist
Data persistence means saving data so it remains available even after the app is closed and reopened.
A UITableView with multiple sections, where data is grouped into categories.
👉 Example:
A plist can be:
Example structure:
Food
├── Fruits
├── Vegetables
└── Drinks
A table view contains:
data.plistExample plist structure:
Fruits → Apple, Banana, Mango
Vegetables → Carrot, Potato
Drinks → Water, Juice
if let path = Bundle.main.path(forResource: "data", ofType: "plist"),
let dict = NSDictionary(contentsOfFile: path) as? [String: [String]] {
print(dict)
}
var sections: [String] = []
var data: [[String]] = []
sections = Array(dict.keys)
data = Array(dict.values)
func numberOfSections(in tableView: UITableView) -> Int {
return sections.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data[section].count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
cell.textLabel?.text = data[indexPath.section][indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sections[section]
}
Draw:
TableView
├── Fruits
│ ├ Apple
│ ├ Banana
│
├── Vegetables
│ ├ Carrot
│ ├ Potato
│
└── Drinks
├ Water
├ Juice
Sections:
👉 Data stored in plist 👉 Displayed in multi-section table
Use plist for:
Use JSON/Core Data for large apps
Keep data organized in dictionaries
Always validate data before use
Use meaningful section names
titleForHeaderInSection used for?Plist = key-value file for storing small data
Used for data persistence
Multi-section table groups data into categories
Key methods:
numberOfSectionsnumberOfRowsInSectioncellForRowAtSection titles improve UI clarity
Best for static data (settings, lists)
Open this section to load past papers