Skip to content

Commit 0a22cad

Browse files
committed
adopt swift5
1 parent 7496dce commit 0a22cad

File tree

6 files changed

+673
-626
lines changed

6 files changed

+673
-626
lines changed

AutoLayoutVisualFormat.xcodeproj/project.pbxproj

Lines changed: 582 additions & 575 deletions
Large diffs are not rendered by default.

AutoLayoutVisualFormat.xcodeproj/xcshareddata/xcschemes/VFLStatic.xcscheme

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1010"
3+
LastUpgradeVersion = "1020"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -20,6 +20,20 @@
2020
ReferencedContainer = "container:AutoLayoutVisualFormat.xcodeproj">
2121
</BuildableReference>
2222
</BuildActionEntry>
23+
<BuildActionEntry
24+
buildForTesting = "YES"
25+
buildForRunning = "YES"
26+
buildForProfiling = "YES"
27+
buildForArchiving = "YES"
28+
buildForAnalyzing = "YES">
29+
<BuildableReference
30+
BuildableIdentifier = "primary"
31+
BlueprintIdentifier = "210A01911CC4CE710040DE1D"
32+
BuildableName = "Tests.xctest"
33+
BlueprintName = "Tests"
34+
ReferencedContainer = "container:AutoLayoutVisualFormat.xcodeproj">
35+
</BuildableReference>
36+
</BuildActionEntry>
2337
</BuildActionEntries>
2438
</BuildAction>
2539
<TestAction
@@ -28,7 +42,26 @@
2842
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
2943
shouldUseLaunchSchemeArgsEnv = "YES">
3044
<Testables>
45+
<TestableReference
46+
skipped = "NO">
47+
<BuildableReference
48+
BuildableIdentifier = "primary"
49+
BlueprintIdentifier = "210A01911CC4CE710040DE1D"
50+
BuildableName = "Tests.xctest"
51+
BlueprintName = "Tests"
52+
ReferencedContainer = "container:AutoLayoutVisualFormat.xcodeproj">
53+
</BuildableReference>
54+
</TestableReference>
3155
</Testables>
56+
<MacroExpansion>
57+
<BuildableReference
58+
BuildableIdentifier = "primary"
59+
BlueprintIdentifier = "212A164D21D50CC7007DB60D"
60+
BuildableName = "VFL.framework"
61+
BlueprintName = "VFLStatic"
62+
ReferencedContainer = "container:AutoLayoutVisualFormat.xcodeproj">
63+
</BuildableReference>
64+
</MacroExpansion>
3265
<AdditionalOptions>
3366
</AdditionalOptions>
3467
</TestAction>

AutoLayoutVisualFormat.xcodeproj/xcshareddata/xcschemes/VFLSwift.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1010"
3+
LastUpgradeVersion = "1020"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

VFL.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'VFL'
11-
s.version = '1.1.0'
11+
s.version = '2.0.0'
1212
s.summary = 'Powerful and Easy to use AutoLayout Visual Format Language'
1313

1414
# This description is used to generate tags and improve search results.

