'Call a structure from a single file in every other class

I made a single file for a structure that I need to call in other classes but I am trying everything to make it work but it seems I am not going to make this alone and figure it out.

Code for single file:

import Foundation

struct CustomLanguage {

func createBundlePath () -> Bundle {
    let selectedLanguage = "en" 
    let path = Bundle.main.path(forResource: selectedLanguage, ofType: "lproj")
    return Bundle(path: path!)!
    }
}

other class:

import Foundation
import UIKit

class signInViewController: UIViewController {

@IBOutlet weak var welcomeLabelSignIn: UILabel!

override func viewDidLoad() {
    welcomeLabelSignIn.text = NSLocalizedString("Welcome!", tableName: nil, bundle: "the structure call here" , value: "", comment: "")
}

so at the bundle: I Need to call that structure

the single file for the structure

I can't call it to localize the labels, buttons... in other classes



Solution 1:[1]

Try this;

 struct CustomLanguage {

      static func createBundlePath () -> Bundle {
        let selectedLanguage = "en" 
        let path = Bundle.main.path(forResource: selectedLanguage,  ofType: "lproj")
       return Bundle(path: path!)!
     }
}

Then;

     welcomeLabelSignIn.text = NSLocalizedString("Welcome!", tableName: nil, bundle: CustomLanguage.createBundlePath() , value: "", comment: "")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 john elemans