1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
| # -*- coding: utf-8 -*-
import random
import os,sys
import string
#创建.swift文件
def createSwift(fileNmae,propertyNumber,methodArray):
full_path = sys.path[0] + '/SwiftFiles/' + fileNmae + '.swift'
file = open(full_path, 'w')
file.write('//\n// '+fileNmae+'.swift\n// Orange\n\n// Created by Ashen on 18/06/06.\n// Copyright © 2018年 BeiLian. All rights reserved.\n//\n\n')
file.write('import UIKit \n\n' + 'class '+fileNmae+': UIViewController {\n\n')
propryNameArray = []
for index in range(1,propertyNumber):
propryNameArray.append(random.choice(array))
propryNameArray = list(set(propryNameArray))
for propertyName in propryNameArray:
file.write(' public var '+propertyName+':'+random.choice(classArray)+'!\n')
file.write('\n\n')
file.write(' override func viewDidLoad() {\n super.viewDidLoad()\n }\n\n')
for methodName in methodArray:
file.write(' public func '+methodName+'TOVC() {\n\n var realArr = Array<String>()\n')
number = random.randint(3, 10)
for i in range(1,number):
file.write(' realArr.append("'+random.choice(array)+'")\n')
file.write('\n }\n\n')
file.write('}')
file.close()
print('Done')
def createClassName():
first = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
second = "abcdefghijklmnopqrstuvwxyz"
index = 0
array = []
# 设置生成多少个类
classNumber = 3
for i in range(classNumber):
final=(random.choice(first))
index = random.randint(3, 5)
for i in range(index):
final+=(random.choice(second))
final += (random.choice(first))
for i in range(index):
final+=(random.choice(second))
array.append(final)
return array
#属性类型
classArray = ['UIColor','UILabel','UITableView','UISlider','UIScrollView','UIView','UIButton']
array = createClassName()
array = list(set(array))
for name in array:
number = random.randint(3, 10)
methodArray = []
for i in range(1,5):
methodArray.append(random.choice(array))
methodArray = list(set(methodArray))#数组去重
createSwift(name+'VController',number,methodArray)
|