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
}
}
It was a noob error, just needed to add
public
to the struct :)