Milton Palaguachi
Milton Palaguachi

Reputation: 31

How to access a json file that is inside an internal framework in Swift

Code to find my framework location

//  Bundle+Ext.swift
//  AVStream
private final class AVStream { }

extension Bundle {
    static var avstream: Bundle {
        moduleBundle(for: AVStream.self)
    }
    public static func moduleBundle(for object: AnyObject) -> Bundle! {
        Bundle.moduleBundle(forObject: object)
    }

    public static func moduleBundle(forObject: AnyObject) -> Bundle {
        Bundle(for: type(of: forObject))
    }
}

A tried to get the url, but it is nil

guard let url = Bundle.avstream.url(forResource:"RemoteVideos", withExtension: "json") else {
    return
}

my framework

Upvotes: 1

Views: 703

Answers (1)

Milton Palaguachi
Milton Palaguachi

Reputation: 31

After adding the file to the framework on the Target Membership. I was able to get the file's path/urlenter image description here

Upvotes: 1

Related Questions