OBJC_ATTRIBUTES_FIX_SUMMARY.md
3.78 KB
@objc Attributes Fix for SPM Class Resolution
Problem
XIB files in SPM couldn't find Swift classes due to name mangling differences between CocoaPods and SPM, causing:
Unknown class _TtC41SwiftWarplyFramework_SwiftWarplyFramework40MyRewardsBannerOffersScrollTableViewCell in Interface Builder file.
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UITableViewCell 0x105f2d060> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key collectionView.'
Solution
Added explicit @objc(ClassName)
attributes to all cell classes to provide stable, predictable class names for XIB file instantiation.
Classes Updated
Table View Cells:
-
MyRewardsBannerOffersScrollTableViewCell -
@objc(MyRewardsBannerOffersScrollTableViewCell)
-
MyRewardsOffersScrollTableViewCell -
@objc(MyRewardsOffersScrollTableViewCell)
-
ProfileCouponFiltersTableViewCell -
@objc(ProfileCouponFiltersTableViewCell)
-
ProfileHeaderTableViewCell -
@objc(ProfileHeaderTableViewCell)
-
ProfileQuestionnaireTableViewCell -
@objc(ProfileQuestionnaireTableViewCell)
-
ProfileCouponTableViewCell -
@objc(ProfileCouponTableViewCell)
Collection View Cells:
-
MyRewardsOfferCollectionViewCell -
@objc(MyRewardsOfferCollectionViewCell)
-
MyRewardsBannerOfferCollectionViewCell -
@objc(MyRewardsBannerOfferCollectionViewCell)
-
ProfileFilterCollectionViewCell -
@objc(ProfileFilterCollectionViewCell)
What This Fix Does
Before:
- Swift name mangling in SPM:
_TtC41SwiftWarplyFramework_SwiftWarplyFramework40MyRewardsBannerOffersScrollTableViewCell
- XIB files couldn't find the class
- Fell back to generic
UITableViewCell
- Crashed when trying to connect
collectionView
outlet
After:
- Explicit Objective-C name:
MyRewardsBannerOffersScrollTableViewCell
- XIB files can reliably find the class
- Proper class instantiation
- All outlets connect correctly
Benefits
- Stable Class Names - XIB files always find the correct class regardless of Swift name mangling
- SPM Compatibility - Works consistently in SPM environments
- CocoaPods Compatibility - Maintains backward compatibility
- No Swift Regression - All Swift features and improvements remain intact
- Industry Standard - Common practice for Swift frameworks using XIB files
Testing
After this fix, you should see:
- No more "Unknown class" errors
- Successful XIB instantiation
- Proper outlet connections
- No crashes related to key-value coding compliance
Files Modified
SwiftWarplyFramework/SwiftWarplyFramework/cells/MyRewardsBannerOffersScrollTableViewCell/MyRewardsBannerOffersScrollTableViewCell.swift
SwiftWarplyFramework/SwiftWarplyFramework/cells/MyRewardsOffersScrollTableViewCell/MyRewardsOffersScrollTableViewCell.swift
SwiftWarplyFramework/SwiftWarplyFramework/cells/ProfileCouponFiltersTableViewCell/ProfileCouponFiltersTableViewCell.swift
SwiftWarplyFramework/SwiftWarplyFramework/cells/ProfileHeaderTableViewCell/ProfileHeaderTableViewCell.swift
SwiftWarplyFramework/SwiftWarplyFramework/cells/ProfileQuestionnaireTableViewCell/ProfileQuestionnaireTableViewCell.swift
SwiftWarplyFramework/SwiftWarplyFramework/cells/ProfileCouponTableViewCell/ProfileCouponTableViewCell.swift
SwiftWarplyFramework/SwiftWarplyFramework/cells/MyRewardsOfferCollectionViewCell/MyRewardsOfferCollectionViewCell.swift
SwiftWarplyFramework/SwiftWarplyFramework/cells/MyRewardsBannerOfferCollectionViewCell/MyRewardsBannerOfferCollectionViewCell.swift
SwiftWarplyFramework/SwiftWarplyFramework/cells/ProfileFilterCollectionViewCell/ProfileFilterCollectionViewCell.swift
This fix should resolve the XIB class resolution issue and eliminate the NSUnknownKeyException
crashes in SPM environments.