无法调用非函数类型'String'的值 [英] Cannot call value of non-function type 'String'

查看:323
本文介绍了无法调用非函数类型'String'的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户通过深度链接启动我的应用程序时,我试图将ILTItem变量传递给由AppDelegate.swift触发的ILTViewController.

I'm trying to pass the ILTItem variable into my ILTViewController, triggered by AppDelegate.swift when the user launches my app via a deeplink.

我的代码有错误:

无法调用非函数类型'String'的值

Cannot call value of non-function type 'String'

在我定义ilt的那一行上.

这是我目前的代码:

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
var ilt = ILT(homeworkID: 1234, title: "History ILT", subject: "History", teacher: "Miss A Smith", teacherCode: "asmith", studentID: 12345, description: "Description....", due: 1450137600, status: "In Progress", hasAttachments: true)
var newVC = ILTViewController()
newVC.ILTitem = ilt
appDelegate.window?.addSubview(newVC.view)

为什么会这样?在我的ILTViewController类中,我有:

Why could this be? In my ILTViewController class I have:

class ILTViewController: UIViewController {
  // accept the incoming ILT struct
  var ILTitem: ILT!

ITL结构声明:

struct ILT {
    let homeworkID: Int
    let title: String
    let subject: String
    let teacher: String
    let teacherCode: String
    let studentID: Int
    let description: String
    let due: Double
    let status: String
    let hasAttachments: Bool
}

推荐答案

该错误告诉您正在尝试调用String而不是方法(在您的情况下为结构构造函数).您可能已经在其他地方声明了名为ILT(大写)的String变量,这就是它失败的原因.

The error is telling you that you are trying to call a String instead of a method (struct constructor in your case). You've probably declared a String variable named ILT (uppercase) somewhere else and that's why it fails.

您发布的代码工作正常,因此该错误必须在代码中的其他地方.

Your posted code works fine so the error must be somewhere else in your code.

这篇关于无法调用非函数类型'String'的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