1. text/plain (Native 영역의 모듈 변경 노출 케이스)

실험 설정 화면

Untitled

Swift 코드

Arbiter.fetch(with: URL(string: "<https://pandora.dev.daumkakao.io/arbiter/v1/run/zlWoqwPDuf>")!) { [weak self] data in
            var color: UIColor = .black
            switch String(data: data!, encoding: .utf8)! {
            case "red":
                color = .red
            case "blue":
                color = .blue
            default:
                break
            }
            DispatchQueue.main.async { [weak self] in
                self?.bannerView.backgroundColor = color
            }
}

결과 예시(IOS native 영역)

Untitled

Simulator Screen Shot - iPhone 13 - 2022-04-22 at 15.40.45.png

2. application.json (Native 영역의 모듈 순서 변경 케이스)

실험 설정 화면

Untitled

Swift 코드 (주석 부분 위주로 보아주세요)

import UIKit
import Arbiter

struct item: Decodable {
    let name: String
    let color: String
    let price: Int
}

class ViewController: UIViewController {
    @IBOutlet weak var tableView: UITableView!
    var items: [item] = [] // 결과를 담을 변수를 설정
    
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.delegate = self
        tableView.dataSource = self
        
        // Atbiter fetch 후 결과값 디코딩하고 뷰를 그림
        Arbiter.fetch(with: URL(string: "<https://pandora.dev.daumkakao.io/arbiter/v1/run/bnuwxzoQQU>")!) { [weak self] data in
            let json = try! JSONDecoder().decode([item].self, from: data!)
            self?.items = json
            DispatchQueue.main.async {
                self?.tableView.reloadData()
            }
        }
    }

}

extension ViewController: UITableViewDelegate, UITableViewDataSource {
    public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }
    
    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell()
        var content = cell.defaultContentConfiguration()
        var background = UIBackgroundConfiguration.listPlainCell()
        
        // Arbiter fetch의 결과값으로 cell을 구성
        content.text = items[indexPath.row].name
        content.secondaryText = "\\(items[indexPath.row].price)원"
        background.backgroundColor = UIColor(hexString: items[indexPath.row].color)
        //
        
        background.cornerRadius = 15
        background.backgroundInsets = .init(top: 10, leading: 10, bottom: 10, trailing: 10)
        
        cell.contentConfiguration = content
        cell.backgroundConfiguration = background
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 150
    }
    
}

// String Hex 값으로 색상을 반환하는 편의상 사용하는 함수
extension UIColor {
    convenience init(hexString: String) {
        let hex = hexString.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
        var int = UInt64()
        Scanner(string: hex).scanHexInt64(&int)
        let a, r, g, b: UInt64
        switch hex.count {
        case 3: // RGB (12-bit)
            (a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17)
        case 6: // RGB (24-bit)
            (a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF)
        case 8: // ARGB (32-bit)
            (a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF)
        default:
            (a, r, g, b) = (255, 0, 0, 0)
        }
        self.init(red: CGFloat(r) / 255, green: CGFloat(g) / 255, blue: CGFloat(b) / 255, alpha: CGFloat(a) / 255)
    }
}

결과 예시

Simulator Screen Shot - iPhone 13 - 2022-04-22 at 15.27.20.png

Simulator Screen Shot - iPhone 13 - 2022-04-22 at 15.28.01.png