Can't access singleton instance from Swift framework

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Can't access singleton instance from Swift framework

Tron Thomas
Using Xcode 6.3, I created a very simple, contrived command line tool in Swift. It contains three modules.

The main module:

import Foundation

let displayer
= ValueDisplayer()

displayer
.displayValue()


A ValueDisplayer module:

import Foundation

class ValueDisplayer {
    func displayValue
() {
        println
("The value is \(ValueProvider.instance.value)")
   
}
}



and a ValueProvider module:

import Foundation

public class ValueProvider {
   
class var instance: ValueProvider {
       
struct Static {
           
static let instance = ValueProvider()
       
}
       
       
return Static.instance
   
}
   
   
var value: Int {
       
return Int(arc4random())
   
}
}



This all compiled and ran successfully. However, I then decided to convert the ValueProvider to a framework. I created a Cocoa Framework target, and moved the ValueProvider module into it instead of in the command line target. I modified the ValueDisplayer module to this:

import Foundation
import ValueProvider

class ValueDisplayer {
    func displayValue
() {
        println
("The value is \(ValueProvider.instance.value)")
   
}
}



and configured the command line tool to link against the framework. Now I get the following compilation error in the ValueDisplayer module related to the println statement:

Module 'ValueProvider' has no member named 'instance'

I'm confused as to why the code doesn't work anymore. I'm wondering if the ValueProvider class is not being qualified correctly anymore, only it is unclear how that should be done.

What is needed to allow the command line tool to compile by linking against the framework?

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/3fa62b93-cadc-4dfb-818d-1b6c388f8ad9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can't access singleton instance from Swift framework

Jim Dovey
You need to mark the "instance" property as being public. Right now it's only internal. Note that making a class public doesn't automatically make its members public as well.

Sent from my iPhone

On May 2, 2015, at 10:32 AM, Tron Thomas <[hidden email]> wrote:

Using Xcode 6.3, I created a very simple, contrived command line tool in Swift. It contains three modules.

The main module:

import Foundation

let displayer
= ValueDisplayer()

displayer
.displayValue()


A ValueDisplayer module:

import Foundation

class ValueDisplayer {
    func displayValue
() {
        println
("The value is \(ValueProvider.instance.value)")
   
}
}



and a ValueProvider module:

import Foundation

public class ValueProvider {
   
class var instance: ValueProvider {
       
struct Static {
           
static let instance = ValueProvider()
       
}
       
       
return Static.instance
   
}
   
   
var value: Int {
       
return Int(arc4random())
   
}
}



This all compiled and ran successfully. However, I then decided to convert the ValueProvider to a framework. I created a Cocoa Framework target, and moved the ValueProvider module into it instead of in the command line target. I modified the ValueDisplayer module to this:

import Foundation
import ValueProvider

class ValueDisplayer {
    func displayValue
() {
        println
("The value is \(ValueProvider.instance.value)")
   
}
}



and configured the command line tool to link against the framework. Now I get the following compilation error in the ValueDisplayer module related to the println statement:

Module 'ValueProvider' has no member named 'instance'

I'm confused as to why the code doesn't work anymore. I'm wondering if the ValueProvider class is not being qualified correctly anymore, only it is unclear how that should be done.

What is needed to allow the command line tool to compile by linking against the framework?

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/3fa62b93-cadc-4dfb-818d-1b6c388f8ad9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/ECFBCA7E-300C-4A0E-8B4F-A913FA3B0A44%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can't access singleton instance from Swift framework

Tron Thomas
I tried making the instance variable public, and I’m still getting the same compile error.

On May 2, 2015, at 10:47 o'clock, Jim Dovey <[hidden email]> wrote:

You need to mark the "instance" property as being public. Right now it's only internal. Note that making a class public doesn't automatically make its members public as well.

Sent from my iPhone

On May 2, 2015, at 10:32 AM, Tron Thomas <[hidden email]> wrote:

