Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable #imageLiteral(resourceName: <..>) preview in Xcode?

I found image literals to be rather distracting than useful.
Is there any way to disable this Xcode feature?

like image 510
Krypt Avatar asked Jun 09 '18 15:06

Krypt


1 Answers

A good method for this is to replace all occurrences of #imageLiteral with UIImage(imageLiteralResourceName:) initializers (thanks for the suggestion, @D6mi!). Here's how you can do it automatically:

  1. Navigate to Find/Find and Replace... (or press ⌥⌘F).

  2. Open the dropdown list on the right side and select Regular Expression.

  3. For the search term, enter the following regex:

    #imageLiteral\(resourceName: (.*)\)
    

    For the replacement, enter this:

    UIImage(imageLiteralResourceName: $1)
    

    This regular expression captures the value of the resource name with (.*) and inserts it again with $1. The backslashes are for escaping the parentheses, since they count as special characters.

Note that you don't have to use regular expression in this case (as LinusGeffarth pointed out), but it can be more useful in more complex cases than this.

like image 60
Tamás Sengel Avatar answered Oct 13 '22 20:10

Tamás Sengel