Skip to content

Commit 30b4932

Browse files
author
蔡士林
committed
Add property mark 'F' to support use config method to set initialize value.
1 parent 804f9a4 commit 30b4932

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

.DS_Store

0 Bytes
Binary file not shown.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
.DS_Store
1+
*/.DS_Store
22
*.xcuserstate

BZCodeX/BaseFunction/Property/Property.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public struct Property {
4646
"w": "weak",
4747
"c": "class",
4848
"s": "static",
49-
"b": "_B__B_"]
49+
"b": "_B__B_",
50+
"F": "_F__F_"]
5051

5152
public private(set) var className: String
5253
let scope: String
@@ -187,11 +188,14 @@ public func generatePropertyCode(property: Property, spaceCount: Int) -> String
187188
}
188189
}
189190
} else {
190-
if property.scope.contains("lazy") {
191-
code += " " * spaceCount + property.scope + " " + property.instanceName + ": " + property.className + " = {\n" + " " * (spaceCount + 4) + "<#code#>" + "\n" + " " * spaceCount + "}()"
191+
if let range = regularMatchRange(text: property.scope, expression: "_F__F_[\\ ]?").first {
192+
let scope = String(property.scope[..<property.scope.index(property.scope.startIndex, offsetBy: range.location)] + property.scope[property.scope.index(property.scope.startIndex, offsetBy: range.location+range.length)...])
193+
code += " " * spaceCount + scope + " " + property.instanceName + " = config(\(property.className)()) {\n" + " " * (spaceCount + 4) + "<#code#>" + "\n" + " " * spaceCount + "}"
192194
} else if let range = regularMatchRange(text: property.scope, expression: "_B__B_[\\ ]?").first {
193195
let scope = String(property.scope[..<property.scope.index(property.scope.startIndex, offsetBy: range.location)] + property.scope[property.scope.index(property.scope.startIndex, offsetBy: range.location+range.length)...])
194196
code += " " * spaceCount + scope + " " + property.instanceName + ": " + property.className + " = {\n" + " " * (spaceCount + 4) + "<#code#>" + "\n" + " " * spaceCount + "}()"
197+
} else if property.scope.contains("lazy") {
198+
code += " " * spaceCount + property.scope + " " + property.instanceName + ": " + property.className + " = {\n" + " " * (spaceCount + 4) + "<#code#>" + "\n" + " " * spaceCount + "}()"
195199
} else {
196200
code += " " * spaceCount + property.scope + " " + property.instanceName + ": " + property.className
197201
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ private let <#name#>: UIButton = {
195195
| 特殊符号 | 功能 |
196196
| :-: | :-: |
197197
| b | block, 为属性生成block形式的初始化值,类似于 lazy var |
198+
| F | 自用,属性的初始值是由 config 函数来提供的 |
198199

199200

200201

0 commit comments

Comments
 (0)