Using Xcode 6.3, I created a very simple, contrived command line tool in Swift. It contains three modules.

The main module:

import Foundation

let displayer = ValueDisplayer()

displayer.displayValue()


A ValueDisplayer module:

import Foundation

class ValueDisplayer {
    func displayValue() {
        println("The value is \(ValueProvider.instance.value)")
    }
}



and a ValueProvider module:

import Foundation

public class ValueProvider {
    class var instance: ValueProvider {
        struct Static {
            static let instance = ValueProvider()
        }
        
        return Static.instance
    }
    
    var value: Int {
        return Int(arc4random())
    }
}



This all compiled and ran successfully. However, I then decided to convert the ValueProvider to a framework. I created a Cocoa Framework target, and moved the ValueProvider module into it instead of in the command line target. I modified the ValueDisplayer module to this:

import Foundation
import ValueProvider

class ValueDisplayer {
    func displayValue() {
        println("The value is \(ValueProvider.instance.value)")
    }
}



and configured the command line tool to link against the framework. Now I get the following compilation error in the ValueDisplayer module related to the println statement:

Module 'ValueProvider' has no member named 'instance'

I'm confused as to why the code doesn't work anymore. I'm wondering if the ValueProvider class is not being qualified correctly anymore, only it is unclear how that should be done.

What is needed to allow the command line tool to compile by linking against the framework?


-- 
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/3fa62b93-cadc-4dfb-818d-1b6c388f8ad9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/F59F2D57-72E7-4A96-B53A-267F2B192BC7%40frontier.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can't access singleton instance from Swift framework

Jim Dovey
Reading through it again, there may be a scoping problem here. Is your framework/module called ValueProvider, the same as the class? If that is the case, then it sounds as though simply using "ValueProvider" unqualified is being treated as the module, not the class.

Note that the error says "Module 'ValueProvider'", not "Class 'ValueProvider'".

To test the hypothesis, use the fully-qualified name of the class. Replace "ValueProvider.instance" with "ValueProvider.ValueProvider.instance". If that solves the problem, then I would suggest renaming your module to avoid the name clash. When the compiler looks for ValueProvider then, it will not find a top-level symbol (module name) so will search within the imported modules and find your class.

Sent from my iPhone

On May 2, 2015, at 1:06 PM, Tron Thomas <[hidden email]> wrote:

I tried making the instance variable public, and I’m still getting the same compile error.

On May 2, 2015, at 10:47 o'clock, Jim Dovey <[hidden email]> wrote:

You need to mark the "instance" property as being public. Right now it's only internal. Note that making a class public doesn't automatically make its members public as well.

Sent from my iPhone

On May 2, 2015, at 10:32 AM, Tron Thomas <[hidden email]> wrote:

Using Xcode 6.3, I created a very simple, contrived command line tool in Swift. It contains three modules.

The main module:

import Foundation

let displayer = ValueDisplayer()

displayer.displayValue()


A ValueDisplayer module:

import Foundation

class ValueDisplayer {
    func displayValue() {
        println("The value is \(ValueProvider.instance.value)")
    }
}



and a ValueProvider module:

import Foundation

public class ValueProvider {
    class var instance: ValueProvider {
        struct Static {
            static let instance = ValueProvider()
        }
        
        return Static.instance
    }
    
    var value: Int {
        return Int(arc4random())
    }
}



This all compiled and ran successfully. However, I then decided to convert the ValueProvider to a framework. I created a Cocoa Framework target, and moved the ValueProvider module into it instead of in the command line target. I modified the ValueDisplayer module to this:

import Foundation
import ValueProvider

class ValueDisplayer {
    func displayValue() {
        println("The value is \(ValueProvider.instance.value)")
    }
}



and configured the command line tool to link against the framework. Now I get the following compilation error in the ValueDisplayer module related to the println statement:

Module 'ValueProvider' has no member named 'instance'

I'm confused as to why the code doesn't work anymore. I'm wondering if the ValueProvider class is not being qualified correctly anymore, only it is unclear how that should be done.

