Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IB connection rule #9

Closed
wants to merge 15 commits into from
31 changes: 29 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"object": {
"pins": [
{
"package": "Clang_C",
"repositoryURL": "https://github.com/norio-nomura/Clang_C.git",
"state": {
"branch": null,
"revision": "90a9574276f0fd17f02f58979423c3fd4d73b59e",
"version": "1.0.2"
}
},
{
"package": "Commandant",
"repositoryURL": "https://github.com/Carthage/Commandant.git",
Expand Down Expand Up @@ -46,13 +55,31 @@
"version": "4.2.5"
}
},
{
"package": "SourceKit",
"repositoryURL": "https://github.com/norio-nomura/SourceKit.git",
"state": {
"branch": null,
"revision": "18eaa67ca44443bbe39646916792b9f0c98dbaa1",
"version": "1.0.1"
}
},
{
"package": "SourceKitten",
"repositoryURL": "https://github.com/jpsim/SourceKitten.git",
"state": {
"branch": null,
"revision": "71e8297e5d95118588f8aa8e1de892762346dc9d",
"version": "0.18.4"
}
},
{
"package": "Yams",
"repositoryURL": "https://github.com/jpsim/Yams.git",
"state": {
"branch": null,
"revision": "95f45caf07472ec78223ebada45255086a85b01a",
"version": "0.5.0"
"revision": "90a76f3cdb552b8e6aea5dabdd6c3578b8a7ad45",
"version": "0.4.1"
}
}
]
Expand Down
8 changes: 5 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ let package = Package(
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/drmohundro/SWXMLHash.git", from: "4.0.0"),
.package(url: "https://github.com/Carthage/Commandant.git", .branch("master")),
.package(url: "https://github.com/jpsim/Yams.git", from: "0.4.1")
.package(url: "https://github.com/jpsim/Yams.git", from: "0.4.1"),
.package(url: "https://github.com/jpsim/SourceKitten.git", from: "0.18.4")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand All @@ -25,11 +26,12 @@ let package = Package(
dependencies: ["IBLinterKit"]),
.target(
name: "IBLinterCore",
dependencies: ["SWXMLHash"]),
dependencies: ["SWXMLHash", "SourceKittenFramework"]),
.target(
name: "IBLinterKit",
dependencies: ["IBLinterCore", "Commandant", "Yams"]),
.testTarget(name: "IBLinterKitTest",
dependencies: ["IBLinterKit"])
dependencies: ["IBLinterKit"],
exclude: ["Resources"])
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Created by SaitoYuta on 2017/12/13.
//

public protocol InterfaceBuilderFile {
public protocol FileProtocol {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to analyze not only xib or storyboard but also swift

var pathString: String { get }
var fileName: String { get }
}
36 changes: 34 additions & 2 deletions Sources/IBLinterCore/InterfaceBuilderNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public extension InterfaceBuilderNode {
public let colorMatched: Bool?
public let device: Device?
public let views: [View]?
public let gestureRecognizers: [GestureRecognizer]?
public let placeholders: [Placeholder]?

static func decode(_ xml: XMLIndexerProtocol) throws -> InterfaceBuilderNode.XibDocument {
Expand All @@ -70,6 +71,7 @@ public extension InterfaceBuilderNode {
colorMatched: xml.attributeValue(of: "colorMatched"),
device: xml.byKey("device").flatMap(decodeValue),
views: xml.byKey("objects")?.childrenNode.flatMap(decodeValue),
gestureRecognizers: xml.byKey("objects")?.childrenNode.flatMap(decodeValue),
placeholders: xml.byKey("objects")?.byKey("placeholder")?.allElements.flatMap(decodeValue)
)
}
Expand All @@ -92,11 +94,13 @@ public extension InterfaceBuilderNode {
public struct Scene: XMLDecodable {
public let id: String
public let viewController: ViewController?
public let gestureRecognizers: [GestureRecognizer]?

static func decode(_ xml: XMLIndexerProtocol) throws -> InterfaceBuilderNode.Scene {
return Scene.init(
id: try xml.attributeValue(of: "sceneID"),
viewController: xml.byKey("objects")?.childrenNode.first.flatMap(decodeValue)
id: try xml.attributeValue(of: "sceneID"),
viewController: xml.byKey("objects")?.childrenNode.flatMap(decodeValue).first,
gestureRecognizers: xml.byKey("objects")?.childrenNode.flatMap(decodeValue)
)
}
}
Expand Down Expand Up @@ -143,13 +147,37 @@ public extension InterfaceBuilderNode {
}
}

public struct GestureRecognizer: XMLDecodable {

static let classNames: [String] = [
"tapGestureRecognizer", "pinchGestureRecognizer",
"rotationGestureRecognizer", "swipeGestureRecognizer",
"panGestureRecognizer", "screenEdgePanGestureRecognizer",
"pongPressGestureRecognizer", "gestureRecognizer",
]

public let connections: [InterfaceBuilderNode.View.Connection]?

static func decode(_ xml: XMLIndexerProtocol) throws -> InterfaceBuilderNode.GestureRecognizer {
guard let elementName = xml.elementNode?.name, classNames.contains(elementName) else {
throw Error.elementNotFound
}

return GestureRecognizer.init(
connections: xml.byKey("connections")?.childrenNode.flatMap(decodeValue)
)
}
}

public enum Error: Swift.Error, CustomStringConvertible {
case elementNotFound
case unsupportedViewClass(String)
case unsupportedViewControllerClass(String)
case unsupportedConstraint(String)
case unsupportedTableViewDataMode(String)
case unsupportedColorSpace(String)
case unsupportedConnectionType(String)
case notViewElement

public var description: String {
switch self {
Expand All @@ -165,6 +193,10 @@ public extension InterfaceBuilderNode {
return "unsupported dataMode '\(name)'"
case .unsupportedColorSpace(let colorSpace):
return "unsupported color space '\(colorSpace)'"
case .unsupportedConnectionType(let connectionType):
return "unsupported connection type \(connectionType)"
case .notViewElement:
return "not view element"
}
}
}
Expand Down
Loading