1

I'm building a project using Swift 3 and Xcode 8.1. First I created an API client using Siesta on a framework and I'm including it on my mail project, but when I try to use an struct from the framework to do a downcast I get an error No type named 'Business' in module 'ApiClient', I've tried using it like ApiClient.Business but no success...

My framework is in a workspace together with another dependencies injected by carthage, and I can call another instances from it (like the API itself) but I need to access this to be able to downcast the results. I've also tried adding the framework under Link Binary With Libraries, Compile Sources, Embed Frameworks, Embedded Binaries and Linked Frameworks and Libraries, but can't make it work...

Here's my code

//
//  BusinessesViewController.swift
//

import UIKit
import ApiClient
import Siesta

class BusinessesViewController: UIViewController, ResourceObserver{

    override func viewDidLoad() {
        super.viewDidLoad()
        globalInstance.MyAPI.businesses.addObserver(self).loadIfNeeded()
    }

    func resourceChanged(_ resource: Resource, event: ResourceEvent) {

        let businesses: Array = resource.typedContent(ifNone: [])
        if(businesses.count > 0){
            let object : ApiClient.Business =  businesses[0] as! ApiClient.Business // <-- error here
        }
    }

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

}



//
//  global.swift
//

import Foundation
import ApiClient

class Global {
    var MyAPI :ApiClientService 

    init() {
        MyAPI = ApiClientService(baseURL: "http://test.myproject.com")
    }

}
var globalInstance = Global()



//
//  Business.swift  -- from ApiClient framework
//

import SwiftyJSON
import Foundation
struct Business {
    let name, id: String?
    let userId: Int?
    let description: String?

    init(json: JSON) throws {
        id          = json["id"].string
        userId     =  json["user_id"].int
        name        = json["name"].string
        description = json["description"].string
    }
}
SkarXa
  • 1,184
  • 1
  • 12
  • 24

1 Answers1

5

It was a noob error, just needed to add public to the struct :)

SkarXa
  • 1,184
  • 1
  • 12
  • 24
  • Im having a similar problem. My protocol is written is swift and isnt added automatically to my framework.h header file, so i added the .swift file to public headers, but it still isnt being found. (the error I get is "No type named "protocolname" in module "frameworkName".) Any help with this would be greatly appreciated. I've also added public to the protocol... – Jeremie D Sep 01 '17 at 14:07
  • @Jeremie, without having more context and code hard to tell. Maybe worth checking if you have `import Foundation` and also link it to your framework target. – Mazen Kasser Sep 28 '17 at 02:54