iOS Guides | Samples

MonoTouch.UIKit.NSDataAsset Class

Platform-specific data object stored in an asset catalog.

See Also: NSDataAsset


[MonoTouch.Foundation.Register("NSDataAsset", true)]
[MonoTouch.ObjCRuntime.Introduced(MonoTouch.ObjCRuntime.PlatformName.iOS, 9, 0, MonoTouch.ObjCRuntime.PlatformArchitecture.None, null)]
[MonoTouch.ObjCRuntime.Unavailable(MonoTouch.ObjCRuntime.PlatformName.WatchOS, MonoTouch.ObjCRuntime.PlatformArchitecture.All, null)]
public class NSDataAsset : NSObject, INSCopying, IDisposable


Asset catalogs are often used for icons and images, but may be used to deliver any kind of data in a platform-specific manner.

Within an asset catalog, there is one folder per data object. That folder contains platform-specific data files and a Contents.json file that maps platform characteristics to specific datafiles. For example:

Where Contents.json contains:

json Example

  "info" : {
    "version" : 1,
    "author" : "xcode"
  "data" : [
      "idiom" : "iphone",
      "filename" : "iphone.wav",
      "universal-type-identifier" : ""
      "idiom" : "ipad",
      "filename" : "ipad.wav",
      "universal-type-identifier" : ""

To load an asset, call NSDataAsset.NSDataAsset(String) or NSDataAsset.NSDataAsset(String,NSBundle) passing the name of the folder. For instance:

C# Example

var assetCatalog = new NSDataAsset ("FolderName");
var data = assetCatalog.Data;
var uti = assetCatalog.TypeIdentifier;

NSError error = null;
var player = new AVAudioPlayer (data, uti, out error);
if (player != null) { //...etc

The appropriate datafile for the hardware device will be loaded.

Related content


Namespace: MonoTouch.UIKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions:

The members of MonoTouch.UIKit.NSDataAsset are listed below.

See Also: NSObject

Public Constructors

A constructor that initializes the object from the data stored in the unarchiver object.
Constructor to call on derived classes to skip initialization and merely allocate the object.
A constructor used when creating managed representations of unmanaged objects; Called by the runtime.
Returns the data specified in the name folder's "Contents.json" file.
Returns the data specified in the name folder's "Contents.json" file.

Public Properties

ClassHandleIntPtr. The handle for this class.
DataNSData. The raw data of the asset.
NameString. The identifier of the asset dataset folder within the asset catalog.
TypeIdentifierNSString. The UTI of the NSDataAsset.Data.

Public Methods

Copy(NSZone) : NSObject
Performs a copy of the underlying Objective-C object.