- JSON - web api formatted data the is the most popular way of serving downloaded or uploaded content from a network resource
{ "language": "swift", "releaseYear": 2014, "url": "https://developer.apple.com/swift/images/swift-og.png" }
extension Bundle { | |
enum BundleError: Error { | |
case noResource(String) | |
case noContents(String) | |
case decodingError(Error) | |
} | |
func parseJSONData<T: Decodable>(_ name: String, ext: String = "json") throws -> T { | |
guard let path = Bundle.main.path(forResource: name, ofType: ext) else { | |
throw BundleError.noResource(name) |
// Making sections for a 2D array to be used in a CollectionView or TableView. [Fellow] => [[Fellow]] | |
import Foundation | |
struct Fellow { | |
let name: String | |
let cohort: String | |
static func allFellows() -> [Fellow] { | |
return [ |
{ | |
"results": [ | |
{ | |
"gender": "male", | |
"name": { | |
"title": "Monsieur", | |
"first": "Alfonso", | |
"last": "Rolland" | |
}, | |
"location": { |
Delegates: You use delegates to interact with Cocoa objects that inform you of events in an app.
Apple docs - delegation
// Object A
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
import UIKit | |
final class DetailView: UIView { | |
// setting up a scroll view | |
// 1. add scrollview | |
// 2. add content view | |
// 3. add subviews to content view | |
// Note: must set high priority of content view to low, default is 1000 | |
// Date extension | |
extension Date { | |
static func getStringFromDate(date: Date) -> String { | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = "EEEE, MMM d, yyyy" | |
let dateString = dateFormatter.string(from: date) | |
return dateString | |
} | |
static func getDateFromString(dateString: String) -> Date? { | |
let formatter = ISO8601DateFormatter() |