ios - What does 'array' method in RACSequence (ReactiveCocoa) do? -
this code snippet ray wenderich's ios 7 best practices article. he's fetching json file , making model each in list;
return [[self fetchjsonfromurl:url] map:^id(nsdictionary *json) { racsequence *list = [json[@"list"] rac_sequence]; return [[list map:^(nsdictionary *item) { return [mtljsonadapter modelofclass:[wxdailyforecase class] fromjsondictionary:item error:nil]; }] array]; }]; what array do?
racsequence's instance method map returns racsequence instance. if want nsarray instance, have use -[racsequence array] method evaluate entire sequence , convert values nsarray.
by way, map method executed lazily; sequence produces values, receive them 1 one until unsubscribe or reach end of sequence. calling -array method block current thread if of values not yet available (until become available, @ point method un-block , return array).
Comments
Post a Comment