NSRegularExpression enumerateMatchesInString:options:range:usingBlock: giving a null result?

后端 未结 1 438
误落风尘
误落风尘 2021-01-13 13:27

I\'m using a regular expression in a parser, however, it seems to give one result to much, this is my code: Regex:

self.seatSelectRegex = [NSRegularExpressio         


        
相关标签:
1条回答
  • 2021-01-13 14:15

    This is because your using the NSMatchingReportCompletion option with enumerateMatchesInString:options:range:usingBlock:. From Apples documentation:

    If the NSMatchingReportCompletion matching option is specified, the Block object will be called once after matching is complete, with nil result and the NSMatchingCompleted matching flag is set in the flags passed to the Block, plus any additional relevant “NSMatchingFlags” from among NSMatchingHitEnd, NSMatchingRequiredEnd, or NSMatchingInternalError.

    And the reason your seeing the last block call as a range with location and length set as 0 is because your sending messages to nil which will return nil (which is the integer 0).

    0 讨论(0)
提交回复
热议问题