objective c - how to get item from rac_sequence, reactive cocoa, ios -


i parsing needed links in header of response server. header looks like

access-control-allow-origin → * age → 0 cache-control → private,must-revalidate

connection → keep-alive

content-encoding → gzip content-type → application/json

date → sat, 13 jun 2015 15:58:56 gmt etag → w/"cb38bb07f1635fd6aba5969985bf0607"

link → http://thisiscurrentlink&limit=24; rel="next",http://thisislastlink&limit=24; rel="last",http://thisisfirstlink&limit=24; rel="first",<>; rel="prev"

server → nginx

vary → accept-encoding

x-total-count → 131

transfer-encoding → chunked

by doing this, can links array contains links

nsstring *linkheader = [(nshttpurlresponse *)operation.response  allheaderfields][@"link"]; nsarray *links = [linkheader componentsseparatedbystring:@","]; 

then doing following links needed

racsequence *sequence = [links.rac_sequence map:^id(nsstring* item) {                 nserror *error;                 nslog(@"item %@",item);                  nsregularexpression *regex  =   [nsregularexpression regularexpressionwithpattern:@"<(.*)>" options:0 error:&error];                 nsstring *actuallink;                  if (regex != nil) {                     nstextcheckingresult *result    =   [regex firstmatchinstring:item                                                                           options:0                                                                             range:nsmakerange(0, item.length)                                                          ];                     if (result) {                         nsrange range    =   [result rangeatindex:1];                         actuallink       =   [item substringwithrange:range];                         nslog(@"actuallink %@",actuallink);                          return [racsequence return:actuallink];                      }                 }                 return [racsequence empty];              }]; 

right sequence containing links are

http://thisiscurrentlink&limit=24 http://thisislastlink&limit=24 http://thisisfirsttlink&limit=24 

my question how can access each item above sequence

just use array method, converts racsequence array.

also, don't need use racsequence return:, that's creating sequences within sequence, return usual string , nil, use filter after map remove nil values before trying extract array.

example:

nsarray *actuallinks = [[links.rac_sequence map:^id(nsstring* item) {             nserror *error = nil;             nslog(@"item %@",item);              nsregularexpression *regex  =             [nsregularexpression regularexpressionwithpattern:@"<(.*)>" options:0 error:&error];             nsstring *actuallink = nil;              if (regex != nil) {                 nstextcheckingresult *result = [regex firstmatchinstring:item                                                                         options:0                                                                         range:nsmakerange(0, item.length)];                 if (result) {                     nsrange range = [result rangeatindex:1];                     actuallink = [item substringwithrange:range];                     nslog(@"actuallink %@",actuallink);                 }             }             return actuallink;         }] ignore:nil].array; 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -