2

I have this warning:

Prototype table cells must have reuse identifiers

The project is pretty large and we have many tableViews and I cannot find the cell that causes this warning. Is there a way to find the source of this warning? I can see the storyboard being the Friends.Storyboard but all the cells there have an id.

enter image description here

Wings
  • 2,398
  • 23
  • 46
user1269290
  • 451
  • 1
  • 6
  • 18

3 Answers3

4
  1. Build your project (so the warning is generated)
  2. Go to the Report Navigator
  3. Click on the build log with the warning

enter image description here

  1. Expand the warning in the build log
  2. You will now see the id(s) of the offending cell(s)

enter image description here

  1. Use 'Find in Project' to search your project for the id(s) you just found.
  2. Click on the result that is returned

enter image description here

  1. The storyboard will open with the correct cell selected and you can add the reuse identifier
Hodson
  • 3,438
  • 1
  • 23
  • 51
  • Glad it helped. If this is the answer you used to solve your problem, please mark it as the accepted answer. https://stackoverflow.com/help/someone-answers – Hodson Aug 01 '18 at 07:29
2

Open Friends.storyboard with Left Clic: Open As/Source Code. You should see now the Friends.storyboard as a XML File.

I create specially a UITableView, with two cells, one with an reuse identifier, and another one without one:

<prototypes>
    <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="thisID" id="rXT-Vv-RiK">
        <rect key="frame" x="0.0" y="28" width="327" height="44"/>
        <autoresizingMask key="autoresizingMask"/>
        <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="rXT-Vv-RiK" id="o6B-Eq-gDX">
            <rect key="frame" x="0.0" y="0.0" width="327" height="43.5"/>
            <autoresizingMask key="autoresizingMask"/>
        </tableViewCellContentView>
    </tableViewCell>
    <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="R2l-ad-LaA">
        <rect key="frame" x="0.0" y="72" width="327" height="44"/>
        <autoresizingMask key="autoresizingMask"/>
        <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="R2l-ad-LaA" id="zNB-8w-4eM">
            <rect key="frame" x="0.0" y="0.0" width="327" height="43.5"/>
            <autoresizingMask key="autoresizingMask"/>
        </tableViewCellContentView>
    </tableViewCell>
</prototypes>

Simplified (pointing out what to look for):

...
<tableViewCell ... reuseIdentifier="thisID" ...>
</tableViewCell>
<tableViewCell ...> //With no attribute/tag "reuseIdentifier"
</tableViewCell>
...

So looking for <tableViewCell should be a good start. You could also use a RegularExpression, but that's maybe too much work (too much tests to check it) opposed to the usage a "manual" search.

Larme
  • 24,190
  • 6
  • 51
  • 81
1

Heres another option if you don't mind using terminal and regex, it makes project-wide searching quite fast.

This makes use of pcregrep which is a version of grep that supports Perl Compatible Regular Expressions.

If you don't have pcregrep you can install it using brew:

brew install pcre

Once its installed you can cd into your project root and run this command in terminal, (Note the trailing .):

pcregrep -rnI --buffer-size=100000000 '^(.)*\btableViewCell \b((?!reuseIdentifier).)*$' .

It will list the file names and line numbers where a tableViewCell is declared and is missing a reuse identifier.

It prints out results in the terminal like this:

// this is the terminal prompt and the command we entered to search
myUser$ pcregrep -rnI --buffer-size=10000000000 '^(.)*\btableViewCell \b((?!reuseIdentifier).)*$' .

// This is the path to the matched file, followed by the line number with the match, followed by a preview of the matched line
./MyProject/Source/UI/MyController/Base.lproj/MyAccountTableViewCell.xib:13:        <tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="71" id="B6A-LV-CH7" customClass="MyAccountTableViewCell">

An explanation:

  • pcregrep - The program that will be parsing source files looking for matches.
  • -rnI - (r) search recursively - (n) print line number in file of match. (I) ignore binary files.
  • --buffer-size=100000000 - sets a larger buffer for parsing larger files. (was necessary for some files in my projects)

Regex: ^(.)\btableViewCell \b((?!reuseIdentifier).)$

  • ^ - match position at start of line
  • (.)* - match anything at the start of the line unlimited times
  • \btableViewCell \b - match the word 'tableViewCell ' with trailing space exactly
  • ((?!reuseIdentifier).) - match lines where 'reuseIdentifier' is not found
  • *$ - followed by any text and the end of the line
digitalHound
  • 4,384
  • 27
  • 27
  • I had to run `pcre2grep` instead of `pcregrep` since the latter crashed with a segmentation fault, but otherwise your solution worked perfectly. – idrougge May 05 '21 at 10:00