Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is any function in swift similar to R.java in Android?

I am a beginner in iOS and swift.

I used to write Android and I think the R.java is a good idea to manage ids, drawables, strings and other resources. So I'm surprised that iOS does't provide a good function to access resources.

If I want to get a Image from assets, I call UIImage(named: "img_name"), but I don't think this is the best way to access img_name, I may use a wrong name and I can't get the image.

I found some open source project like Shark and SwiftGen, but Shark only support images and SwiftGen it seems need to run a command not automatically.

Do you have any better solution? Thank you!

like image 313
Findley Tyler Avatar asked Apr 16 '16 08:04

Findley Tyler


1 Answers

I have a open source project R.swift-plugin it provides features as you mentioned. You just need to install the Xcode Plugin via Alcatraz and search R.swift

The plugin will automatically generate a resource file to manage your images, localizable strings and colors, and you can access them like using R.java

Usage:

enter image description here

Sincerely recommend you to try it. And feel free to give me any suggestion to improve it :)

like image 116
Azure Chen Avatar answered Sep 22 '22 21:09

Azure Chen