---
title: "How to call a function within a structure and a class?"  
description: "How to call a function within a structure and a class?"  
author: "Anonymous User"  
published: 2014-10-13  
updated: 2014-10-13  
canonical: https://www.mindstick.com/forum/2372/how-to-call-a-function-within-a-structure-and-a-class  
category: "iphone"  
tags: ["iphone", "mobile development"]  
reading_time: 1 minute  

---

# How to call a function within a structure and a class?

I have [two files](https://www.mindstick.com/interview/2597/can-you-have-two-files-with-the-same-file-name-in-gac): ClassA.swift and ClassB.swift

```
class ClassA: NSObject {        struct StructA {            func talk(string: String) {                println("I say: \(string)")            }        }    }      class ClassB: NSObject {        func makeItTalk(string: String) {            ClassA.StructA.talk("Hello")
<--------------        }    }
```

I get the following [error message](https://www.mindstick.com/forum/23174/error-message-the-page-you-are-requesting-cannot-be-served-because-of-the-extension-configuration)\

Type 'ClassA.StructA' does not conform to [protocol](https://www.mindstick.com/forum/55090/what-is-stateless-protocol) 'StringLiteralConvertible'\

Any idea why? Is it actually something than can be achieved?\

## Replies

### Reply by Anonymous User

You are using talk as static method, but it is declared as instance method. Change to:

```
class ClassA: NSObject {        struct StructA {            static func talk(string: String) {                println("I say: \(string)")            }        }    }
```

### Reply by Anonymous User

You are accessing StructA in a static context, whereas you need an instance of it:\

class ClassB: NSObject {

func makeItTalk(string: String) {

var myStruct = ClassA.StructA()

myStruct.talk("Hello")

}

}

Alternatively, if your goal is to access that method statically, just declare it as a static struct method:\

static func talk(string: String) {

println("I say: \(string)")

}


---

Original Source: https://www.mindstick.com/forum/2372/how-to-call-a-function-within-a-structure-and-a-class

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
