Working with asset catalogs

I am experimenting using an asset catalog in my app, following instructions from @Thom_McGrath blog post:

My first experimentations show a huge speed improvement (6x) when loading 60 pictures at once:

  • Old method using Picture.Open(Folderitem) : 60ms

  • New method using the asset catalog: 5-10ms

Protected Function LoadPictureFromAssets(Name As String) As Picture
  Declare Function autorelease_ lib "Foundation" selector "autorelease" (o as ptr) as Ptr
  declare function NSClassFromString lib "Foundation" (classname as CFStringRef) as ptr
  Declare Function imageNamed_ lib "UIKit" selector "imageNamed:" (obj as ptr, nm as CFStringRef) as ptr
  Dim imgPtr as ptr = autorelease_(imageNamed_(NSClassFromString("UIImage"), name))
  if imgPtr <> nil then
    Return Picture.FromHandle(imgPtr)
  end if
End Function

I noticed that Xojo already creates an file when building the app.
So I need to rename the asset catalog to something else before using a copy file build step.

Problem is after renaming the file, the LoadPictureFromAssets always returns nil.

Any idea how I can load an image from a secondary asset catalog?

@Sam_Rowlands maybe?

Could this be of help?

It seems it’s possible what you want to do and change pointer to the bundle or catalog.

1 Like

Thanks Derk.

I tried following the instructions from that page but the bundle does not load.

The pictures are not loaded in the app and the console outputs the following, despite having a plist file with an identifier.

Could not load asset catalog from bundle NSBundle </Users/jleroy/Library/Developer/CoreSimulator/Devices/C527F195-7095-4A17-B1D0-40F670039E5A/data/Containers/Bundle/Application/A8663460-32A3-4DE6-A354-21B87E5A0039/> (not yet loaded): Error Domain=NSCocoaErrorDomain Code=260 “RunTimeThemeRefForBundleIdentifierAndName() couldn’t find in bundle with identifier: (null)” UserInfo={NSLocalizedDescription=RunTimeThemeRefForBundleIdentifierAndName() couldn’t find in bundle with identifier: (null)}

If someone wants to test here is the Xojo project:

1 Like

Maybe MBS has some plugins you can re-write to native… ?

I don’t think the problem is the code I am using but the bundle itself which isn’t recognized as a bundle by the operating system.
MBS plug-ins wouldn’t solve this unless they have a clear example on how to create a working bundle for iOS.

Is it signed?

Here is says something interesting in the first answer:

While it’s an old question it may be of relevance.
Othewise is there a normal known way to read external bundles you know of ?