# startWith

**将一些元素插入到序列的头部**

![](https://4217506537-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MWj545abP2yK86-qksJ%2Fsync%2Fcb8e7feea08a7c42cd376b1eb03a4c86adac3656.png?generation=1616819394427639\&alt=media)

**startWith** 操作符会在 `Observable` 头部插入一些元素。

（如果你想在尾部加入一些元素可以用[concat](https://3440217568.gitbook.io/rxswift/decision_tree/concat)）

## 演示

```swift
let disposeBag = DisposeBag()

Observable.of("🐶", "🐱", "🐭", "🐹")
    .startWith("1")
    .startWith("2")
    .startWith("3", "🅰️", "🅱️")
    .subscribe(onNext: { print($0) })
    .disposed(by: disposeBag)
```

**输出结果：**

```swift
3
🅰️
🅱️
2
1
🐶
🐱
🐭
🐹
```
