Something like this:
class NS<T> : NSObject
{
public NS(T value)
{
Value = value;
}
public T Value { get; }
}
For more convenient using:
UICollectionViewDiffableDataSource:new UICollectionViewDiffableDataSource<NS<MySectionEnum>, NS<int>>(...);
NSDiffableDataSourceSnapshot<,>var dataSource = new UICollectionViewDiffableDataSource<NS<MySectionEnum>, NS<int>>(...);
var snapshot = new NSDiffableDataSourceSnapshot<NS<MySectionEnum>, NS<int>>();
snapshot.AppendSections(new[] { new NS<MySectionEnum>(section); });
var items = Enumerable.Range(0, 100).Select(x => new NS<int>(x)).ToArray();
snapshot.AppendItems(items);
dataSource.ApplySnapshot(snapshot, animatingDifferences: false);
Possible problem of this approach: https://github.com/xamarin/xamarin-macios/issues/6289
In the above case you better use the existing NSNumber type and avoid creating a custom type (in addition to the generic extra cost).
@wcoder - Thanks for the bug report.
As noted by @Therzok, we'd rather not push people to using generic NSObject due to the non-trivial performance penalty. In some cases you can use existing NS types, such as NSNumber, and in others you'll need a hand rolled type.
If we bake in such a wrapper, I fear we'll push people to using it in cases they shouldn't.
Due to that, we're going to reject this proposal. Thanks for the idea though!
Most helpful comment
In the above case you better use the existing
NSNumbertype and avoid creating a custom type (in addition to the generic extra cost).