【发布时间】:2016-12-20 17:04:47
【问题描述】:
我正在使用 Swift 3 和 Xcode 8.1 构建一个项目。首先,我在框架上使用 Siesta 创建了一个 API 客户端,并将其包含在我的邮件项目中,但是当我尝试使用框架中的结构进行向下转换时,我收到错误 No type named 'Business' in module 'ApiClient',我尝试使用它喜欢ApiClient.Business,但没有成功......
我的框架与 carthage 注入的另一个依赖项一起位于工作区中,我可以从中调用另一个实例(如 API 本身),但我需要访问它才能向下转换结果。我还尝试在 Link Binary With Libraries、Compile Sources、Embed Frameworks、Embedded Binaries 下添加框架和Linked Frameworks and Libraries,但无法正常工作...
这是我的代码
//
// 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
}
}
【问题讨论】:
标签: xcode struct swift3 ios-frameworks siesta-swift