X-Git-Url: https://git.mdrn.pl/wl-app.git/blobdiff_plain/53b27422d140022594fc241cca91c3183be57bca..48b2fe9f7c2dc3d9aeaaa6dbfb27c7da4f3235ff:/iOS/WolneLektury/Extensions/NSObject%20Ext.swift/wl-app.git/blobdiff_plain/53b27422d140022594fc241cca91c3183be57bca..48b2fe9f7c2dc3d9aeaaa6dbfb27c7da4f3235ff:/iOS/WolneLektury/Extensions/NSObject+Ext.swift diff --git a/iOS/WolneLektury/Extensions/NSObject+Ext.swift b/iOS/WolneLektury/Extensions/NSObject+Ext.swift new file mode 100644 index 0000000..8e1be95 --- /dev/null +++ b/iOS/WolneLektury/Extensions/NSObject+Ext.swift @@ -0,0 +1,39 @@ +// +// NSObject+Ext.swift +// WolneLektury +// +// Created by Pawel Dabrowski on 30/05/2018. +// Copyright © 2018 Fundacja Nowoczesna Polska. All rights reserved. +// + +import Foundation +import UIKit + +extension NSObject +{ + var appDelegate:AppDelegate { + return UIApplication.shared.delegate as! AppDelegate + } + + func ebookExists(bookSlug: String) -> Bool { + let path = FileType.ebook.pathForFileName(filename: bookSlug, bookSlug: bookSlug) + print(path) + return FileManager.default.fileExists(atPath: path) + } + + static func audiobookExists(audioBookUrlString: String, bookSlug: String) -> Bool { + let fileName = (audioBookUrlString as NSString).lastPathComponent + return FileManager.default.fileExists(atPath: FileType.audiobook.pathForFileName(filename: fileName, bookSlug: bookSlug)) + } + + static func audiobookPathIfExists(audioBookUrlString: String, bookSlug: String) -> URL? { + let fileName = (audioBookUrlString as NSString).lastPathComponent + let path = FileType.audiobook.pathForFileName(filename: fileName, bookSlug: bookSlug) + + if FileManager.default.fileExists(atPath: path) { + return URL(fileURLWithPath: path) + } + return nil + } + +}