VFL/UIView+SWAutoLayout.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public extension UIView {
4545
func VFLConstraints(_ interpolation:VFLInterpolation) -> [NSLayoutConstraint] {
4646
let format = NSMutableString()
4747
let env = NSMutableArray(object: self)
48-
interpolation.result(format, env)
48+
interpolation.resultInto(format, env)
4949
return VFL.VFLViewConstraints(format as String, self, env)
5050
}
5151

VFL/VFLInterpolation.swift

Lines changed: 54 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func buildInterpolationResult(_ parts: [VFLInterpolation]) -> (format: String, e
3131
let format = NSMutableString()
3232
let env = NSMutableArray()
3333
for part in parts {
34-
part.result(format, env)
34+
part.resultInto(format, env)
3535
if !format.hasSuffix(";") {
3636
format.append("; ")
3737
}
@@ -59,63 +59,59 @@ public func fullInstall(_ interpolation: [VFLInterpolation]) -> [NSLayoutConstra
5959
}
6060

6161
// MARK: -
62-
public enum VFLInterpolation : ExpressibleByStringInterpolation, ExpressibleByStringLiteral {
62+
public struct VFLInterpolation : ExpressibleByStringInterpolation, ExpressibleByStringLiteral {
63+
public struct StringInterpolation: StringInterpolationProtocol {
64+
public init(literalCapacity: Int, interpolationCount: Int) {
65+
storage.reserveCapacity(interpolationCount * 2 + 1)
66+
}
67+
public init(string: String) {
68+
storage.append(.format(string))
69+
}
6370

64-
case format(String)
65-
case metric(CGFloat)
66-
case collection([VFLInterpolation])
67-
case other(AnyObject)
71+
public mutating func appendLiteral(_ literal: StringLiteralType) {
72+
storage.append(.format(literal))
73+
}
74+
public mutating func appendInterpolation<T: BinaryFloatingPoint>(_ value: T) {
75+
storage.append(.metric(CGFloat(value)))
76+
}
77+
public mutating func appendInterpolation<T: BinaryInteger>(_ value: T) {
78+
storage.append(.metric(CGFloat(value)))
79+
}
80+
public mutating func appendInterpolation<T: AnyObject>(_ value: T) {
81+
storage.append(.other(value))
82+
}
83+
public enum Parts {
84+
/// literal string part
85+
case format(String)
86+
/// metrics part
87+
case metric(CGFloat)
88+
/// any constraint item type, like View or guide
89+
case other(AnyObject)
90+
}
91+
var storage = [Parts]()
92+
}
93+
var parts: StringInterpolation
6894

6995
// MARK: ExpressibleByStringLiteral
7096
public init(stringLiteral value: StringLiteralType){
71-
self = .format(value)
97+
parts = StringInterpolation(string: value)
7298
}
7399

74100
public init(extendedGraphemeClusterLiteral value: ExtendedGraphemeClusterType){
75-
self = .format(value)
101+
parts = StringInterpolation(string: value)
76102
}
77103

78104
public init(unicodeScalarLiteral value: UnicodeScalarType) {
79-
self = .format(value)
105+
parts = StringInterpolation(string: value)
80106
}
81107

82108
// MARK: ExpressibleByStringInterpolation
83-
public init(stringInterpolation strings: VFLInterpolation...) {
84-
self = .collection(strings)
85-
}
86-
87-
public init(stringInterpolationSegment str: String) {
88-
self = .format(str)
89-
}
90-
91-
public init(stringInterpolationSegment value: CGFloat) {
92-
self = .metric(value)
109+
public init(stringInterpolation: StringInterpolation) {
110+
parts = stringInterpolation
93111
}
94112

95-
public init<T>(stringInterpolationSegment expr: T) {
96-
self = .other( expr as AnyObject )
97-
}
98-
99-
func result() -> (format: String, env: [AnyObject])! {
100-
switch self {
101-
case .collection(let parts):
102-
let env = NSMutableArray(capacity: parts.count)
103-
let format = NSMutableString()
104-
for part in parts {
105-
part.result(format, env)
106-
}
107-
return (format as String, env as [AnyObject])
108-
case .format(let format):
109-
return (format, [])
110-
default:
111-
assertionFailure("call result on incomplete type")
112-
return nil
113-
}
114-
}
115-
116-
/** fill format and env acording to self part */
117-
func result(_ format: NSMutableString, _ env: NSMutableArray) {
118-
switch self {
113+
func fillResult(format: NSMutableString, env: NSMutableArray, part: StringInterpolation.Parts) {
114+
switch part {
119115
case .format(let str):
120116
format.append(str)
121117
case .metric(let value):
@@ -124,10 +120,21 @@ public enum VFLInterpolation : ExpressibleByStringInterpolation, ExpressibleBySt
124120
case .other(let obj):
125121
format.appendFormat("$%u", env.count)
126122
env.add(obj)
127-
case .collection(let parts): // recursive add format and env
128-
for part in parts {
129-
part.result(format, env)
130-
}
123+
}
124+
}
125+
126+
func result() -> (format: String, env: [AnyObject])! {
127+
let parts = self.parts.storage
128+
let env = NSMutableArray(capacity: parts.count)
129+
let format = NSMutableString()
130+
resultInto(format, env)
131+
return (format as String, env as [AnyObject])
132+
}
133+
134+
/// fill format and env acording to self part
135+
func resultInto(_ format: NSMutableString, _ env: NSMutableArray) {
136+
parts.storage.forEach {
137+
fillResult(format: format, env: env, part: $0)
131138
}
132139
}
133140
}

0 commit comments

Comments
 (0)