diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj
index b10eb193b..2e89a99ee 100644
--- a/Example/Example.xcodeproj/project.pbxproj
+++ b/Example/Example.xcodeproj/project.pbxproj
@@ -371,7 +371,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
- shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
+ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
064D38CE83FACC358B7C0EC8 /* 📦 Copy Pods Resources */ = {
@@ -416,7 +416,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
- shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
+ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
52EDD0255393518C859DA01C /* 📦 Embed Pods Frameworks */ = {
@@ -461,7 +461,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
- shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
+ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
8F716768EB59E9B6D88C48D7 /* [CP] Copy Pods Resources */ = {
@@ -752,7 +752,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 5C8EADB52E1D834750CD7D23 /* Pods-Example.debug.xcconfig */;
buildSettings = {
- ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
+ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = 32F2T8EJ6G;
@@ -760,7 +760,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.folioreader.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
- SWIFT_VERSION = 2.3;
+ SWIFT_VERSION = 3.0;
};
name = Debug;
};
@@ -768,7 +768,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = F4CBB0C2C0FDFA3E1648DB43 /* Pods-Example.release.xcconfig */;
buildSettings = {
- ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
+ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = 32F2T8EJ6G;
@@ -776,7 +776,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.folioreader.Example;
PRODUCT_NAME = "$(TARGET_NAME)";
- SWIFT_VERSION = 2.3;
+ SWIFT_VERSION = 3.0;
};
name = Release;
};
@@ -784,7 +784,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 3CE90B4095B5C7E6237EEBDD /* Pods-FolioReaderTests.debug.xcconfig */;
buildSettings = {
- ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
+ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
BUNDLE_LOADER = "$(TEST_HOST)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = 32F2T8EJ6G;
@@ -793,7 +793,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.folioreader.FolioReaderTests;
PRODUCT_NAME = "$(TARGET_NAME)";
- SWIFT_VERSION = 2.3;
+ SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example";
};
name = Debug;
@@ -802,7 +802,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 8E1BE6465444C567F5D1B8E6 /* Pods-FolioReaderTests.release.xcconfig */;
buildSettings = {
- ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
+ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
BUNDLE_LOADER = "$(TEST_HOST)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEVELOPMENT_TEAM = 32F2T8EJ6G;
@@ -811,7 +811,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.folioreader.FolioReaderTests;
PRODUCT_NAME = "$(TARGET_NAME)";
- SWIFT_VERSION = 2.3;
+ SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example";
};
name = Release;
@@ -820,7 +820,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = D7C82C879F323C6E960F882B /* Pods-StoryboardExample.debug.xcconfig */;
buildSettings = {
- ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
+ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ANALYZER_NONNULL = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -830,6 +830,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.folioreader.StoryboardExample;
PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_VERSION = 3.0;
};
name = Debug;
};
@@ -837,7 +838,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 1D4790507F22E69298DC06E1 /* Pods-StoryboardExample.release.xcconfig */;
buildSettings = {
- ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
+ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = "$(inherited)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ANALYZER_NONNULL = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -847,6 +848,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.folioreader.StoryboardExample;
PRODUCT_NAME = "$(TARGET_NAME)";
+ SWIFT_VERSION = 3.0;
};
name = Release;
};
diff --git a/Example/Example/AppDelegate.swift b/Example/Example/AppDelegate.swift
index 5c7a14cc6..9353ee387 100644
--- a/Example/Example/AppDelegate.swift
+++ b/Example/Example/AppDelegate.swift
@@ -14,16 +14,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
- func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
+ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
- func applicationWillResignActive(application: UIApplication) {
+ func applicationWillResignActive(_ application: UIApplication) {
FolioReader.applicationWillResignActive()
}
- func applicationWillTerminate(application: UIApplication) {
+ func applicationWillTerminate(_ application: UIApplication) {
FolioReader.applicationWillTerminate()
}
diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift
index cd9639ed2..093e199af 100755
--- a/Example/Example/ViewController.swift
+++ b/Example/Example/ViewController.swift
@@ -25,11 +25,11 @@ class ViewController: UIViewController {
setCover(bookTwo, index: 1)
}
- @IBAction func didOpen(sender: AnyObject) {
+ @IBAction func didOpen(_ sender: AnyObject) {
openEpub(sender.tag);
}
- func openEpub(sampleNum: Int) {
+ func openEpub(_ sampleNum: Int) {
let config = FolioReaderConfig()
config.shouldHideNavigationOnTap = sampleNum == 1 ? true : false
config.scrollDirection = sampleNum == 1 ? .horizontal : .vertical
@@ -45,23 +45,23 @@ class ViewController: UIViewController {
// config.menuBackgroundColor = UIColor.lightGrayColor()
// Custom sharing quote background
- let customImageQuote = QuoteImage(withImage: UIImage(named: "demo-bg")!, alpha: 0.6, backgroundColor: UIColor.blackColor())
+ let customImageQuote = QuoteImage(withImage: UIImage(named: "demo-bg")!, alpha: 0.6, backgroundColor: UIColor.black)
let customQuote = QuoteImage(withColor: UIColor(red:0.30, green:0.26, blue:0.20, alpha:1.0), alpha: 1.0, textColor: UIColor(red:0.86, green:0.73, blue:0.70, alpha:1.0))
config.quoteCustomBackgrounds = [customImageQuote, customQuote]
// Epub file
let epubName = epubSampleFiles[sampleNum-1];
- let bookPath = NSBundle.mainBundle().pathForResource(epubName, ofType: "epub")
+ let bookPath = Bundle.main.path(forResource: epubName, ofType: "epub")
FolioReader.presentReader(parentViewController: self, withEpubPath: bookPath!, andConfig: config, shouldRemoveEpub: false)
}
- func setCover(button: UIButton, index: Int) {
+ func setCover(_ button: UIButton, index: Int) {
let epubName = epubSampleFiles[index];
- let bookPath = NSBundle.mainBundle().pathForResource(epubName, ofType: "epub")
+ let bookPath = Bundle.main.path(forResource: epubName, ofType: "epub")
if let image = FolioReader.getCoverImage(bookPath!) {
- button.setBackgroundImage(image, forState: .Normal)
+ button.setBackgroundImage(image, for: .normal)
}
}
}
diff --git a/Example/FolioReaderTests/FolioReaderTests.swift b/Example/FolioReaderTests/FolioReaderTests.swift
index dec6db055..8f9943c70 100644
--- a/Example/FolioReaderTests/FolioReaderTests.swift
+++ b/Example/FolioReaderTests/FolioReaderTests.swift
@@ -17,9 +17,10 @@ class FolioReaderTests: QuickSpec {
var subject: FREpubParser!
beforeEach {
- let path = NSBundle(forClass: self.dynamicType).pathForResource("The Silver Chair", ofType: "epub")!
+ let path = Bundle(for: type(of: self)).path(forResource: "The Silver Chair", ofType: "epub")!
subject = FREpubParser()
- subject.readEpub(epubPath: path)
+ let book = subject.readEpub(epubPath: path)
+ print(book?.tableOfContents.first?.title)
}
it("correctly parses a properly formatted document") {
diff --git a/Example/FolioReaderTests/SharingProviderTests.swift b/Example/FolioReaderTests/SharingProviderTests.swift
index c4441647b..02717d0f7 100644
--- a/Example/FolioReaderTests/SharingProviderTests.swift
+++ b/Example/FolioReaderTests/SharingProviderTests.swift
@@ -30,7 +30,7 @@ class SharingProviderTests: QuickSpec {
}
it("returns text for a mail activity") {
- let itemForActivityType = subject.activityViewController(activityViewController, itemForActivityType: UIActivityTypeMail) as? String
+ let itemForActivityType = subject.activityViewController(activityViewController, itemForActivityType: UIActivityType.mail) as? String
expect(itemForActivityType).to(equal(subject.text))
}
}
@@ -41,7 +41,7 @@ class SharingProviderTests: QuickSpec {
}
it("returns HTML for a mail activity") {
- let itemForActivityType = subject.activityViewController(activityViewController, itemForActivityType: UIActivityTypeMail) as? String
+ let itemForActivityType = subject.activityViewController(activityViewController, itemForActivityType: UIActivityType.mail) as? String
expect(itemForActivityType).to(equal(subject.html))
}
}
diff --git a/Example/Podfile b/Example/Podfile
index 4ab1cb243..3e63eda57 100755
--- a/Example/Podfile
+++ b/Example/Podfile
@@ -8,8 +8,8 @@ def shared_pods
end
def testing_pods
- pod 'Quick', '0.9.2'
- pod 'Nimble', '~> 4.1.0'
+ pod 'Quick', '0.10.0'
+ pod 'Nimble', '~> 5.0.0'
end
target 'Example' do
@@ -24,18 +24,3 @@ target 'FolioReaderTests' do
shared_pods
testing_pods
end
-
-
-post_install do |installer|
- installer.pods_project.targets.each do |target|
- target.build_configurations.each do |config|
- # Force add version
- config.build_settings['SWIFT_VERSION'] = '2.3'
-
- # ensure testability is set https://github.com/CocoaPods/CocoaPods/issues/4505
- if config.name == 'Debug'
- config.build_settings['ENABLE_TESTABILITY'] = 'YES'
- end
- end
- end
-end
diff --git a/Example/Podfile.lock b/Example/Podfile.lock
index 411dc1f8a..3be1f5312 100644
--- a/Example/Podfile.lock
+++ b/Example/Podfile.lock
@@ -1,16 +1,18 @@
PODS:
- - AEXML (3.0.0)
+ - AEXML (4.0.0)
- FolioReaderKit (0.9.4):
- - AEXML (= 3.0)
- - JSQWebViewController (~> 3.0)
- - MenuItemKit (= 1.1.3)
+ - AEXML (= 4.0)
+ - FontBlaster (= 3.0.0)
+ - JSQWebViewController (~> 5.0)
+ - MenuItemKit (= 2.0)
- RealmSwift (~> 1.0)
- SSZipArchive (= 1.5)
- ZFDragableModalTransition (~> 0.6)
- - JSQWebViewController (3.0.0)
- - MenuItemKit (1.1.3)
- - Nimble (4.1.0)
- - Quick (0.9.2)
+ - FontBlaster (3.0.0)
+ - JSQWebViewController (5.0.0)
+ - MenuItemKit (2.0)
+ - Nimble (5.0.0)
+ - Quick (0.10.0)
- Realm (1.1.0):
- Realm/Headers (= 1.1.0)
- Realm/Headers (1.1.0)
@@ -21,25 +23,26 @@ PODS:
DEPENDENCIES:
- FolioReaderKit (from `../`)
- - Nimble (~> 4.1.0)
- - Quick (= 0.9.2)
+ - Nimble (~> 5.0.0)
+ - Quick (= 0.10.0)
EXTERNAL SOURCES:
FolioReaderKit:
:path: "../"
SPEC CHECKSUMS:
- AEXML: 716fb0a8decba4a3517324a71fee3685b30233d2
- FolioReaderKit: 993c4bfb89e93c80bba3965feef3a49f70c25f95
- JSQWebViewController: eaa6bd68d9e1426ae25ade99c9bbde4c6cdd4120
- MenuItemKit: 11c448d9172936ee79ebb78f36dffd396020a9e5
- Nimble: 97a0a4cae5124c117115634b2d055d8c97d0af19
- Quick: 18d057bc66451eedd5d1c8dc99ba2a5db6e60226
+ AEXML: 6fc6433aa35bdc15dd8eb8d54eb7aa4520a010eb
+ FolioReaderKit: 600a04088ebaf0613c6681692aa65f477fe85a5c
+ FontBlaster: 0f4a3e2f965968e2dfc3f7f5cec7214c3f3b2f07
+ JSQWebViewController: 0461aa42612b221571556df61d9c09f080cb2eef
+ MenuItemKit: 9af69953dc983803ee85230e205fadbac0f26213
+ Nimble: 56fc9f5020effa2206de22c3dd910f4fb011b92f
+ Quick: 5d290df1c69d5ee2f0729956dcf0fd9a30447eaa
Realm: ceecf1a4540c4ce9efe196fe73fa9855bce05bd8
RealmSwift: 838058b2db95b12cb86bd0cf209df642c33fb60a
SSZipArchive: 29daace2bccb90a47de2837744da397728ff9207
ZFDragableModalTransition: 0d294eaaba6edfcb9839595de765f9ca06a4b524
-PODFILE CHECKSUM: 55962a6106e53da04861e4602fc98856987b97b3
+PODFILE CHECKSUM: b6c4012c0fafa1e10299b2246c12b2ff15d1d26d
-COCOAPODS: 1.0.1
+COCOAPODS: 1.1.0.rc.2
diff --git a/FolioReaderKit.podspec b/FolioReaderKit.podspec
index e1d6d958d..b9cb6624e 100644
--- a/FolioReaderKit.podspec
+++ b/FolioReaderKit.podspec
@@ -32,10 +32,11 @@ Pod::Spec.new do |s|
s.libraries = "z"
s.frameworks = 'CoreData'
s.dependency 'SSZipArchive', '1.5'
- s.dependency 'MenuItemKit', '1.1.3'
+ s.dependency 'MenuItemKit', '2.0'
s.dependency 'ZFDragableModalTransition', '~> 0.6'
- s.dependency 'AEXML', '3.0'
- s.dependency 'JSQWebViewController', '~> 3.0'
+ s.dependency 'AEXML', '4.0'
+ s.dependency 'FontBlaster', '3.0.0'
+ s.dependency 'JSQWebViewController', '~> 5.0'
s.dependency 'RealmSwift', '~> 1.0'
# s.dependency 'SMSegmentView'
end
diff --git a/Source/EPUBCore/FRBook.swift b/Source/EPUBCore/FRBook.swift
index d9a997d61..3f2b3b94d 100755
--- a/Source/EPUBCore/FRBook.swift
+++ b/Source/EPUBCore/FRBook.swift
@@ -9,7 +9,7 @@
import UIKit
-public class FRBook: NSObject {
+open class FRBook: NSObject {
var resources = FRResources()
var metadata = FRMetadata()
var spine = FRSpine()
@@ -38,19 +38,23 @@ public class FRBook: NSObject {
}
// @NOTE: should "#" be automatically prefixed with the ID?
- func durationFor(ID: String) -> String? {
+ func durationFor(_ ID: String) -> String? {
return metadata.findMetaByProperty("media:duration", refinedBy: ID)
}
- func activeClass() -> String! {
- let className = metadata.findMetaByProperty("media:active-class");
- return className ?? "epub-media-overlay-active";
+ func activeClass() -> String {
+ guard let className = metadata.findMetaByProperty("media:active-class") else {
+ return "epub-media-overlay-active"
+ }
+ return className
}
- func playbackActiveClass() -> String! {
- let className = metadata.findMetaByProperty("media:playback-active-class");
- return className ?? "epub-media-overlay-playing";
+ func playbackActiveClass() -> String {
+ guard let className = metadata.findMetaByProperty("media:playback-active-class") else {
+ return "epub-media-overlay-playing"
+ }
+ return className
}
@@ -59,7 +63,7 @@ public class FRBook: NSObject {
/**
Get Smil File from a resource (if it has a media-overlay)
*/
- func smilFileForResource(resource: FRResource!) -> FRSmilFile! {
+ func smilFileForResource(_ resource: FRResource!) -> FRSmilFile! {
if( resource == nil || resource.mediaOverlay == nil ){
return nil
}
@@ -71,11 +75,11 @@ public class FRBook: NSObject {
return smils.findByHref( smilResource!.href )
}
- func smilFileForHref(href: String) -> FRSmilFile! {
+ func smilFileForHref(_ href: String) -> FRSmilFile! {
return smilFileForResource(resources.findByHref(href))
}
- func smilFileForId(ID: String) -> FRSmilFile! {
+ func smilFileForId(_ ID: String) -> FRSmilFile! {
return smilFileForResource(resources.findById(ID))
}
diff --git a/Source/EPUBCore/FREpubParser.swift b/Source/EPUBCore/FREpubParser.swift
index 612e94d3e..32225aa39 100755
--- a/Source/EPUBCore/FREpubParser.swift
+++ b/Source/EPUBCore/FREpubParser.swift
@@ -19,13 +19,13 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
var bookBasePath: String!
var resourcesBasePath: String!
var shouldRemoveEpub = true
- private var epubPathToRemove: String?
+ fileprivate var epubPathToRemove: String?
/**
Parse the Cover Image from an epub file.
Returns an UIImage.
*/
- func parseCoverImage(epubPath: String) -> UIImage? {
+ func parseCoverImage(_ epubPath: String) -> UIImage? {
guard let book = readEpub(epubPath: epubPath, removeEpub: false), let coverImage = book.coverImage else {
return nil
}
@@ -41,29 +41,29 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
shouldRemoveEpub = removeEpub
var isDir: ObjCBool = false
- let fileManager = NSFileManager.defaultManager()
+ let fileManager = FileManager.default
let bookName = (withEpubPath as NSString).lastPathComponent
- bookBasePath = (kApplicationDocumentsDirectory as NSString).stringByAppendingPathComponent(bookName)
+ bookBasePath = (kApplicationDocumentsDirectory as NSString).appendingPathComponent(bookName)
- guard fileManager.fileExistsAtPath(withEpubPath) else {
+ guard fileManager.fileExists(atPath: withEpubPath) else {
print("Epub file does not exist.")
return nil
}
// Unzip if necessary
var needsUnzip = false
- if fileManager.fileExistsAtPath(bookBasePath, isDirectory:&isDir) {
- if !isDir { needsUnzip = true }
+ if fileManager.fileExists(atPath: bookBasePath, isDirectory:&isDir) {
+ if !isDir.boolValue { needsUnzip = true }
} else {
needsUnzip = true
}
if needsUnzip {
- SSZipArchive.unzipFileAtPath(withEpubPath, toDestination: bookBasePath, delegate: self)
+ SSZipArchive.unzipFile(atPath: withEpubPath, toDestination: bookBasePath, delegate: self)
}
// Skip from backup this folder
- addSkipBackupAttributeToItemAtURL(NSURL(fileURLWithPath: bookBasePath, isDirectory: true))
+ addSkipBackupAttributeToItemAtURL(URL(fileURLWithPath: bookBasePath, isDirectory: true))
kBookId = bookName
readContainer()
@@ -74,17 +74,17 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
/**
Read and parse container.xml file.
*/
- private func readContainer() {
+ fileprivate func readContainer() {
let containerPath = "META-INF/container.xml"
do {
- let containerData = try NSData(contentsOfFile: (bookBasePath as NSString).stringByAppendingPathComponent(containerPath), options: .DataReadingMappedAlways)
- let xmlDoc = try AEXMLDocument(xmlData: containerData)
+ let containerData = try Data(contentsOf: URL(fileURLWithPath: (bookBasePath as NSString).appendingPathComponent(containerPath)), options: .alwaysMapped)
+ let xmlDoc = try AEXMLDocument(xml: containerData)
let opfResource = FRResource()
opfResource.href = xmlDoc.root["rootfiles"]["rootfile"].attributes["full-path"]
opfResource.mediaType = FRMediaType.determineMediaType(xmlDoc.root["rootfiles"]["rootfile"].attributes["full-path"]!)
book.opfResource = opfResource
- resourcesBasePath = (bookBasePath as NSString).stringByAppendingPathComponent((book.opfResource.href as NSString).stringByDeletingLastPathComponent)
+ resourcesBasePath = (bookBasePath as NSString).appendingPathComponent((book.opfResource.href as NSString).deletingLastPathComponent)
} catch {
print("Cannot read container.xml")
}
@@ -93,13 +93,13 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
/**
Read and parse .opf file.
*/
- private func readOpf() {
- let opfPath = (bookBasePath as NSString).stringByAppendingPathComponent(book.opfResource.href)
+ fileprivate func readOpf() {
+ let opfPath = (bookBasePath as NSString).appendingPathComponent(book.opfResource.href)
var identifier: String?
do {
- let opfData = try NSData(contentsOfFile: opfPath, options: .DataReadingMappedAlways)
- let xmlDoc = try AEXMLDocument(xmlData: opfData)
+ let opfData = try Data(contentsOf: URL(fileURLWithPath: opfPath), options: .alwaysMapped)
+ let xmlDoc = try AEXMLDocument(xml: opfData)
// Base OPF info
if let package = xmlDoc.children.first {
@@ -116,7 +116,7 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
resource.id = item.attributes["id"]
resource.properties = item.attributes["properties"]
resource.href = item.attributes["href"]
- resource.fullHref = (resourcesBasePath as NSString).stringByAppendingPathComponent(item.attributes["href"]!).stringByRemovingPercentEncoding
+ resource.fullHref = (resourcesBasePath as NSString).appendingPathComponent(resource.href).removingPercentEncoding
resource.mediaType = FRMediaType.mediaTypeByName(item.attributes["media-type"]!, fileName: resource.href)
resource.mediaOverlay = item.attributes["media-overlay"]
@@ -179,16 +179,16 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
/**
Reads and parses a .smil file
*/
- private func readSmilFile(resource: FRResource) {
+ fileprivate func readSmilFile(_ resource: FRResource) {
do {
- let smilData = try NSData(contentsOfFile: resource.fullHref, options: .DataReadingMappedAlways)
+ let smilData = try Data(contentsOf: URL(fileURLWithPath: resource.fullHref), options: .alwaysMapped)
var smilFile = FRSmilFile(resource: resource)
- let xmlDoc = try AEXMLDocument(xmlData: smilData)
+ let xmlDoc = try AEXMLDocument(xml: smilData)
let children = xmlDoc.root["body"].children
if children.count > 0 {
- smilFile.data.appendContentsOf(readSmilFileElements(children))
+ smilFile.data.append(contentsOf: readSmilFileElements(children))
}
book.smils.add(smilFile)
@@ -197,7 +197,7 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
}
}
- private func readSmilFileElements(children:[AEXMLElement]) -> [FRSmilElement] {
+ fileprivate func readSmilFileElements(_ children:[AEXMLElement]) -> [FRSmilElement] {
var data = [FRSmilElement]()
// convert each smil element to a FRSmil object
@@ -207,7 +207,7 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
// if this element has children, convert them to objects too
if item.children.count > 0 {
- smil.children.appendContentsOf(readSmilFileElements(item.children))
+ smil.children.append(contentsOf: readSmilFileElements(item.children))
}
data.append(smil)
@@ -219,22 +219,22 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
/**
Read and parse the Table of Contents.
*/
- private func findTableOfContents() -> [FRTocReference] {
+ fileprivate func findTableOfContents() -> [FRTocReference] {
var tableOfContent = [FRTocReference]()
var tocItems: [AEXMLElement]?
guard let tocResource = book.tocResource else { return tableOfContent }
- let tocPath = (resourcesBasePath as NSString).stringByAppendingPathComponent(tocResource.href)
+ let tocPath = (resourcesBasePath as NSString).appendingPathComponent(tocResource.href)
do {
if tocResource.mediaType == FRMediaType.NCX {
- let ncxData = try NSData(contentsOfFile: tocPath, options: .DataReadingMappedAlways)
- let xmlDoc = try AEXMLDocument(xmlData: ncxData)
+ let ncxData = try Data(contentsOf: URL(fileURLWithPath: tocPath), options: .alwaysMapped)
+ let xmlDoc = try AEXMLDocument(xml: ncxData)
if let itemsList = xmlDoc.root["navMap"]["navPoint"].all {
tocItems = itemsList
}
} else {
- let tocData = try NSData(contentsOfFile: tocPath, options: .DataReadingMappedAlways)
- let xmlDoc = try AEXMLDocument(xmlData: tocData)
+ let tocData = try Data(contentsOf: URL(fileURLWithPath: tocPath), options: .alwaysMapped)
+ let xmlDoc = try AEXMLDocument(xml: tocData)
if let nav = xmlDoc.root["body"]["nav"].first, let itemsList = nav["ol"]["li"].all {
tocItems = itemsList
@@ -261,7 +261,7 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
- parameter element: A `AEXMLElement`, usually the `
`
- returns: If found the `