Skip to content
This repository was archived by the owner on Jun 17, 2023. It is now read-only.

Commit f6e155a

Browse files
committed
Complete exporting Xcode project
1 parent a2e2685 commit f6e155a

File tree

15 files changed

+648
-3
lines changed

15 files changed

+648
-3
lines changed

.swiftlint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ opt_in_rules:
3737
excluded:
3838
- Package.swift
3939
- Pods
40+
- PagingLayoutSamples/SampleProject
4041

4142
# adjusting rules
4243

Samples/PagingLayoutSamples.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
29A2D3D324B73A19005A0F6B /* LayoutDesignerIntroCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A2D3D224B73A19005A0F6B /* LayoutDesignerIntroCell.swift */; };
2626
29A2D3D524B73AB7005A0F6B /* LayoutDesignerIntroInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29A2D3D424B73AB7005A0F6B /* LayoutDesignerIntroInfo.swift */; };
2727
29A2D3D724B73CB1005A0F6B /* LayoutDesignerIntroCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 29A2D3D624B73CB1005A0F6B /* LayoutDesignerIntroCell.xib */; };
28+
29A2D3FC24B769D7005A0F6B /* SampleProject in Resources */ = {isa = PBXBuildFile; fileRef = 29A2D3FB24B769D7005A0F6B /* SampleProject */; };
2829
29B5A72024A7B02900C9843E /* ShapeLayout+StackOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29B5A71F24A7B02900C9843E /* ShapeLayout+StackOptions.swift */; };
2930
29B5A72224A7B06300C9843E /* ShapeLayout+SnapshotOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29B5A72124A7B06300C9843E /* ShapeLayout+SnapshotOptions.swift */; };
3031
29B5A72424A8CC4B00C9843E /* CGFloat+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29B5A72324A8CC4B00C9843E /* CGFloat+String.swift */; };
@@ -134,6 +135,7 @@
134135
29A2D3D224B73A19005A0F6B /* LayoutDesignerIntroCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutDesignerIntroCell.swift; sourceTree = "<group>"; };
135136
29A2D3D424B73AB7005A0F6B /* LayoutDesignerIntroInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutDesignerIntroInfo.swift; sourceTree = "<group>"; };
136137
29A2D3D624B73CB1005A0F6B /* LayoutDesignerIntroCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LayoutDesignerIntroCell.xib; sourceTree = "<group>"; };
138+
29A2D3FB24B769D7005A0F6B /* SampleProject */ = {isa = PBXFileReference; lastKnownFileType = folder; path = SampleProject; sourceTree = "<group>"; };
137139
29B5A71F24A7B02900C9843E /* ShapeLayout+StackOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ShapeLayout+StackOptions.swift"; sourceTree = "<group>"; };
138140
29B5A72124A7B06300C9843E /* ShapeLayout+SnapshotOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ShapeLayout+SnapshotOptions.swift"; sourceTree = "<group>"; };
139141
29B5A72324A8CC4B00C9843E /* CGFloat+String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CGFloat+String.swift"; sourceTree = "<group>"; };
@@ -389,6 +391,7 @@
389391
AB500A3123B104E20056BE37 /* PagingLayoutSamples */ = {
390392
isa = PBXGroup;
391393
children = (
394+
29A2D3FB24B769D7005A0F6B /* SampleProject */,
392395
292489AD2461A57900A316B0 /* Paging Layout.entitlements */,
393396
AB1E03AD23B25CD30087F904 /* CustomViews */,
394397
AB500A5223B152170056BE37 /* Modules */,
@@ -635,6 +638,7 @@
635638
AB7C1E0823B4E2C0006441DE /* MainViewController.xib in Resources */,
636639
ABA1A72E23B42247006A46A3 /* PriceTagView.xib in Resources */,
637640
29A2D3AA24B72895005A0F6B /* LayoutDesignerCodePreviewViewController.xib in Resources */,
641+
29A2D3FC24B769D7005A0F6B /* SampleProject in Resources */,
638642
ABA1A73323B422B9006A46A3 /* QuantityControllerView.xib in Resources */,
639643
);
640644
runOnlyForDeploymentPostprocessing = 0;

Samples/PagingLayoutSamples/Modules/LayoutDesigner/Code/LayoutDesignerCodePreviewViewController.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ class LayoutDesignerCodePreviewViewController: UIViewController, NibBased, ViewM
4949
}
5050

