Showing
4 changed files
with
144 additions
and
0 deletions
NIB_LOADING_FIX_SUMMARY.md
0 → 100644
1 | +# NIB Loading Fix Summary | ||
2 | + | ||
3 | +## Problem Identified | ||
4 | +Your demo client was crashing with the error: | ||
5 | +``` | ||
6 | +Could not load NIB in bundle: 'NSBundle .../SwiftWarplyFramework.framework' with name 'MyRewardsViewController' | ||
7 | +``` | ||
8 | + | ||
9 | +## Root Cause | ||
10 | +The issue was that view controllers in the SwiftWarplyFramework were not properly specifying the NIB name and bundle when being instantiated. When your demo client tried to create these view controllers, iOS couldn't find the XIB files because it was looking in the wrong bundle. | ||
11 | + | ||
12 | +## Solution Applied | ||
13 | +Added proper initializers to all XIB-based view controllers in the framework: | ||
14 | + | ||
15 | +### Fixed View Controllers: | ||
16 | +1. **MyRewardsViewController** ✅ | ||
17 | +2. **ProfileViewController** ✅ | ||
18 | +3. **CouponViewController** ✅ | ||
19 | + | ||
20 | +### What Was Added: | ||
21 | +Each view controller now has these initializers: | ||
22 | + | ||
23 | +```swift | ||
24 | +// MARK: - Initializers | ||
25 | +public convenience init() { | ||
26 | + self.init(nibName: "ViewControllerName", bundle: Bundle(for: MyEmptyClass.self)) | ||
27 | +} | ||
28 | + | ||
29 | +public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { | ||
30 | + super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) | ||
31 | +} | ||
32 | + | ||
33 | +required init?(coder: NSCoder) { | ||
34 | + super.init(coder: coder) | ||
35 | +} | ||
36 | +``` | ||
37 | + | ||
38 | +## How to Use in Your Demo Client | ||
39 | + | ||
40 | +### ✅ Correct Usage (Now Works): | ||
41 | +```swift | ||
42 | +// Simple instantiation - uses convenience initializer | ||
43 | +let vc = MyRewardsViewController() | ||
44 | +navigationController?.pushViewController(vc, animated: true) | ||
45 | + | ||
46 | +// Or explicit instantiation | ||
47 | +let vc = MyRewardsViewController(nibName: "MyRewardsViewController", bundle: Bundle(for: MyEmptyClass.self)) | ||
48 | +navigationController?.pushViewController(vc, animated: true) | ||
49 | +``` | ||
50 | + | ||
51 | +### ❌ Previous Issue: | ||
52 | +Before the fix, when you tried to instantiate view controllers without specifying the bundle, iOS couldn't locate the XIB files in the framework bundle. | ||
53 | + | ||
54 | +## View Controllers That Don't Need This Fix: | ||
55 | +- **CampaignViewController** - Uses storyboard instantiation, not XIB files | ||
56 | + | ||
57 | +## Framework Structure: | ||
58 | +``` | ||
59 | +SwiftWarplyFramework/ | ||
60 | +├── SwiftWarplyFramework/ | ||
61 | +│ ├── screens/ | ||
62 | +│ │ ├── MyRewardsViewController/ | ||
63 | +│ │ │ ├── MyRewardsViewController.swift ✅ Fixed | ||
64 | +│ │ │ └── MyRewardsViewController.xib | ||
65 | +│ │ ├── ProfileViewController/ | ||
66 | +│ │ │ ├── ProfileViewController.swift ✅ Fixed | ||
67 | +│ │ │ └── ProfileViewController.xib | ||
68 | +│ │ ├── CouponViewController/ | ||
69 | +│ │ │ ├── CouponViewController.swift ✅ Fixed | ||
70 | +│ │ │ └── CouponViewController.xib | ||
71 | +│ │ └── CampaignViewController.swift (Storyboard-based) | ||
72 | +│ └── Main.storyboard | ||
73 | +``` | ||
74 | + | ||
75 | +## Testing Your Demo Client | ||
76 | +After updating your framework dependency, your demo client should now be able to: | ||
77 | + | ||
78 | +1. ✅ Build successfully (previous podspec fix) | ||
79 | +2. ✅ Run without crashing (this NIB loading fix) | ||
80 | +3. ✅ Instantiate and display all view controllers properly | ||
81 | + | ||
82 | +## Example Demo Client Code: | ||
83 | +```swift | ||
84 | +import SwiftWarplyFramework | ||
85 | + | ||
86 | +class ViewController: UIViewController { | ||
87 | + | ||
88 | + @IBAction func showMyRewards(_ sender: Any) { | ||
89 | + let vc = MyRewardsViewController() | ||
90 | + navigationController?.pushViewController(vc, animated: true) | ||
91 | + } | ||
92 | + | ||
93 | + @IBAction func showProfile(_ sender: Any) { | ||
94 | + let vc = ProfileViewController() | ||
95 | + navigationController?.pushViewController(vc, animated: true) | ||
96 | + } | ||
97 | +} | ||
98 | +``` | ||
99 | + | ||
100 | +## Next Steps: | ||
101 | +1. Update your framework dependency to get these fixes | ||
102 | +2. Test your demo client to ensure it works properly | ||
103 | +3. All view controllers should now load and display correctly | ||
104 | + | ||
105 | +The framework is now properly configured for CocoaPods distribution with correct bundle references for all XIB-based view controllers. |
... | @@ -10,6 +10,19 @@ import UIKit | ... | @@ -10,6 +10,19 @@ import UIKit |
10 | @objc public class CouponViewController: UIViewController { | 10 | @objc public class CouponViewController: UIViewController { |
11 | @IBOutlet weak var couponImage: UIImageView! | 11 | @IBOutlet weak var couponImage: UIImageView! |
12 | 12 | ||
13 | + // MARK: - Initializers | ||
14 | + public convenience init() { | ||
15 | + self.init(nibName: "CouponViewController", bundle: Bundle(for: MyEmptyClass.self)) | ||
16 | + } | ||
17 | + | ||
18 | + public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { | ||
19 | + super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) | ||
20 | + } | ||
21 | + | ||
22 | + required init?(coder: NSCoder) { | ||
23 | + super.init(coder: coder) | ||
24 | + } | ||
25 | + | ||
13 | @IBOutlet weak var infoView: UIView! | 26 | @IBOutlet weak var infoView: UIView! |
14 | @IBOutlet weak var infoImage: UIImageView! | 27 | @IBOutlet weak var infoImage: UIImageView! |
15 | @IBOutlet weak var infoLabel: UILabel! | 28 | @IBOutlet weak var infoLabel: UILabel! | ... | ... |
... | @@ -11,6 +11,19 @@ import UIKit | ... | @@ -11,6 +11,19 @@ import UIKit |
11 | @objc public class MyRewardsViewController: UIViewController { | 11 | @objc public class MyRewardsViewController: UIViewController { |
12 | @IBOutlet weak var tableView: UITableView! | 12 | @IBOutlet weak var tableView: UITableView! |
13 | 13 | ||
14 | + // MARK: - Initializers | ||
15 | + public convenience init() { | ||
16 | + self.init(nibName: "MyRewardsViewController", bundle: Bundle(for: MyEmptyClass.self)) | ||
17 | + } | ||
18 | + | ||
19 | + public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { | ||
20 | + super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) | ||
21 | + } | ||
22 | + | ||
23 | + required init?(coder: NSCoder) { | ||
24 | + super.init(coder: coder) | ||
25 | + } | ||
26 | + | ||
14 | // MARK: - Dummy Data | 27 | // MARK: - Dummy Data |
15 | // match - survey - tesla - energy saver | 28 | // match - survey - tesla - energy saver |
16 | let allOffers: [OfferModel] = [ | 29 | let allOffers: [OfferModel] = [ | ... | ... |
... | @@ -9,6 +9,19 @@ import UIKit | ... | @@ -9,6 +9,19 @@ import UIKit |
9 | 9 | ||
10 | @objc public class ProfileViewController: UIViewController { | 10 | @objc public class ProfileViewController: UIViewController { |
11 | @IBOutlet weak var tableView: UITableView! | 11 | @IBOutlet weak var tableView: UITableView! |
12 | + | ||
13 | + // MARK: - Initializers | ||
14 | + public convenience init() { | ||
15 | + self.init(nibName: "ProfileViewController", bundle: Bundle(for: MyEmptyClass.self)) | ||
16 | + } | ||
17 | + | ||
18 | + public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { | ||
19 | + super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) | ||
20 | + } | ||
21 | + | ||
22 | + required init?(coder: NSCoder) { | ||
23 | + super.init(coder: coder) | ||
24 | + } | ||
12 | 25 | ||
13 | // MARK: - Dummy Data | 26 | // MARK: - Dummy Data |
14 | let allOffers: [OfferModel] = [ | 27 | let allOffers: [OfferModel] = [ | ... | ... |
-
Please register or login to post a comment