Skip to content

Commit b19b34a

Browse files
committed
Updated project to Swift 4. Used WKWebView from IB, removed wrapper. Refactored code, created HTML and PDF classes.
1 parent aa02067 commit b19b34a

File tree

17 files changed

+272
-229
lines changed

17 files changed

+272
-229
lines changed

HTMLWithImagesToPDF.xcodeproj/project.pbxproj

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,30 @@
1010
CE018BA41F3FAFA0007EB8D2 /* index-img.html in Resources */ = {isa = PBXBuildFile; fileRef = CE018BA31F3FAFA0007EB8D2 /* index-img.html */; };
1111
CEBD8AF61F3E5DD60068CD11 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEBD8AF51F3E5DD60068CD11 /* AppDelegate.swift */; };
1212
CEBD8AF81F3E5DD60068CD11 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEBD8AF71F3E5DD60068CD11 /* ViewController.swift */; };
13-
CEBD8AFB1F3E5DD60068CD11 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CEBD8AF91F3E5DD60068CD11 /* Main.storyboard */; };
1413
CEBD8AFD1F3E5DD60068CD11 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CEBD8AFC1F3E5DD60068CD11 /* Assets.xcassets */; };
15-
CEBD8B001F3E5DD60068CD11 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CEBD8AFE1F3E5DD60068CD11 /* LaunchScreen.storyboard */; };
1614
CEBD8B0A1F3E616D0068CD11 /* index.html in Resources */ = {isa = PBXBuildFile; fileRef = CEBD8B091F3E616D0068CD11 /* index.html */; };
1715
CEBD8B0C1F3E65130068CD11 /* apple.png in Resources */ = {isa = PBXBuildFile; fileRef = CEBD8B0B1F3E65130068CD11 /* apple.png */; };
18-
CEBD8B0E1F3F751F0068CD11 /* WKWebViewWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEBD8B0D1F3F751F0068CD11 /* WKWebViewWrapper.swift */; };
1916
CEBD8B101F3F76F70068CD11 /* UIAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEBD8B0F1F3F76F70068CD11 /* UIAlertController.swift */; };
17+
CEF30F3C1F72CBFD0040E6FF /* HTML.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEF30F3B1F72CBFD0040E6FF /* HTML.swift */; };
18+
CEF30F3E1F72CDF90040E6FF /* PDF.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEF30F3D1F72CDF90040E6FF /* PDF.swift */; };
19+
CEF30F401F72D6070040E6FF /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CEF30F371F72CB300040E6FF /* Main.storyboard */; };
20+
CEF30F411F72D60A0040E6FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CEF30F381F72CB310040E6FF /* LaunchScreen.storyboard */; };
2021
/* End PBXBuildFile section */
2122

2223
/* Begin PBXFileReference section */
2324
CE018BA31F3FAFA0007EB8D2 /* index-img.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "index-img.html"; sourceTree = "<group>"; };
2425
CEBD8AF21F3E5DD60068CD11 /* HTMLWithImagesToPDF.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HTMLWithImagesToPDF.app; sourceTree = BUILT_PRODUCTS_DIR; };
2526
CEBD8AF51F3E5DD60068CD11 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
2627
CEBD8AF71F3E5DD60068CD11 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
27-
CEBD8AFA1F3E5DD60068CD11 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
2828
CEBD8AFC1F3E5DD60068CD11 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
29-
CEBD8AFF1F3E5DD60068CD11 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
3029
CEBD8B011F3E5DD60068CD11 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3130
CEBD8B091F3E616D0068CD11 /* index.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = index.html; sourceTree = "<group>"; };
3231
CEBD8B0B1F3E65130068CD11 /* apple.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = apple.png; sourceTree = "<group>"; };
33-
CEBD8B0D1F3F751F0068CD11 /* WKWebViewWrapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WKWebViewWrapper.swift; sourceTree = "<group>"; };
3432
CEBD8B0F1F3F76F70068CD11 /* UIAlertController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIAlertController.swift; sourceTree = "<group>"; };
33+
CEF30F371F72CB300040E6FF /* Main.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
34+
CEF30F381F72CB310040E6FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
35+
CEF30F3B1F72CBFD0040E6FF /* HTML.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTML.swift; sourceTree = "<group>"; };
36+
CEF30F3D1F72CDF90040E6FF /* PDF.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDF.swift; sourceTree = "<group>"; };
3537
/* End PBXFileReference section */
3638

