實例方法
output(in:)
在已發布元素的序列中發布由其範圍指定的元素。
聲明
func output<R>(in range: R) -> Publishers.Output<Self> where R : RangeExpression, R.Bound == Int
返回值
發布由範圍指定的元素的發布者。
參數
range
指示要發布哪些元素的範圍。
詳述
使用 Publisher/output(in:)
重新發布您在已發布流中指定的範圍索引。發布所有元素後,發布者正常完成。如果發布者在生成範圍內的所有元素之前正常完成或出現錯誤,則不會發布剩餘的元素。
在下麵的示例中,數組發布者在指定範圍內的索引處發出元素子集:
let numbers = [1, 1, 2, 2, 2, 3, 4, 5, 6]
numbers.publisher
.output(in: (3...5))
.sink { print("\($0)", terminator: " ") }
// Prints: "2 2 3"
可用版本
iOS 13.0+, iPadOS 13.0+, macOS 10.15+, Mac Catalyst 13.0+, tvOS 13.0+, watchOS 6.0+
相關用法
- Swift Optional.Publisher reduce(_:_:)用法及代碼示例
- Swift Optional.Publisher tryDrop(while:)用法及代碼示例
- Swift Optional.Publisher debounce(for:scheduler:options:)用法及代碼示例
- Swift Optional.Publisher breakpoint(receiveSubscription:receiveOutput:receiveCompletion:)用法及代碼示例
- Swift Optional.Publisher mapError(_:)用法及代碼示例
- Swift Optional.Publisher catch(_:)用法及代碼示例
- Swift Optional.Publisher tryAllSatisfy(_:)用法及代碼示例
- Swift Optional.Publisher zip(_:_:_:)用法及代碼示例
- Swift Optional.Publisher sink(receiveValue:)用法及代碼示例
- Swift Optional.Publisher scan(_:_:)用法及代碼示例
- Swift Optional.Publisher throttle(for:scheduler:latest:)用法及代碼示例
- Swift Optional.Publisher assertNoFailure(_:file:line:)用法及代碼示例
- Swift Optional.Publisher collect(_:)用法及代碼示例
- Swift Optional.Publisher combineLatest(_:_:_:_:)用法及代碼示例
- Swift Optional.Publisher share()用法及代碼示例
- Swift Optional.Publisher merge(with:_:_:)用法及代碼示例
- Swift Optional.Publisher map(_:_:)用法及代碼示例
- Swift Optional.Publisher assign(to:on:)用法及代碼示例
- Swift Optional.Publisher zip(_:_:_:_:)用法及代碼示例
- Swift Optional.Publisher tryReduce(_:_:)用法及代碼示例
- Swift Optional.Publisher map(_:_:_:)用法及代碼示例
- Swift Optional.Publisher prepend(_:)用法及代碼示例
- Swift Optional.Publisher removeDuplicates()用法及代碼示例
- Swift Optional.Publisher merge(with:_:_:_:_:_:_:)用法及代碼示例
- Swift Optional.Publisher measureInterval(using:options:)用法及代碼示例
注:本文由純淨天空篩選整理自apple.com大神的英文原創作品 Optional.Publisher output(in:)。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。