【问题标题】:Swift structs: no type named 'Business' in moduleSwift 结构:模块中没有名为“Business”的类型
【发布时间】: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 LibrariesCompile SourcesEmbed FrameworksEmbedded 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


    【解决方案1】:

    这是一个菜鸟错误,只需要在结构中添加public :)

    【讨论】:

    • 我也有类似的问题。我的协议是 swift 编写的,并且不会自动添加到我的 framework.h 头文件中,所以我将 .swift 文件添加到公共头文件中,但仍然找不到。 (我得到的错误是“模块“frameworkName”中没有名为“protocolname”的类型。)对此的任何帮助将不胜感激。我还向协议添加了公共......
    • @Jeremie,没有更多的上下文和难以分辨的代码。也许值得检查您是否有 import Foundation 并将其链接到您的框架目标。
    猜你喜欢
    • 2014-08-10
    • 2021-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-17
    • 2017-12-14
    相关资源
    最近更新 更多