What is needed to allow the command line tool to compile by linking against the framework?


-- 
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/3fa62b93-cadc-4dfb-818d-1b6c388f8ad9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/57E3DFD8-C4C5-4EFB-876C-79407D8B4599%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can't access singleton instance from Swift framework

Tron Thomas
The name of the framework in also ValueProvider. Theoretically that shouldn’t matter. Someone should be able to call their framework whatever they want. I did notice that it said ‘Module’ instead of ‘Class’, which is why I originally mentioned qualifying the class. Trying ValueProvider.ValueProvider.instance results in the error: Module ‘ValueProvider’ has no member named ‘ValueProvider’.

I’m having great difficulty understanding what it takes to properly reference items in the frame work. I even tried adding a global function to the framework, and was unable to figure out how to successfully call that as well.

On May 2, 2015, at 13:21 o'clock, Jim Dovey <[hidden email]> wrote:

Reading through it again, there may be a scoping problem here. Is your framework/module called ValueProvider, the same as the class? If that is the case, then it sounds as though simply using "ValueProvider" unqualified is being treated as the module, not the class.

Note that the error says "Module 'ValueProvider'", not "Class 'ValueProvider'".

To test the hypothesis, use the fully-qualified name of the class. Replace "ValueProvider.instance" with "ValueProvider.ValueProvider.instance". If that solves the problem, then I would suggest renaming your module to avoid the name clash. When the compiler looks for ValueProvider then, it will not find a top-level symbol (module name) so will search within the imported modules and find your class.

Sent from my iPhone

On May 2, 2015, at 1:06 PM, Tron Thomas <[hidden email]> wrote:

I tried making the instance variable public, and I’m still getting the same compile error.

On May 2, 2015, at 10:47 o'clock, Jim Dovey <[hidden email]> wrote:

You need to mark the "instance" property as being public. Right now it's only internal. Note that making a class public doesn't automatically make its members public as well.

Sent from my iPhone

On May 2, 2015, at 10:32 AM, Tron Thomas <[hidden email]> wrote:

Using Xcode 6.3, I created a very simple, contrived command line tool in Swift. It contains three modules.

The main module:

import Foundation

let displayer = ValueDisplayer()

displayer.displayValue()


A ValueDisplayer module:

import Foundation

class ValueDisplayer {
    func displayValue() {
        println("The value is \(ValueProvider.instance.value)")
    }
}



and a ValueProvider module:

import Foundation

public class ValueProvider {
    class var instance: ValueProvider {
        struct Static {
            static let instance = ValueProvider()
        }
        
        return Static.instance
    }
    
    var value: Int {
        return Int(arc4random())
    }
}



This all compiled and ran successfully. However, I then decided to convert the ValueProvider to a framework. I created a Cocoa Framework target, and moved the ValueProvider module into it instead of in the command line target. I modified the ValueDisplayer module to this:

import Foundation
import ValueProvider

class ValueDisplayer {
    func displayValue() {
        println("The value is \(ValueProvider.instance.value)")
    }
}



and configured the command line tool to link against the framework. Now I get the following compilation error in the ValueDisplayer module related to the println statement:

Module 'ValueProvider' has no member named 'instance'

I'm confused as to why the code doesn't work anymore. I'm wondering if the ValueProvider class is not being qualified correctly anymore, only it is unclear how that should be done.

What is needed to allow the command line tool to compile by linking against the framework?


-- 
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/3fa62b93-cadc-4dfb-818d-1b6c388f8ad9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to a topic in the Google Groups "Swift Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swift-language/lyxBy6mKA68/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/57E3DFD8-C4C5-4EFB-876C-79407D8B4599%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/E7535F86-C3B1-4EE2-A523-12B41EF51A22%40frontier.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Can't access singleton instance from Swift framework

