Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swift: declare public variable

class XYActivity: UIActivity,YouTubeHelperDelegate
{
    var youTubeHelper:YouTubeHelper
    var uploadURL: String!
    override init() {
        self.youTubeHelper = YouTubeHelper()
    }
    override  func activityType() -> String? {
        return nil
    }
//
}

I want to make uploadURL public, That is, to be assigned in other class. When I add public infront of var uploadURL:String! it suggest me to make it as internal. I wanna make it public. Please help

like image 361
rishu1992 Avatar asked Jan 28 '15 12:01

rishu1992


People also ask

How do you make a public variable in Swift?

JuST ADD a keyword "public" at start this will make it public in the app.

How do you declare a global variable in Swift?

Here you can see section is a global variable we have defined, inside a class but outside a function. We can use an access modifier prefixed with the global variable as per the need. You can also define a global variables as static by prefixing static keyword.

What is difference between open and public in Swift?

An open class member is accessible and overridable outside of the defining module. A public class is accessible but not subclassable outside of the defining module. A public class member is accessible but not overridable outside of the defining module.

How do you use a variable outside a function in Swift?

"use variables from within the function, outside of the function" You can't. They are declared inside the function. So they are temporary, and scoped within the function. If you want something outside the function, pass it out as part of the result, or (less good) declare it outside the function.


2 Answers

You can make it public if the class that contains it is also public, so change that according to it.

like image 172
Dániel Nagy Avatar answered Oct 12 '22 12:10

Dániel Nagy


JuST ADD a keyword "public" at start this will make it public in the app.

like image 37
Muhammad Waqas Bhati Avatar answered Oct 12 '22 12:10

Muhammad Waqas Bhati