Created
October 8, 2016 19:12
-
-
Save sadiq81/06209dde694d076c6545b87496f8aa92 to your computer and use it in GitHub Desktop.
Generate enums for Assets.xcassets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: UTF-8 -*- | |
# generate_image_assets.py | |
# punchcards | |
# | |
# Created by Privat on 13/07/2016. | |
# Copyright © 2016 Eazy IT. All rights reserved. | |
import re | |
import os | |
IMAGES_PATH = "./Assets.xcassets" | |
IMAGES_FILE_PATH = "../Classes/Ressources/Images.swift" | |
print "Path to image directory ",IMAGES_PATH | |
print "Path to Swift file ",IMAGES_FILE_PATH | |
with open(IMAGES_FILE_PATH, "w") as f: | |
f.write("//\n\ | |
// Created by Privat on 13/07/2016.\n\ | |
// Copyright (c) 2016 Eazy IT. All rights reserved.\n\ | |
//\n\ | |
\n\ | |
import Foundation\n\ | |
import UIKit\n\ | |
\n\ | |
enum Images: String {\n\n") | |
for root, dirs, files in os.walk(IMAGES_PATH): | |
for dir in dirs: | |
if dir.endswith(".imageset"): | |
string = dir.replace(".imageset","") | |
string2 = " case " + string + "\n" | |
f.write(string2) | |
f.write("\n\ | |
var image: UIImage? {\n\ | |
return UIImage(named: self.rawValue)\n\ | |
}\n\ | |
}") | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment