# create

**通过一个构建函数完整的创建一个 `Observable`**

![](/files/-MWlwMu2jiO0xAWOYtmJ)

**create** 操作符将创建一个 `Observable`，你需要提供一个构建函数，在构建函数里面描述事件（`next`，`error`，`completed`）的产生过程。

通常情况下一个有限的序列，只会调用一次**观察者**的 `onCompleted` 或者 `onError` 方法。并且在调用它们后，不会再去调用**观察者**的其他方法。

## 演示

创建一个 `[0, 1, ... 8, 9]` 的序列：

```swift
let id = Observable<Int>.create { observer in
    observer.onNext(0)
    observer.onNext(1)
    observer.onNext(2)
    observer.onNext(3)
    observer.onNext(4)
    observer.onNext(5)
    observer.onNext(6)
    observer.onNext(7)
    observer.onNext(8)
    observer.onNext(9)
    observer.onCompleted()
    return Disposables.create()
}
```


---

# 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://3440217568.gitbook.io/rxswift/decision_tree/create.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.
