Skip to content

Instantly share code, notes, and snippets.

View LearnWithTung's full-sized avatar

Tung Vu LearnWithTung

  • https://star.global/
  • Vietnam
  • 09:34 (UTC +07:00)
View GitHub Profile
class SceneDelegate {
var navigationController: UINavigationController!
...
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let sceneWindow = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: sceneWindow)
window?.makeKeyAndVisible()
navigationController = UINavigationController(rootViewController: makeRootViewController())
window?.rootViewController = navigationController
}
class ViewControllerA {
var onButtonTappedObserve: (() -> Void)?
...
@IBAction func buttonTapped(_ sender: UIButton) {
onButtonTappedObserve?(// dependencies if any)
}
...
}
protocol DatabaseManagement {
func insert(_ articles: [Article], completion: @escaping (Result<Bool, Error>) -> Void)
func retrieve(completion: @escaping (Result<[Article], Error>) -> Void)
func delete(_ article: Article, completion: @escaping (Result<Bool, Error>) -> Void)
}
GET *url*
200 RESPONSE
{
"items": [
{
"id": "a UUID",
"title": "a title",
"description": "a description",
struct FeedItem {
let id: UUID
let title: String
let thumbnailURL: URL
let description: String?
let createdDate: Date
}
struct RemoteFeedItem {
let id: UUID
struct User {
var id: UUID
var accessToken: String?
var username: String?
var imageURL: URL?
var email: String?
var address: String?
}
class FeedViewModel {}
class FeedViewController: UIViewController {
private var viewModel: FeedViewModel?
init(viewModel: FeedViewModel) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}
class FeedViewModel {}
class FeedViewController: UIViewController {
private var viewModel: FeedViewModel?
override func viewDidLoad(){
super.viewDidLoad()
viewModel = FeedViewModel()
}
class AllCategoriesViewController: UIViewController {
var loader: FeedLoader?
func viewDidLoad(){
super.viewDidLoad()
loadFeed()
}
protocol FeedLoader {
func load(completion: @escaping ([FeedItem]) -> Void)
}