该项目涵盖动态表视图单元高度、MVVM 和干净的体系结构和预取表数据 从服务器或无限滚动视图

昆贝

Quinbay是一个示例应用程序。该项目涵盖动态表视图单元高度、MVVM 和干净的体系结构以及从服务器或无限滚动视图预取表数据。

要学习的东西

MVVM 和干净架构

该项目的体系结构使用 MVVM 体系结构。在这里,“ViewController”负责更新 API 并将用户触摸请求传递给 View 模型。

项目狙击 : –

截图 2022-01-11 在 12 01 41 PM

视图模型是使用 SearchAPIHandler 协议启动的。这里使用了固体原则的开盘原则。任何类都可以使SearchAPI Handler提供一些协议规则。

项目狙击 : –

截图 2022-01-11 在 12 08 22 PM
截图 2022-01-11 在 12 10 04 PM

Dynamic cell height

The tableview cell uses dynamic cell height. The technique to use dynamic cell height is to add constrains from top to bottom and make the table view height dynamic. Other important things is to give don’t give height to labels as it can expand and make its number of lines 0 or custom as per requirement.

Projects Snipet : –

Screenshot 2022-01-11 at 12 02 04 PM

JSON Decoder with Models

JSON received from server is mapped to model classes using Codable Protocol and JSONDecoder class.

Projects Snipet : –
Screenshot 2022-01-11 at 12 02 28 PM

Prefetch table data from server

When user reaches the bottom of the page, in “prefetchRowsAt” function, we inform view model to fetch more products with “page” incremented.

Projects Snipet : –

Screenshot 2022-01-11 at 12 13 13 PM
Screenshot 2022-01-11 at 12 14 24 PM

Infinite scrollview

See the attached GIF. As soon as user reaches bottom of the page, view model fetches data and append to current product list and show.

Canceling Previous Search Call when new call added in Queue.

In the current session, all the tasks are fetched and mached to given search string. If matches and the next request occured, the last all tasks are cancelled.

Projects Snipet : –

Screenshot 2022-01-11 at 12 15 23 PM

When task is cancelled, callback is received with -999 error code. Here return and don’t do anything.

Projects Snipet : –

Screenshot 2022-01-11 at 12 16 26 PM

Technologies

Project is created with:

  • Xcode : 13.1
  • IOS version: 15

Application GIF

RPReplay_Final1641881731.mov


GitHub

点击跳转