Tron Thomas
I got program to build and run. What I had to do was go to the Build Phases for the framework and remove the generated header file from the Headers section. I don’t know why this makes things work. My understanding is that header is needed to help with Objective-C interaction. If the program had needed to  interact with Objective-C as well as Swift, I’m wondering how anyone could get things to work properly.

On May 2, 2015, at 14:53 o'clock, Tron Thomas <[hidden email]> wrote:

The name of the framework in also ValueProvider. Theoretically that shouldn’t matter. Someone should be able to call their framework whatever they want. I did notice that it said ‘Module’ instead of ‘Class’, which is why I originally mentioned qualifying the class. Trying ValueProvider.ValueProvider.instance results in the error: Module ‘ValueProvider’ has no member named ‘ValueProvider’.

I’m having great difficulty understanding what it takes to properly reference items in the frame work. I even tried adding a global function to the framework, and was unable to figure out how to successfully call that as well.

On May 2, 2015, at 13:21 o'clock, Jim Dovey <[hidden email]> wrote:

Reading through it again, there may be a scoping problem here. Is your framework/module called ValueProvider, the same as the class? If that is the case, then it sounds as though simply using "ValueProvider" unqualified is being treated as the module, not the class.

Note that the error says "Module 'ValueProvider'", not "Class 'ValueProvider'".

To test the hypothesis, use the fully-qualified name of the class. Replace "ValueProvider.instance" with "ValueProvider.ValueProvider.instance". If that solves the problem, then I would suggest renaming your module to avoid the name clash. When the compiler looks for ValueProvider then, it will not find a top-level symbol (module name) so will search within the imported modules and find your class.

Sent from my iPhone

On May 2, 2015, at 1:06 PM, Tron Thomas <[hidden email]> wrote:

I tried making the instance variable public, and I’m still getting the same compile error.

On May 2, 2015, at 10:47 o'clock, Jim Dovey <[hidden email]> wrote:

You need to mark the "instance" property as being public. Right now it's only internal. Note that making a class public doesn't automatically make its members public as well.

Sent from my iPhone

On May 2, 2015, at 10:32 AM, Tron Thomas <[hidden email]> wrote:

Using Xcode 6.3, I created a very simple, contrived command line tool in Swift. It contains three modules.

The main module:

import Foundation

let displayer = ValueDisplayer()

displayer.displayValue()


A ValueDisplayer module:

import Foundation

class ValueDisplayer {
    func displayValue() {
        println("The value is \(ValueProvider.instance.value)")
    }
}



and a ValueProvider module:

import Foundation

public class ValueProvider {
    class var instance: ValueProvider {
        struct Static {
            static let instance = ValueProvider()
        }
        
        return Static.instance
    }
    
    var value: Int {
        return Int(arc4random())
    }
}



This all compiled and ran successfully. However, I then decided to convert the ValueProvider to a framework. I created a Cocoa Framework target, and moved the ValueProvider module into it instead of in the command line target. I modified the ValueDisplayer module to this:

import Foundation
import ValueProvider

class ValueDisplayer {
    func displayValue() {
        println("The value is \(ValueProvider.instance.value)")
    }
}



and configured the command line tool to link against the framework. Now I get the following compilation error in the ValueDisplayer module related to the println statement:

Module 'ValueProvider' has no member named 'instance'

I'm confused as to why the code doesn't work anymore. I'm wondering if the ValueProvider class is not being qualified correctly anymore, only it is unclear how that should be done.

What is needed to allow the command line tool to compile by linking against the framework?


-- 
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/3fa62b93-cadc-4dfb-818d-1b6c388f8ad9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to a topic in the Google Groups "Swift Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swift-language/lyxBy6mKA68/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/57E3DFD8-C4C5-4EFB-876C-79407D8B4599%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to a topic in the Google Groups "Swift Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/swift-language/lyxBy6mKA68/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/E7535F86-C3B1-4EE2-A523-12B41EF51A22%40frontier.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/773C96E3-4961-4676-A7AC-853E64167E99%40frontier.com.
For more options, visit https://groups.google.com/d/optout.