python写一段自动生成Objective-C模型对象的脚本
来源:互联网 发布:借款网站源码 编辑:程序博客网 时间:2024/06/03 16:10
新学python,读取文件操作文件部分,一直是我比较头疼的部分
其他平台的编译调试比较累。
想来每次写iphone程序mvc分离时候,最头疼的就是复制粘贴model和object部分了。
于是亲自动手练习一下=_=代码写的不是很好,希望指正。
1.0版本
支持ARC与非ARC
支持NSString,NSInteger,NSDate
下面的工作:
1:安装到本地和打包上传
2:增加自定义对象。
3:模型部分(支持单件模式,数组列表,增删改查函数)
都不是很麻烦,以后想起来在加=_=
以下是代码
__author__ = 'watsy'import sys"""title comment"""def fileTitleComment(): return """ /** *author:watsy */\n""""""help"""def showHelp(): print """help\n example: 1:createObject.py obj:CWDemoObject 1 s:sName s:sTitle i:nID d:dBirtyday 2:createObject.py obj:CWDemoObject 0 s:sName s:sTitle i:nID d:dBirtyday 3:createObject.py obj:CWDemoObject s:sName s:sTitle i:nID d:dBirtyday 4:createObject.py CWDemoObject s:sName s:sTitle i:nID d:dBirtyday obj:name (name means file name and object name.) 1: open arc flag ^-^ s:NSString i:NSInteger d:NSDate""""""@property (nonatomic, strong) NSString* sCode;"""def writeObj(obj_string, fileHandle): try: (obj, name) = obj_string.strip().split(':') if obj == 's': fileHandle.write('@property (nonatomic, strong) NSString*\t\t\t%s;\n' %(name)) elif obj == 'i': fileHandle.write('@property (nonatomic, assign) NSInteger\t\t\t%s;\n' %(name)) elif obj == 'd': fileHandle.write('@property (nonatomic, strong) NSDate*\t\t\t%s;\n' %(name)) except ValueError as err: print ('error %s' % (err))"""@synthesize _sCode;"""def writeSynthesize(obj_string, fileHandle): try: (obj, name) = obj_string.strip().split(':') fileHandle.write('@synthesize _%s;\n' %(name)) except ValueError as err: print ('error %s' % (err))""" [object release];"""def writeObjectRelease(obj_string, fileHandle): try: (obj, name) = obj_string.strip().split(':') fileHandle.write('\n\t[_%s release];' % (name)) except ValueError as err: print ('error %s' % (err))def createObject(*args, **kwargs): # print args try: args = args[0] if len(args) == 2 and args[1] == '--help': showHelp() else: filename = args[1] #get file name if 'obj:' in filename: filename = filename.split(":")[1] arc = args[2] bArc = False if arc == '1': bArc = True objs = args[3:] elif arc =='0': objs = args[3:] else: objs = args[2:] #create file.h with open("%s.h" % (filename), 'w') as fn: #write title comment fn.write(fileTitleComment()) #write import file fn.write('import <Foundation/Foundation.h>\n\n') #write object fn.write("@interface %s : NSObject\n\n" % (filename)) for eachObj in objs: writeObj(eachObj, fn) #write end fn.write("\n@end") #create file.m with open("%s.m" % (filename), 'w') as fn: #write import file fn.write('#import "%s.h"\n\n' % (filename)) fn.write('@implementation %s\n\n' % (filename)) #@synthesize for eachObj in objs: writeSynthesize(eachObj, fn) #init fn.write('\n- (id) init {\n\tif (self = [super init]) {\n\t\t//add code\n\t}\n\treturn self;\n}') #arc model if bArc == False: fn.write('\n\n- (void) dealloc {\n'); for eachObj in objs: writeObjectRelease(eachObj, fn) fn.write('\n\n\t[super dealloc]\n}\n\n'); fn.write('\n@end') except: print "input error : %s" % ( args) print showHelp()if __name__ == '__main__': createObject(sys.argv)
- python写一段自动生成Objective-C模型对象的脚本
- Objective-C的对象模型
- Objective-C对象模型
- Objective-C对象模型
- objective C 对象模型
- Objective-C 对象模型
- Objective-C对象模型
- objective c下的对象模型
- python 随便写的数据库差异化比较,并自动生成差异化脚本
- python写一段脚本代码自动完成输入(目录下的所有)文件的数据替换(修改数据和替换数据都是输入的)
- 自己写了一段iOS Objective-C的反射的代码
- C写的一段音乐程序
- 用批处理写的自动生成tablediff脚本的工具
- python写代码生成脚本
- 为STARUML写的自动生成文档脚本
- 为STARUML写的自动生成文档脚本[收藏]
- 为STARUML写的自动生成文档脚本
- Objective-C的对象模型与运行时
- Android应用程序资源管理器(Asset Manager)的创建过程分析
- js中继承的几种用法apply,call,prototype
- java语法总结01--基本数据类型
- C++ 可变参数函数
- OpenWrt U盘根目录设置
- python写一段自动生成Objective-C模型对象的脚本
- javafx TableView中的TableColumn如何填充的自带类
- 策略模式
- Palindrome Partitioning
- SVG介绍---摘自百度百科
- Android代码中实现WAP方式联网
- 圈内业务描述
- JAVA 网络编程(TCP 上传图片)
- java语法总结02--数组