0
votes

I am trying to get data from swift and need to pass in react native and able to print array but not able to pass data to react native

import Foundation
import MusicKit

@objc(MusicKitView)
class MusicKitView:RCTEventEmitter{
    
private let request:MusicCatalogSearchRequest = {
        var request = MusicCatalogSearchRequest(term: "bhola", types: [Song.self])
        request.limit = 25
        return request
    }()
    
  @objc
   func fetchMusic(_ callback:@escaping RCTResponseSenderBlock) -> Void {
          Task{
              let status = await MusicAuthorization.request()
              switch status {
              case .authorized:
                do  {
                  let result = try await request.response()
                  callback([[NSNull() ,result]]) // i am having 
                  print("result",result.songs)
                  return;
                  }
                  catch{
                      print(String(describing: error))
              
                    return;
                  }
              default:
                  break

              }
          }

      }
  
 
  
  @objc
 override static func requiresMainQueueSetup() -> Bool{
    return true;
  }
  
  @objc
  override func constantsToExport() -> [AnyHashable:Any]!{
  return ["initialCount": "Swapnil"];
  }
  
  override func supportedEvents() -> [String]! {
    return ["musicData"]
  }
    
    
}

so in fetchMusic function if i use callback([[NSNull() ,result.songs[0].title]]) then it will pass but not array