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)
Else
Break
end if
End Function
I noticed that Xojo already creates an Assets.car 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?
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/Untitled.debug.app/ActivityIcons.bundle> (not yet loaded): Error Domain=NSCocoaErrorDomain Code=260 “RunTimeThemeRefForBundleIdentifierAndName() couldn’t find Assets.car in bundle with identifier: (null)” UserInfo={NSLocalizedDescription=RunTimeThemeRefForBundleIdentifierAndName() couldn’t find Assets.car in bundle with identifier: (null)}
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.