5151
@IBAction private func saveButtonTouched() {
52-
refreshViews()
52+
guard let exportURL = viewModel.sampleProjectTempURL else { return }
53+
viewModel.generateSampleProject()
54+
let controller = UIDocumentPickerViewController(url: exportURL, in: UIDocumentPickerMode.exportToService)
55+
controller.delegate = self
56+
present(controller, animated: true)
5357
}
5458

5559
@IBAction private func onHelpButtonTouched() {
@@ -81,7 +85,6 @@ class LayoutDesignerCodePreviewViewController: UIViewController, NibBased, ViewM
8185
codeModeSegmentedControl.setTitleTextAttributes([.foregroundColor: UIColor.white], for: .normal)
8286
codeModeSegmentedControl.setTitleTextAttributes([.foregroundColor: UIColor.black.withAlphaComponent(0.6)], for: .selected)
8387
codeModeSegmentedControl.selectedSegmentIndex = 0
84-
8588
}
8689

8790
private func configureTextView() {
@@ -97,3 +100,16 @@ class LayoutDesignerCodePreviewViewController: UIViewController, NibBased, ViewM
97100

98101

99102
}
103+
104+
105+
extension LayoutDesignerCodePreviewViewController: UIDocumentPickerDelegate {
106+
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
107+
controller.dismiss(animated: true)
108+
viewModel.removeSampleProject()
109+
}
110+
111+
func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
112+
controller.dismiss(animated: true)
113+
viewModel.removeSampleProject()
114+
}
115+
}

Samples/PagingLayoutSamples/Modules/LayoutDesigner/Code/LayoutDesignerCodePreviewViewModel.swift

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ struct LayoutDesignerCodePreviewViewModel {
1414
// MARK: Properties
1515

1616
let code: String
17+
var sampleProjectTempURL: URL? {
18+
FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("SampleProject")
19+
}
1720

1821
private let highlighter = SyntaxHighlighter(format: AttributedStringOutputFormat(theme: .sundellsColors(withFont: Font(size: 14))))
1922

@@ -24,10 +27,32 @@ struct LayoutDesignerCodePreviewViewModel {
2427
highlighter.highlight(getCode(includeViewController: includeVC))
2528
}
2629

30+
func generateSampleProject() {
31+
removeSampleProject()
32+
guard let sampleProjectTempURL = sampleProjectTempURL,
33+
let sampleProjectURL = Bundle.main.url(forResource: "SampleProject", withExtension: nil) else {
34+
return
35+
}
36+
try? FileManager.default.copyItem(at: sampleProjectURL, to: sampleProjectTempURL)
37+
38+
let viewControllerPath = sampleProjectTempURL.appendingPathComponent("PagingLayout").appendingPathComponent("ViewController.swift")
39+
try? FileManager.default.removeItem(at: viewControllerPath)
40+
41+
let code = getCode(includeViewController: true)
42+
try? code.write(to: viewControllerPath, atomically: true, encoding: .utf8)
43+
}
44+
45+
func removeSampleProject() {
46+
guard let sampleProjectTempURL = sampleProjectTempURL else {
47+
return
48+
}
49+
try? FileManager.default.removeItem(at: sampleProjectTempURL)
50+
}
51+
2752

2853
// MARK: Private functions
2954

30-
func getCode(includeViewController: Bool) -> String {
55+
private func getCode(includeViewController: Bool) -> String {
3156
if !includeViewController {
3257
return code
3358
}

Samples/PagingLayoutSamples/Paging Layout.entitlements

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<dict>
55
<key>com.apple.security.app-sandbox</key>
66
<true/>
7+
<key>com.apple.security.files.user-selected.read-write</key>
8+
<true/>
79
<key>com.apple.security.network.client</key>
810
<true/>
911
</dict>

0 commit comments

Comments
 (0)