From fbb4cfc6f959a3fec6be14311baba844a15fb7b5 Mon Sep 17 00:00:00 2001 From: PAOLO MUSOLINO Date: Wed, 11 May 2016 00:51:50 +0200 Subject: [PATCH] Now the library permit to load the PMAlertController bundle when used via Cocoapods --- Library/PMAlertController.swift | 30 +++++++++++++++++++++++++++--- PMAlertController.podspec | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Library/PMAlertController.swift b/Library/PMAlertController.swift index bde53d7..ccd04d5 100644 --- a/Library/PMAlertController.swift +++ b/Library/PMAlertController.swift @@ -32,8 +32,10 @@ public class PMAlertController: UIViewController { public convenience init(title: String, description: String, image: UIImage?, style: PMAlertControllerStyle) { self.init() - let nib = NSBundle.mainBundle().loadNibNamed("PMAlertController", owner: self, options: nil) - self.view = nib[0] as! UIView + let nib = loadNibAlertController() + if nib != nil{ + self.view = nib![0] as! UIView + } self.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext self.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve @@ -46,7 +48,7 @@ public class PMAlertController: UIViewController { //if alert width = 270, else width = screen width - 36 style == .Alert ? (alertViewWidthConstraint.constant = 270) : (alertViewWidthConstraint.constant = UIScreen.mainScreen().bounds.width - 36) - + setShadowAlertView() } @@ -77,4 +79,26 @@ public class PMAlertController: UIViewController { alertView.layer.shadowRadius = 8 alertView.layer.shadowOpacity = 0.3 } + + private func loadNibAlertController() -> [AnyObject]?{ + let podBundle = NSBundle(forClass: self.classForCoder) + + if let bundleURL = podBundle.URLForResource("PMAlertController", withExtension: "bundle") { + + if let bundle = NSBundle(URL: bundleURL) { + return bundle.loadNibNamed("PMAlertController", owner: self, options: nil) + } + else { + assertionFailure("Could not load the bundle") + } + + } + else if let nib = NSBundle.mainBundle().loadNibNamed("PMAlertController", owner: self, options: nil) { + return nib + } + else{ + assertionFailure("Could not create a path to the bundle") + } + return nil + } } diff --git a/PMAlertController.podspec b/PMAlertController.podspec index 011dc9b..0e4d7c6 100644 --- a/PMAlertController.podspec +++ b/PMAlertController.podspec @@ -14,7 +14,7 @@ Pod::Spec.new do |s| s.source = { :git => "https://github.com/Codeido/PMAlertController.git", :tag => "1.0.0" } s.source_files = "Library/**/*" s.resource_bundles = { - 'PMAlertController' => ['Library/Resources/*.png'] + 'PMAlertController' => ['Library/Resources/*.png', 'Library/**/*.xib'] } s.framework = "UIKit" s.requires_arc = true