Ska*_*rXa 1 xcode struct ios-frameworks siesta-swift swift3
我正在使用Swift 3和Xcode 8.1构建项目。首先,我在框架上使用Siesta创建了一个API客户端,并将其包含在我的邮件项目中,但是当我尝试使用框架中的结构进行向下转换时,出现错误No type named 'Business' in module 'ApiClient'
,我尝试使用它,ApiClient.Business
但是没有成功...
我的框架和另一个由carthage注入的依赖项一起在工作区中,我可以从中调用另一个实例(例如API本身),但是我需要访问它才能下调结果。我也尝试过在“ 与库链接二进制文件”,“ 编译源”,“ 嵌入框架”,“ 嵌入式二进制文件”和“ 链接框架和库”下添加框架,但是无法使其正常工作...
这是我的代码
//
// 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
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
943 次 |
最近记录: |