# Post Rendering

## Custom Post Rendering

UIKit provides default renderers for the core data types: `text`, `image`, and `file`. It also provides a way to render your own UI for your custom post.&#x20;

### Post Structure:

A single post UI is composed of 1 or more UITableViewCell. This allows reusability of cell components such as header or footer which can be shared by different kinds of posts.&#x20;

![Text Post Structure](/files/-McN4tKRdTKSoGQ40jnn)

This is an example of simple text post which contains 3 tableview cell. Top cell represents the header, middle cell contains text content and bottom cell is footer cell.

### Creating UI for custom posts :

There are 3 steps involved in creating custom post renderer.

**Step 1:** Create your UI using UITableView cells.&#x20;

```swift
class MyPostHeaderCell: UITableViewCell { 
    // ...
}

class MyPostContentCell: UITableViewCell {
    // ...
}
```

**Step 2:** Compose a post UI component. For this create a component which conforms to `AmityPostComposable` protocol.

```swift
struct MyCustomPostComponent: AmityPostComposable {
    
    var post: AmityPostModel
    
    // Post data model which you can use to render ui.
    init(post: AmityPostModel) {
        self.post = post
    }
    
    func getComponentCount(for index: Int) -> Int {
        return 2
    }
    
    func getComponentCell(_ tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell {
        switch indexPath.row {
        case 0:
            let cell = tableView.dequeueReusableCell(withIdentifier: "my-cell-identifier", for: indexPath) as! MyPostHeaderCell
            // ... populate cell data here
            return cell
        case 1:
            let cell = tableView.dequeueReusableCell(withIdentifier: "my-cell-identifier", for: indexPath) as! MyPostContentCell
            // ... populate cell data here
            return cell
        default:
						fatalError("indexPath is out of bound")
        }
    }
    
    // Height for each cell component
    func getComponentHeight(indexPath: IndexPath) -> CGFloat {
        return UITableView.automaticDimension
    }
}

```

You can also use our default header cell `AmityPostHeaderTableViewCell` & default footer cell `AmityPostFooterTableViewCell` in your custom post component.&#x20;

**Step 3:** Register your custom cell & implement datasource.

```swift
class YourViewController: UIViewController {
    
		func showFeed() {
				// 1.
				// Register your cell here. You can register both 
				// nib as well as class itself.
				AmityFeedUISettings.shared.register(UINib(nibName: "PostThumbsupTableViewCell", bundle: nil), forCellReuseIdentifier: "PostThumbsupTableViewCell")
        AmityFeedUISettings.shared.dataSource = self

        // Showing our feed UI
				let feedViewController = AmityGlobalFeedViewController.make()
	      navigationController?.pushViewController(feedViewController, animated: true)
		}
}

extension YourViewController: AmityFeedDataSource {
    
    // 2. 
    // Provide your rendering component for custom post.
    func getUIComponentForPost(post: AmityPostModel, at index: Int) -> AmityPostComposable? {
        switch post.dataType {
        case "your-data-type":
            return MyCustomPostComponent(post: post)
        default:
            return nil
        }
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.social.plus/social-plus-uikit/uikit-3/ios/community/overriding-behavior/feed-ui-settings/post-rendering.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
