Skip to content

Commit 20d23e6

Browse files
committed
Initial commit
0 parents  commit 20d23e6

File tree

6 files changed

+125
-0
lines changed

6 files changed

+125
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/
6+
DerivedData/
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Package.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// swift-tools-version:5.5
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "ValueTypes",
8+
products: [
9+
// Products define the executables and libraries a package produces, and make them visible to other packages.
10+
.library(
11+
name: "ValueTypes",
12+
targets: ["ValueTypes"]),
13+
],
14+
dependencies: [
15+
// Dependencies declare other packages that this package depends on.
16+
// .package(url: /* package url */, from: "1.0.0"),
17+
],
18+
targets: [
19+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
20+
// Targets can depend on other targets in this package, and on products in packages this package depends on.
21+
.target(
22+
name: "ValueTypes",
23+
dependencies: []),
24+
.testTarget(
25+
name: "ValueTypesTests",
26+
dependencies: ["ValueTypes"]),
27+
]
28+
)

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# ValueTypes
2+
3+
A description of this package.

Sources/ValueTypes/Project.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import Foundation
2+
3+
public struct Project {
4+
public init() {
5+
}
6+
7+
var pages: [Page] = []
8+
}
9+
10+
public struct Page {
11+
public var frame: CGRect = .zero
12+
var pageObjects: [PageObject] = []
13+
}
14+
15+
public protocol PageObject {
16+
var frame: CGRect { get set }
17+
}
18+
19+
public struct TextObject: PageObject {
20+
public var frame: CGRect = .zero
21+
public var text: String = ""
22+
}
23+
24+
public struct ImageObject: PageObject {
25+
public var frame: CGRect = .zero
26+
public var imagePath: URL?
27+
}
28+
29+
public struct Group: PageObject {
30+
public var frame: CGRect = .zero
31+
public var pageObjects: [PageObject] = []
32+
}
33+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import XCTest
2+
@testable import ValueTypes
3+
4+
final class ValueTypesTests: XCTestCase {
5+
func testExample() throws {
6+
var project = makeProject()
7+
8+
// Shift all objects inside of a group on some page
9+
for i in 0..<project.pages.count {
10+
var page = project.pages[i]
11+
12+
for j in 0..<page.pageObjects.count {
13+
let pageObject = page.pageObjects[j]
14+
15+
if var group = pageObject as? Group {
16+
for k in 0..<group.pageObjects.count {
17+
var pageObject = group.pageObjects[k]
18+
19+
let shiftedFrame = pageObject.frame.applying(CGAffineTransform(translationX: 10, y: 10))
20+
pageObject.frame = shiftedFrame
21+
22+
// Write back changed page object
23+
group.pageObjects[k] = pageObject
24+
}
25+
26+
// Write back changed group
27+
page.pageObjects[j] = group
28+
}
29+
}
30+
31+
// Write back changed page
32+
project.pages[i] = page
33+
}
34+
}
35+
36+
func makeProject() -> Project {
37+
let sheetSize = CGSize(width: 2000, height: 500)
38+
39+
var project = Project()
40+
project.pages = [Page(frame: CGRect(origin: .zero, size: sheetSize)), Page(frame: CGRect(origin: .zero, size: sheetSize))]
41+
let group = Group(frame: CGRect(x: 100, y: 100, width: 800, height: 400), pageObjects: [TextObject(), ImageObject()])
42+
project.pages[0].pageObjects = [TextObject(), ImageObject(), group]
43+
44+
return project
45+
}
46+
}

0 commit comments

Comments
 (0)