├── FastXcodeFileDemoGif.gif ├── README.md └── fast_xcode_file.py /FastXcodeFileDemoGif.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luisrecuenco/FastXcodeFile/dbdd722195b7380c39b88dacf6edc8135fb20249/FastXcodeFileDemoGif.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FastXcodeFile 2 | A Python script to create new files in Xcode faster. 3 | 4 | ## Motivation 5 | I've always found creating files in Xcode incredibly annoying. It's super slow and cumbersome. Not that creating files is the bottleneck of any iOS project whatsoever, but I'd very thankful if Apple provided a way to create files in a faster and less intrusive way. This simple script aims at fixing that. 6 | 7 | ## Usage 8 | You must first install [mod-pbxproj](https://github.com/kronenthaler/mod-pbxproj) 9 | 10 | ``` 11 | sudo pip install mod_pbxproj 12 | ``` 13 | 14 | Then, just make the appropriate changes in the script to match your Xcode project and invoke the script with the class name argument you wish. The fastest way I've found to invoke the script is via Alfred as you can see in the following gif, but you can also use some other tools like Keyboard Maestro to achieve so. 15 | 16 | ![gif](https://raw.githubusercontent.com/luisrecuenco/FastXcodeFile/master/FastXcodeFileDemoGif.gif) 17 | 18 | ## Contact 19 | FastXcodeFile was created by Luis Recuenco: [@luisrecuenco](https://twitter.com/luisrecuenco). 20 | -------------------------------------------------------------------------------- /fast_xcode_file.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys, os, time 4 | from mod_pbxproj import XcodeProject 5 | 6 | project = "__PROJECT_NAME__" # Only used in the file comment 7 | files_group = "__FILES_GROUP__" # The Xcode group where you want the new files to be created 8 | files_path = "__XCODE_FILES_PATH__" # The file system path where the new files will be created 9 | xcode_proj_path = "__XCODE_PROJECT_PATH__" 10 | super_class = "__SUPERCLASS__" # NSObject, UIViewController... 11 | framework = "__FRAMEWORK__" ## Foundation, UIKit... 12 | author = "__AUTHOR__" 13 | class_name = sys.argv[1] # The class name will be the first argument of the script 14 | header_file = "{0}.h".format(class_name) 15 | implementation_file = "{0}.m".format(class_name) 16 | header_full_file = "{0}/{1}".format(files_path, header_file) 17 | implementation_full_file = "{0}/{1}".format(files_path, implementation_file) 18 | 19 | def check_file(file): 20 | if os.path.exists(file): 21 | sys.exit() 22 | 23 | def check_files_existence(): 24 | check_file(header_full_file) 25 | check_file(implementation_full_file) 26 | 27 | def create_files(): 28 | try: 29 | date = time.strftime("%d/%m/%Y") 30 | copyright = "//\n// {0}\n// {1}\n//\n// Created by {2} on {3}.\n// Copyright (c) 2015, {1}. All rights reserved.\n//" 31 | header_copyright = copyright.format(header_file, project, author, date) 32 | implementation_copyright = copyright.format(implementation_file, project, author, date) 33 | 34 | # header file 35 | file = open(header_full_file,'w') 36 | file.write("{0}\n\n#import <{1}/{1}.h>\n\n@interface {2} : {3}\n\n@end\n".format(header_copyright, framework, class_name, super_class)) 37 | file.close() 38 | 39 | # implementation file 40 | file2 = open(implementation_full_file,'w') 41 | file2.write("{0}\n\n#import \"{1}\"\n\n@implementation {2}\n\n@end\n".format(implementation_copyright, header_file, class_name)) 42 | file2.close() 43 | 44 | except: 45 | print('Something went wrong') 46 | 47 | def add_files_to_project(): 48 | project = XcodeProject.Load('{0}/project.pbxproj'.format(xcode_proj_path)) 49 | group = project.get_or_create_group(files_group) 50 | project.add_file_if_doesnt_exist(header_full_file, group) 51 | project.add_file_if_doesnt_exist(implementation_full_file, group) 52 | project.save() 53 | 54 | check_files_existence() 55 | create_files() 56 | add_files_to_project() 57 | --------------------------------------------------------------------------------