Reputation: 511
I found image literals to be rather distracting than useful.
Is there any way to disable this Xcode feature?
Upvotes: 12
Views: 1783
Reputation: 58069
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:
Navigate to Find/Find and Replace... (or press ⌥⌘F).
Open the dropdown list on the right side and select Regular Expression.
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.
Upvotes: 12