How do I find weak properties that are not IBOUtlets using the Xcode search tool?

In a project I am working on, I have noticed some cases where properties are marked as weak

or assign

when they shouldn't:

@property(nonatomic, assign) NSArray *data;

      

I'm trying to check if there are other cases where this happens, so I'm doing a regex search using this pattern:

property.+(assign|weak).+\*

      

enter image description here

The problem is this will match all IBOutlet

s:

@property (weak, nonatomic) IBOutlet UIBarButtonItem *barButtonItem;

      

Is it possible to improve my regex to ignore them somehow?

(Of course, if you know of any other way to do what I want, please share!)

+3


source to share


1 answer


If your regex works for you, and you just want to avoid matching the same strings you matched with the substring IBOutlet

, you can simply use negative lookahead (?!.*IBOutplet)

right after finding property

:

property(?!.*IBOutlet).+(assign|weak).+\*
        ^^^^^^^^^^^^^^

      

See regex demo



Note that you can add word boundaries \b

to match only whole words:

\bproperty\b(?!.*\bIBOutlet\b).+\b(assign|weak)\b.+\*

      

+3


source







All Articles