1

Swift 3 と Xcode 8.1 を使用してプロジェクトを構築しています。まず、フレームワークで Siesta を使用して API クライアントを作成し、それをメール プロジェクトに含めていますが、フレームワークの構造体を使用してダウンキャストを実行しようとすると、エラーが発生し、次のNo type named 'Business' in module 'ApiClient'ように使用しようとしましたApiClient.Businessが、失敗...

私のフレームワークは、carthage によって注入された別の依存関係と一緒にワークスペースにあり、そこから (API 自体のように) 別のインスタンスを呼び出すことができますが、結果をダウンキャストできるようにするには、これにアクセスする必要があります。また、 Link Binary With LibrariesCompile SourcesEmbed FrameworksEmbedded BinariesLinked 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
    }
}
4

1 に答える 1

5

構造体に追加する必要があるだけのnoobエラーでしたpublic:)

于 2016-12-20T17:26:24.277 に答える