---
title: Không khởi tạo trực tiếp các protocol hệ thống
impact: MEDIUM
impactDescription: Tránh misuse các compiler protocol như ExpressibleByArrayLiteral, khuyến khích sử dụng literal syntax.
tags: swift, ios, compiler, literals, code-quality
---

## Không khởi tạo trực tiếp các protocol hệ thống

Các protocol của compiler (như `ExpressibleByArrayLiteral`) không nên được gọi `init` trực tiếp. Hãy sử dụng cú pháp gọn gàng (literals) để khởi tạo giá trị.

**Incorrect (Gọi init trực tiếp):**

```swift
let array = Array(arrayLiteral: 1, 2, 3)
let dict = Dictionary(dictionaryLiteral: ("key", "value"))
let string = String(stringLiteral: "Hello")
```

**Correct (Sử dụng literal syntax):**

```swift
let array = [1, 2, 3]
let dict = ["key": "value"]
let string = "Hello"
```

**Tools:** SwiftLint (compiler_protocol_init)
