Inaccesible to access due to internal protection error swift class function in cocoa pod

Viewed 221

I'm building a cocoa pod as a wrapper for a RESTAPI i have created a Swift file inside Class folder of the cocoa pod project.Inside the swift file i have added a Singleton pattern class and Protocol which conform to codable protocol. But when i try to access the singleton class function in Example application viewcontroller.swift file i get an error stating getCapsules is inaccessible due to internal protection.Even have made everything as public still I get this error.

enter image description here

Class folder file

import Foundation


 class NetworkService
{
   
    
    public  let capsuleurl = URL(string: "https://api.spacexdata.com/v4/capsules")
      public let session = URLSession(configuration: .default)
    
   
    
 public func getCapsules(onCompletion :@escaping(Capsules) -> Void)
    {
     let task = session.dataTask(with: capsuleurl!) { (data, response, error) in
            
            DispatchQueue.main.async {
                do
                {
                    let capsules = try JSONDecoder().decode(Capsules.self, from: data!)
                    
                    onCompletion(capsules)
                    
                    
                    
                }
                
                catch
                {
                    print(error.localizedDescription)
                }
            }
        
            
        }
        
        task.resume()
    }
    
    
    
}




public struct Capsule: Codable {
 public   let reuseCount, waterLandings, landLandings: Int
public     let lastUpdate: String?
public     let launches: [String]
  public  let serial: String
public     let status: Status
 public   let id: String

  public   enum CodingKeys: String, CodingKey {
        case reuseCount = "reuse_count"
        case waterLandings = "water_landings"
        case landLandings = "land_landings"
        case lastUpdate = "last_update"
        case launches, serial, status, id
    }
}

public enum Status: String, Codable {
    case active = "active"
    case destroyed = "destroyed"
    case retired = "retired"
    case unknown = "unknown"
}

public typealias Capsules = [Capsule]

View controller.swift file in Example application

import UIKit
import KSBSpacexKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
       
        
        NetworkService.sharedobj. //I get error here sometimes NetworkService also not show in autocomplete

        
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

project structure

2 Answers

Make your variable and functions public to get access ... by default they are internal

public class NetworkService
    {
        public static var sharedobj = NetworkService()
        
       public  let capsuleurl = URL(string: "https://api.spacexdata.com/v4/capsules")
         public let session = URLSession(configuration: .default)
        
       
        
   public  func getCapsules(onCompletion :@escaping(Capsules) -> Void)
        {
           let task = session.dataTask(with: capsuleurl!) { (data, response, error) in
                
                DispatchQueue.main.async {
                    do
                    {
                        let capsules = try JSONDecoder().decode(Capsules.self, from: data!)
                        
                        onCompletion(capsules)
                    }
                    
                    catch
                    {
                        print(error.localizedDescription)
                    }
                }
            
                
            }
            
            task.resume()
        }
        
        
        
    }
    
    
    
    
    struct Capsule: Codable {
        let reuseCount, waterLandings, landLandings: Int
        let lastUpdate: String?
        let launches: [String]
        let serial: String
        let status: Status
        let id: String
    
        enum CodingKeys: String, CodingKey {
            case reuseCount = "reuse_count"
            case waterLandings = "water_landings"
            case landLandings = "land_landings"
            case lastUpdate = "last_update"
            case launches, serial, status, id
        }
    }
    
    enum Status: String, Codable {
        case active = "active"
        case destroyed = "destroyed"
        case retired = "retired"
        case unknown = "unknown"
    }
    
    typealias Capsules = [Capsule]

I found out that after making all properties of struct and functions of class as public Xcode 12 beta still shows error but when build it works fine. It is a bug in Xcode 12 beta

Related