Mvvm - Collection View Notes With Swift

Related tags

Guides mvvm
Overview

CollectionViewNotes

Haciendo apuntes para cuando pierda la memoria

Comenzando 🚀

  • Crear CollectionView desde StoryBoard

  • Agregar Label en Celda

alt text

  • Crear Cocoa Touch Class para la Celda
import UIKit
class MyCollectionViewCell: UICollectionViewCell {
    
    @IBOutlet weak var myLabel: UILabel!
}
  • Crear @IBOutlet hacia ViewController
@IBOutlet weak var collectionView: UICollectionView!
  • Declarar delegate y datasource
override func viewDidLoad() {
        super.viewDidLoad()
        collectionView.delegate = self
        collectionView.dataSource = self
    }
  • Declarar Array y nombre de celda para Identifier
let reuseIdentifier = "cell" // also enter this string as the cell identifier in the storyboard
var items = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48"]
    
  • Declarar Delegate y Datasource en clase
class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate
  • Agregar protocolos para TableView
// tell the collection view how many cells to make
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.items.count
    }
    
    // make a cell for each cell index path
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        // get a reference to our storyboard cell
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! MyCollectionViewCell
        
        // Use the outlet in our custom class to get a reference to the UILabel in the cell
        cell.myLabel.text = self.items[indexPath.row] // The row value is the same as the index of the desired text within the array.
        cell.backgroundColor = UIColor.cyan // make cell more visible in our example project
        
        return cell
    }
    
    // MARK: - UICollectionViewDelegate protocol
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        // handle tap events
        print("You selected cell #\(indexPath.item)!")
    }

Control de columnas

  • Añadir UICollectionViewDelegateFlowLayout
class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {...
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
           let padding: CGFloat =  50
           let collectionViewSize = collectionView.frame.size.width - padding

           return CGSize(width: collectionViewSize/columnsItems, height: collectionViewSize/columnsItems)
       }

Referencias:

-Simple collection view

https://stackoverflow.com/questions/31735228/how-to-make-a-simple-collection-view-with-swift

-Column settings

https://stackoverflow.com/questions/38394810/display-just-two-columns-with-multiple-rows-in-a-collectionview-using-storyboar

You might also like...
This a simple swiftui app where i used mvvm architecture, coredata swiftui and so on..
This a simple swiftui app where i used mvvm architecture, coredata swiftui and so on..

SwiftUI MVVM COREDATA NOTE APP This a simple swiftui app where i used mvvm architecture, coredata swiftui and so on... #FEATURES SWIFTUI MVVM COREDATA

WhaleFull - MVVM + RxSwift + CTMediator + MJRefresh + DZNEmptyDataSet

WhaleFull 👌 . MVVM + RxSwift + CTMediatror + MJRefresh + DZNEmptyDataSet Englis

MVVM-RXSWIFT-COMBINE- - Demo application populating posts from network request using
MVVM-RXSWIFT-COMBINE- - Demo application populating posts from network request using

MVVM = RXSWIFT + COMBINE Demo application populating posts from network request

PunkAPI(BrewDog) 을 이용한 RxSwift-MVVM 예제 (Naver Tech Concert)

BringMyOwnBeer 🍺 RxSwift를 이용한 MVVM 패턴 예제 Contents About BringMyOwnBeer 🍺 Concept Contact Me About BringMyOwnBeer 🍺 생소한 RxSwift와 MVVM 개념을 보다 쉽게 이해할

Demonstration blackjack app for native iOS. Uses MVVM architecture
Demonstration blackjack app for native iOS. Uses MVVM architecture

Blackjack - native iOS application This project is a simple demonstration on how to intergrate swiftUI with MVVM architecture. Although, technically,

A sample project exploring MVVM pattern with SwiftUI/Combine, using Unsplash API (via Picsum.photos API)
A sample project exploring MVVM pattern with SwiftUI/Combine, using Unsplash API (via Picsum.photos API)