3739
/* Begin PBXFrameworksBuildPhase section */
@@ -64,26 +66,23 @@
6466
CEBD8AF41F3E5DD60068CD11 /* HTMLWithImagesToPDF */ = {
6567
isa = PBXGroup;
6668
children = (
67-
CEBD8AF51F3E5DD60068CD11 /* AppDelegate.swift */,
68-
CEBD8AF71F3E5DD60068CD11 /* ViewController.swift */,
69-
CEBD8B0D1F3F751F0068CD11 /* WKWebViewWrapper.swift */,
70-
CEBD8B0F1F3F76F70068CD11 /* UIAlertController.swift */,
71-
CEBD8B071F3E5DDE0068CD11 /* Storyboards */,
72-
CEBD8B081F3E5DEA0068CD11 /* Supporting Files */,
69+
CEF30F3A1F72CBBB0040E6FF /* Source */,
70+
CEF30F361F72CADF0040E6FF /* Storyboards */,
71+
CEF30F391F72CB6F0040E6FF /* Supporting Files */,
7372
);
7473
path = HTMLWithImagesToPDF;
7574
sourceTree = "<group>";
7675
};
77-
CEBD8B071F3E5DDE0068CD11 /* Storyboards */ = {
76+
CEF30F361F72CADF0040E6FF /* Storyboards */ = {
7877
isa = PBXGroup;
7978
children = (
80-
CEBD8AF91F3E5DD60068CD11 /* Main.storyboard */,
81-
CEBD8AFE1F3E5DD60068CD11 /* LaunchScreen.storyboard */,
79+
CEF30F371F72CB300040E6FF /* Main.storyboard */,
80+
CEF30F381F72CB310040E6FF /* LaunchScreen.storyboard */,
8281
);
83-
name = Storyboards;
82+
path = Storyboards;
8483
sourceTree = "<group>";
8584
};
86-
CEBD8B081F3E5DEA0068CD11 /* Supporting Files */ = {
85+
CEF30F391F72CB6F0040E6FF /* Supporting Files */ = {
8786
isa = PBXGroup;
8887
children = (
8988
CEBD8AFC1F3E5DD60068CD11 /* Assets.xcassets */,
@@ -92,7 +91,27 @@
9291
CE018BA31F3FAFA0007EB8D2 /* index-img.html */,
9392
CEBD8B0B1F3E65130068CD11 /* apple.png */,
9493
);
95-
name = "Supporting Files";
94+
path = "Supporting Files";
95+
sourceTree = "<group>";
96+
};
97+
CEF30F3A1F72CBBB0040E6FF /* Source */ = {
98+
isa = PBXGroup;
99+
children = (
100+
CEBD8AF51F3E5DD60068CD11 /* AppDelegate.swift */,
101+
CEBD8AF71F3E5DD60068CD11 /* ViewController.swift */,
102+
CEF30F3B1F72CBFD0040E6FF /* HTML.swift */,
103+
CEF30F3D1F72CDF90040E6FF /* PDF.swift */,
104+
CEF30F3F1F72CE400040E6FF /* Extensions */,
105+
);
106+
path = Source;
107+
sourceTree = "<group>";
108+
};
109+
CEF30F3F1F72CE400040E6FF /* Extensions */ = {
110+
isa = PBXGroup;
111+
children = (
112+
CEBD8B0F1F3F76F70068CD11 /* UIAlertController.swift */,
113+
);
114+
path = Extensions;
96115
sourceTree = "<group>";
97116
};
98117
/* End PBXGroup section */
@@ -122,12 +141,13 @@
122141
isa = PBXProject;
123142
attributes = {
124143
LastSwiftUpdateCheck = 0830;
125-
LastUpgradeCheck = 0830;
144+
LastUpgradeCheck = 0900;
126145
ORGANIZATIONNAME = nyg;
127146
TargetAttributes = {
128147
CEBD8AF11F3E5DD60068CD11 = {
129148
CreatedOnToolsVersion = 8.3.3;
130149
DevelopmentTeam = 7BPPXA6BRU;
150+
LastSwiftMigration = 0900;
131151
ProvisioningStyle = Automatic;
132152
};
133153
};
@@ -137,8 +157,6 @@
137157
developmentRegion = English;
138158
hasScannedForEncodings = 0;
139159
knownRegions = (
140-
en,
141-
Base,
142160
);
143161
mainGroup = CEBD8AE91F3E5DD50068CD11;
144162
productRefGroup = CEBD8AF31F3E5DD60068CD11 /* Products */;
@@ -156,9 +174,9 @@
156174
buildActionMask = 2147483647;
157175
files = (
158176
CEBD8B0A1F3E616D0068CD11 /* index.html in Resources */,
159-
CEBD8B001F3E5DD60068CD11 /* LaunchScreen.storyboard in Resources */,
177+
CEF30F401F72D6070040E6FF /* Main.storyboard in Resources */,
160178
CEBD8AFD1F3E5DD60068CD11 /* Assets.xcassets in Resources */,
161-
CEBD8AFB1F3E5DD60068CD11 /* Main.storyboard in Resources */,
179+
CEF30F411F72D60A0040E6FF /* LaunchScreen.storyboard in Resources */,
162180
CEBD8B0C1F3E65130068CD11 /* apple.png in Resources */,
163181
CE018BA41F3FAFA0007EB8D2 /* index-img.html in Resources */,
164182
);
@@ -172,33 +190,15 @@
172190
buildActionMask = 2147483647;
173191
files = (
174192
CEBD8B101F3F76F70068CD11 /* UIAlertController.swift in Sources */,
193+
CEF30F3E1F72CDF90040E6FF /* PDF.swift in Sources */,
175194
CEBD8AF81F3E5DD60068CD11 /* ViewController.swift in Sources */,
195+
CEF30F3C1F72CBFD0040E6FF /* HTML.swift in Sources */,
176196
CEBD8AF61F3E5DD60068CD11 /* AppDelegate.swift in Sources */,
177-
CEBD8B0E1F3F751F0068CD11 /* WKWebViewWrapper.swift in Sources */,
178197
);
179198
runOnlyForDeploymentPostprocessing = 0;
180199
};
181200
/* End PBXSourcesBuildPhase section */
182201

183-
/* Begin PBXVariantGroup section */
184-
CEBD8AF91F3E5DD60068CD11 /* Main.storyboard */ = {
185-
isa = PBXVariantGroup;
186-
children = (
187-
CEBD8AFA1F3E5DD60068CD11 /* Base */,
188-
);
189-
name = Main.storyboard;
190-
sourceTree = "<group>";
191-
};
192-
CEBD8AFE1F3E5DD60068CD11 /* LaunchScreen.storyboard */ = {
193-
isa = PBXVariantGroup;
194-
children = (
195-
CEBD8AFF1F3E5DD60068CD11 /* Base */,
196-
);
197-
name = LaunchScreen.storyboard;
198-
sourceTree = "<group>";
199-
};
200-
/* End PBXVariantGroup section */
201-
202202
/* Begin XCBuildConfiguration section */
203203
CEBD8B021F3E5DD60068CD11 /* Debug */ = {
204204
isa = XCBuildConfiguration;
@@ -210,15 +210,21 @@
210210
CLANG_CXX_LIBRARY = "libc++";
211211
CLANG_ENABLE_MODULES = YES;
212212
CLANG_ENABLE_OBJC_ARC = YES;
213+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
213214
CLANG_WARN_BOOL_CONVERSION = YES;
215+
CLANG_WARN_COMMA = YES;
214216
CLANG_WARN_CONSTANT_CONVERSION = YES;
215217
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
216218
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
217219
CLANG_WARN_EMPTY_BODY = YES;
218220
CLANG_WARN_ENUM_CONVERSION = YES;
219221
CLANG_WARN_INFINITE_RECURSION = YES;
220222
CLANG_WARN_INT_CONVERSION = YES;
223+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
224+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
221225
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
226+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
227+
CLANG_WARN_STRICT_PROTOTYPES = YES;
222228
CLANG_WARN_SUSPICIOUS_MOVE = YES;
223229
CLANG_WARN_UNREACHABLE_CODE = YES;
224230
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -241,7 +247,7 @@
241247
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
242248
GCC_WARN_UNUSED_FUNCTION = YES;
243249
GCC_WARN_UNUSED_VARIABLE = YES;
244-
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
250+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
245251
MTL_ENABLE_DEBUG_INFO = YES;
246252
ONLY_ACTIVE_ARCH = YES;
247253
SDKROOT = iphoneos;
@@ -261,15 +267,21 @@
261267
CLANG_CXX_LIBRARY = "libc++";
262268
CLANG_ENABLE_MODULES = YES;
263269
CLANG_ENABLE_OBJC_ARC = YES;
270+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
264271
CLANG_WARN_BOOL_CONVERSION = YES;
272+
CLANG_WARN_COMMA = YES;
265273
CLANG_WARN_CONSTANT_CONVERSION = YES;
266274
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
267275
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
268276
CLANG_WARN_EMPTY_BODY = YES;
269277
CLANG_WARN_ENUM_CONVERSION = YES;
270278
CLANG_WARN_INFINITE_RECURSION = YES;
271279
CLANG_WARN_INT_CONVERSION = YES;
280+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
281+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
272282
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
283+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
284+
CLANG_WARN_STRICT_PROTOTYPES = YES;
273285
CLANG_WARN_SUSPICIOUS_MOVE = YES;
274286
CLANG_WARN_UNREACHABLE_CODE = YES;
275287
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -286,7 +298,7 @@
286298
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
287299
GCC_WARN_UNUSED_FUNCTION = YES;
288300
GCC_WARN_UNUSED_VARIABLE = YES;
289-
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
301+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
290302
MTL_ENABLE_DEBUG_INFO = NO;
291303
SDKROOT = iphoneos;
292304
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
@@ -300,11 +312,12 @@
300312
buildSettings = {
301313
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
302314
DEVELOPMENT_TEAM = 7BPPXA6BRU;
303-
INFOPLIST_FILE = HTMLWithImagesToPDF/Info.plist;
315+
INFOPLIST_FILE = "HTMLWithImagesToPDF/Supporting Files/Info.plist";
304316
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
305317
PRODUCT_BUNDLE_IDENTIFIER = ch.nyg.HTMLWithImagesToPDF;
306318
PRODUCT_NAME = "$(TARGET_NAME)";
307-
SWIFT_VERSION = 3.0;
319+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
320+
SWIFT_VERSION = 4.0;
308321
};
309322
name = Debug;
310323
};
@@ -313,11 +326,12 @@
313326
buildSettings = {
314327
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
315328
DEVELOPMENT_TEAM = 7BPPXA6BRU;
316-
INFOPLIST_FILE = HTMLWithImagesToPDF/Info.plist;
329+
INFOPLIST_FILE = "HTMLWithImagesToPDF/Supporting Files/Info.plist";
317330
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
318331
PRODUCT_BUNDLE_IDENTIFIER = ch.nyg.HTMLWithImagesToPDF;
319332
PRODUCT_NAME = "$(TARGET_NAME)";
320-
SWIFT_VERSION = 3.0;
333+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
334+
SWIFT_VERSION = 4.0;
321335
};
322336
name = Release;
323337
};
File renamed without changes.

HTMLWithImagesToPDF/UIAlertController.swift renamed to HTMLWithImagesToPDF/Source/Extensions/UIAlertController.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ import UIKit
1010

1111
extension UIAlertController {
1212

13-
func addAction(title: String?, style: UIAlertActionStyle = .default, handler: ((UIAlertAction) -> Void)? = nil) {
13+
@discardableResult
14+
func addAction(title: String?, style: UIAlertActionStyle = .default, handler: ((UIAlertAction) -> Void)? = nil) -> Self {
1415
addAction(UIAlertAction(title: title, style: style, handler: handler))
16+
return self
17+
}
18+
19+
func present(by viewController: UIViewController) {
20+
viewController.present(self, animated: true)
1521
}
1622
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// HTML.swift
3+
// HTMLWithImagesToPDF
4+
//
5+
// Created by user on 20.09.17.
6+
// Copyright © 2017 nyg. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class HTML {
12+
13+
/**
14+
Reads the given HTML file and replaces `{{ABSOLUTE_PATH}}` and `{{BASE64_STRING}}` with proper values.
15+
16+
- parameters:
17+
- fileName: The name of the HTML file.
18+
19+
- returns: The transformed HTML code.
20+
*/
21+
class func get(from fileName: String) -> String {
22+
23+
guard let htmlFile = Bundle.main.url(forResource: fileName, withExtension: nil)
24+
else { fatalError("Error locating HTML file.") }
25+
26+
guard let htmlContent = try? String(contentsOf: htmlFile)
27+
else { fatalError("Error getting HTML file content.") }
28+
29+
guard let imageURL = Bundle.main.url(forResource: "apple", withExtension: "png")
30+
else { fatalError("Error locating image file.") }
31+
32+
// create base64-encoded string of the "apple" image (located in Assets.xcassets)
33+
guard let base64String = UIImagePNGRepresentation(#imageLiteral(resourceName: "apple"))?.base64EncodedString()
34+
else { fatalError("Error creating PNG representation.") }
35+
36+
return htmlContent
37+
.replacingOccurrences(of: "{{ABSOLUTE_PATH}}", with: imageURL.description)
38+
.replacingOccurrences(of: "{{BASE64_STRING}}", with: base64String)
39+
}
40+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
//
2+
// PDF.swift
3+
// HTMLWithImagesToPDF
4+
//
5+
// Created by user on 20.09.17.
6+
// Copyright © 2017 nyg. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
class PDF {
12+
13+
/**
14+
Generates a PDF using the given print formatter and saves it to the user's document directory.
15+
16+
- parameters:
17+
- printFormatter: The print formatter used to generate the PDF.
18+
19+
- returns: The generated PDF.
20+
*/
21+
class func generate(using printFormatter: UIPrintFormatter) -> Data {
22+
23+
// assign the print formatter to the print page renderer
24+
let renderer = UIPrintPageRenderer()
25+
renderer.addPrintFormatter(printFormatter, startingAtPageAt: 0)
26+
27+
// assign paperRect and printableRect values
28+
let page = CGRect(x: 0, y: 0, width: 595.2, height: 841.8) // A4, 72 dpi
29+
renderer.setValue(page, forKey: "paperRect")
30+
renderer.setValue(page, forKey: "printableRect")
31+
32+
// create pdf context and draw each page
33+
let pdfData = NSMutableData()
34+
UIGraphicsBeginPDFContextToData(pdfData, .zero, nil)
35+
36+
for i in 0..<renderer.numberOfPages {
37+
UIGraphicsBeginPDFPage()
38+
renderer.drawPage(at: i, in: UIGraphicsGetPDFContextBounds())
39+
}
40+
41+
UIGraphicsEndPDFContext();
42+
43+
// save data to a pdf file and return
44+
guard nil != (try? pdfData.write(to: outputURL, options: .atomic))
45+
else { fatalError("Error writing PDF data to file.") }
46+
47+
return pdfData as Data
48+
}
49+
50+
private class var outputURL: URL {
51+
52+
guard let directory = try? FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
53+
else { fatalError("Error getting user's document directory.") }
54+
55+
let url = directory.appendingPathComponent(outputFileName).appendingPathExtension("pdf")
56+
print("open \(url.path)")
57+
return url
58+
}
59+
60+
private class var outputFileName: String {
61+
return "generated-\(Int(Date().timeIntervalSince1970))"
62+
}
63+
}
File renamed without changes.

0 commit comments

Comments
 (0)