CombineUnsplash A sample project exploring MVVM pattern with SwiftUI/Combine, using Unsplash API (via Picsum.photos API) with detail example. Resource

SampleProjectMVVM - Sample project using MVVM parsing data from Giphy.com
SampleProjectMVVM - Sample project using MVVM parsing data from Giphy.com

iOS Take Home Create an iOS app with two views, MainViewController and DetailVie

iOS protocol-oriented MVVM examples
iOS protocol-oriented MVVM examples

MVVM-Example Protocol-Oriented MVVM example apps. Sample projects: MVVM-Example - A Settings screen that has one settings – put your app in Minion Mod

ProductListSwiftUI - SwiftUI Project to fetch product list using the fakestoreapi and the MVVM architectural pattern
ProductListSwiftUI - SwiftUI Project to fetch product list using the fakestoreapi and the MVVM architectural pattern

ProductListSwiftUI SwiftUI Project to fetch product list using the fakestoreapi

Owner
null
iOS native app demo with Xcode and Swift using MVVM architecture and Apple's Combine framework for functional reactive programming, all with UIKit

iOS (Swift 5): MVVM test with Combine and UIKit MVVM and functional reactive programming (FRP) are very used in iOS development inside companies. Here

Koussaïla BEN MAMAR 2 Dec 31, 2021
Create a simple MVVM-C iOS architecture with Swift for starters

iOS-Architecture-MVVM MVVM+Coordinators IOS Architecture Tutorial By Bobby Pehtr

Mehrdad Ahmadian 0 Dec 30, 2021
NewsAppMVVM - A Swift iOS App created to practice MVVM Design Pattern

NewsAppMVVM A Swift iOS App created to practice MVVM Design Pattern. This app re

Jorge Roberto 1 Jan 3, 2022
A Swift implementation of a Flickr-search application that uses MVVM and ReactiveCocoa

ReactiveCocoa, Swift and MVVM This application is a Swift-port of an MVVM / ReactiveCocoa example application I wrote a few months ago. Instructions T

Colin Eberhardt 377 Sep 26, 2022
MVVM-of-SuYeon - Build an Instagram iOS App Clone with Cloud Firestore, Swift 5

MVVM-of-SuYeon Instagram Firestore App Clone | Swift 5 + iOS 14 | MVVM Build an

null 2 Feb 16, 2022
HotCoffee is learning project with MVVM, Generic,Swift 5, TableView

HotCoffee A simple Coffee Ordering app built using TableView, MVVM design pattern and Swift5. Tools Xcode Version 13.2.1 Framework -UIKit Architecture

Ghullam Abbas 2 Aug 26, 2022
Swift, UIkit, Anchorage, Clean Architecture, UICollectionViewDiffableDataSourcem, MVVM+Coordinators patterns

About the app iOS project realized with Swift, UIkit, Anchorage, Clean Architecture, UICollectionViewDiffableDataSource and MVVM + Coordinators patter

Luca Berardinelli 4 Dec 29, 2022
Exemplify a LazyVGrid in SwiftUI in a MVVM pattern with Mock Data and images in assets.

SwiftUI-LazyVGrid Exemplify a LazyVGrid in SwiftUI in a MVVM pattern with Mock Data and images in assets. Screenshots Samples IP & Credits All those b

Ethan Halprin 3 Aug 9, 2022
SpaceX rocket listing app using RxSwift and CLEAN Architecture with MVVM

Jibble SpaceX rocket listing app using RxSwift and CLEAN Architecture with MVVM Demo Features Reactive Bindings URL / JSON Parameter Encoding Filter Y

Ammad Akhtar 0 Dec 5, 2021
A demo demonstrates how to use combine and MVVM in the SwiftUI app

SwiftUI-MVVM-Combine A demo demonstrates how to use combine and MVVM in the Swif

Asa. Ga 7 Jul 5, 2022