What is the use of open variables over public variables which are stored? [duplicate]What is the 'open' keyword in Swift?What is the difference between String? and String! (two ways of creating an optional variable)?Swift Beta performance: sorting arraysStatic vs class functions/variables in Swift classes?What is the difference between a property and a variable in Swift?Overriding methods in Swift extensionsVariable with getter/setter cannot have initial value, on overridden stored propertyWhy are class stored properties not supported in classes?Omitting class name when using a class var from the same classWhat design patten it is that the class variable has the class itselfCannot override with a stored property 'leadingConstraint' , Overriding non-open var outside of its defining module xcode 10
Reverse dictionary where values are lists
Solving a recurrence relation (poker chips)
How seriously should I take size and weight limits of hand luggage?
Do UK voters know if their MP will be the Speaker of the House?
Is it possible to create a QR code using text?
Avoiding the "not like other girls" trope?
Short story with a alien planet, government officials must wear exploding medallions
Bullying boss launched a smear campaign and made me unemployable
What do you call someone who asks many questions?
How did the Super Star Destroyer Executor get destroyed exactly?
Cursor Replacement for Newbies
Should I cover my bicycle overnight while bikepacking?
How do I deal with an unproductive colleague in a small company?
What exploit Are these user agents trying to use?
iPad being using in wall mount battery swollen
Detention in 1997
Mathematica command that allows it to read my intentions
How dangerous is XSS?
I would say: "You are another teacher", but she is a woman and I am a man
If human space travel is limited by the G force vulnerability, is there a way to counter G forces?
Arrow those variables!
Expand and Contract
How badly should I try to prevent a user from XSSing themselves?
Venezuelan girlfriend wants to travel the USA to be with me. What is the process?
What is the use of open variables over public variables which are stored? [duplicate]
What is the 'open' keyword in Swift?What is the difference between String? and String! (two ways of creating an optional variable)?Swift Beta performance: sorting arraysStatic vs class functions/variables in Swift classes?What is the difference between a property and a variable in Swift?Overriding methods in Swift extensionsVariable with getter/setter cannot have initial value, on overridden stored propertyWhy are class stored properties not supported in classes?Omitting class name when using a class var from the same classWhat design patten it is that the class variable has the class itselfCannot override with a stored property 'leadingConstraint' , Overriding non-open var outside of its defining module xcode 10
This question already has an answer here:
What is the 'open' keyword in Swift?
6 answers
I have checking out some code and I came across code that is marked as open
for a variable and it is a stored property. What kind of use does open
have over public
in this case? This is some made up code:
open class God
open var hasSuperPowers = true
class HalfGod: God
override var hasSuperPowers = false
This does not compile: Cannot override with a stored property 'hasSuperPowers'
. This is because the variable is stored.
My question is therefore: What difference does it make when marking my stored property either open
or public
? Can I do something with an open
stored property, which I can not do with a public
stored property?
I would expect xCode
would give me warning that marking hasSuperPowers
as open
would have no effect and would falsely imply to other people that they can override this variable. Ofcourse, this only applies when someone can confirm me that open
or public
does not make any difference.
Edit: I got now three people showing me the difference between open and var. Does my question even get read? Again:
What difference does it make when marking my stored property either open
or public
? Again: STORED PROPERTY
swift
marked as duplicate by Sh_Khan
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 8 at 22:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
What is the 'open' keyword in Swift?
6 answers
I have checking out some code and I came across code that is marked as open
for a variable and it is a stored property. What kind of use does open
have over public
in this case? This is some made up code:
open class God
open var hasSuperPowers = true
class HalfGod: God
override var hasSuperPowers = false
This does not compile: Cannot override with a stored property 'hasSuperPowers'
. This is because the variable is stored.
My question is therefore: What difference does it make when marking my stored property either open
or public
? Can I do something with an open
stored property, which I can not do with a public
stored property?
I would expect xCode
would give me warning that marking hasSuperPowers
as open
would have no effect and would falsely imply to other people that they can override this variable. Ofcourse, this only applies when someone can confirm me that open
or public
does not make any difference.
Edit: I got now three people showing me the difference between open and var. Does my question even get read? Again:
What difference does it make when marking my stored property either open
or public
? Again: STORED PROPERTY
swift
marked as duplicate by Sh_Khan
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 8 at 22:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
@Sh_Khan can you point out the sentence that would help me finding the answer to my question in your provided link? I know the difference betweenopen
andpublic
.
– J. Doe
Mar 8 at 22:45
I think I have answered exactly your question. You can override stored property in another module only if it's public. I have shown what does it mean to override a stored property.
– Sulthan
Mar 8 at 23:06
@Sulthan 'You can override stored property in another module only if it's public' What? Clearly we can not override stored properties. And only if it is public? I don't understand.
– J. Doe
Mar 8 at 23:07
1
Clearly you can override stored properties. You cannot override them with another stored property. You can override a stored property only with a computed property.
– Sulthan
Mar 8 at 23:08
@Sulthan Wow yes you are right :/ I feel dumb now
– J. Doe
Mar 8 at 23:11
add a comment |
This question already has an answer here:
What is the 'open' keyword in Swift?
6 answers
I have checking out some code and I came across code that is marked as open
for a variable and it is a stored property. What kind of use does open
have over public
in this case? This is some made up code:
open class God
open var hasSuperPowers = true
class HalfGod: God
override var hasSuperPowers = false
This does not compile: Cannot override with a stored property 'hasSuperPowers'
. This is because the variable is stored.
My question is therefore: What difference does it make when marking my stored property either open
or public
? Can I do something with an open
stored property, which I can not do with a public
stored property?
I would expect xCode
would give me warning that marking hasSuperPowers
as open
would have no effect and would falsely imply to other people that they can override this variable. Ofcourse, this only applies when someone can confirm me that open
or public
does not make any difference.
Edit: I got now three people showing me the difference between open and var. Does my question even get read? Again:
What difference does it make when marking my stored property either open
or public
? Again: STORED PROPERTY
swift
This question already has an answer here:
What is the 'open' keyword in Swift?
6 answers
I have checking out some code and I came across code that is marked as open
for a variable and it is a stored property. What kind of use does open
have over public
in this case? This is some made up code:
open class God
open var hasSuperPowers = true
class HalfGod: God
override var hasSuperPowers = false
This does not compile: Cannot override with a stored property 'hasSuperPowers'
. This is because the variable is stored.
My question is therefore: What difference does it make when marking my stored property either open
or public
? Can I do something with an open
stored property, which I can not do with a public
stored property?
I would expect xCode
would give me warning that marking hasSuperPowers
as open
would have no effect and would falsely imply to other people that they can override this variable. Ofcourse, this only applies when someone can confirm me that open
or public
does not make any difference.
Edit: I got now three people showing me the difference between open and var. Does my question even get read? Again:
What difference does it make when marking my stored property either open
or public
? Again: STORED PROPERTY
This question already has an answer here:
What is the 'open' keyword in Swift?
6 answers
swift
swift
edited Mar 8 at 23:02
J. Doe
asked Mar 8 at 22:40
J. DoeJ. Doe
3,02411438
3,02411438
marked as duplicate by Sh_Khan
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 8 at 22:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Sh_Khan
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 8 at 22:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
@Sh_Khan can you point out the sentence that would help me finding the answer to my question in your provided link? I know the difference betweenopen
andpublic
.
– J. Doe
Mar 8 at 22:45
I think I have answered exactly your question. You can override stored property in another module only if it's public. I have shown what does it mean to override a stored property.
– Sulthan
Mar 8 at 23:06
@Sulthan 'You can override stored property in another module only if it's public' What? Clearly we can not override stored properties. And only if it is public? I don't understand.
– J. Doe
Mar 8 at 23:07
1
Clearly you can override stored properties. You cannot override them with another stored property. You can override a stored property only with a computed property.
– Sulthan
Mar 8 at 23:08
@Sulthan Wow yes you are right :/ I feel dumb now
– J. Doe
Mar 8 at 23:11
add a comment |
1
@Sh_Khan can you point out the sentence that would help me finding the answer to my question in your provided link? I know the difference betweenopen
andpublic
.
– J. Doe
Mar 8 at 22:45
I think I have answered exactly your question. You can override stored property in another module only if it's public. I have shown what does it mean to override a stored property.
– Sulthan
Mar 8 at 23:06
@Sulthan 'You can override stored property in another module only if it's public' What? Clearly we can not override stored properties. And only if it is public? I don't understand.
– J. Doe
Mar 8 at 23:07
1
Clearly you can override stored properties. You cannot override them with another stored property. You can override a stored property only with a computed property.
– Sulthan
Mar 8 at 23:08
@Sulthan Wow yes you are right :/ I feel dumb now
– J. Doe
Mar 8 at 23:11
1
1
@Sh_Khan can you point out the sentence that would help me finding the answer to my question in your provided link? I know the difference between
open
and public
.– J. Doe
Mar 8 at 22:45
@Sh_Khan can you point out the sentence that would help me finding the answer to my question in your provided link? I know the difference between
open
and public
.– J. Doe
Mar 8 at 22:45
I think I have answered exactly your question. You can override stored property in another module only if it's public. I have shown what does it mean to override a stored property.
– Sulthan
Mar 8 at 23:06
I think I have answered exactly your question. You can override stored property in another module only if it's public. I have shown what does it mean to override a stored property.
– Sulthan
Mar 8 at 23:06
@Sulthan 'You can override stored property in another module only if it's public' What? Clearly we can not override stored properties. And only if it is public? I don't understand.
– J. Doe
Mar 8 at 23:07
@Sulthan 'You can override stored property in another module only if it's public' What? Clearly we can not override stored properties. And only if it is public? I don't understand.
– J. Doe
Mar 8 at 23:07
1
1
Clearly you can override stored properties. You cannot override them with another stored property. You can override a stored property only with a computed property.
– Sulthan
Mar 8 at 23:08
Clearly you can override stored properties. You cannot override them with another stored property. You can override a stored property only with a computed property.
– Sulthan
Mar 8 at 23:08
@Sulthan Wow yes you are right :/ I feel dumb now
– J. Doe
Mar 8 at 23:11
@Sulthan Wow yes you are right :/ I feel dumb now
– J. Doe
Mar 8 at 23:11
add a comment |
2 Answers
2
active
oldest
votes
You can override a property but not with a stored property. When overriding properties, you have to use a computed property, e.g.:
A class with a stored property:
open class God
open var hasSuperPowers = true
The property can be overriden only with a computed property:
class HalfGod: God
override var hasSuperPowers: Bool
didSet
print("(oldValue) -> (hasSuperPowers)")
or
class HalfGod: God
var hasPowers: Bool = false
override var hasSuperPowers: Bool
get
return hasPowers
set
hasPowers = newValue
You can override properties from other modules only if they are open
. public
properties cannot be overriden from other modules.
add a comment |
From the link in the comment:
An open class is accessible and subclassable outside of the defining module. 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.
What difference does it make when marking my stored property either open or public?
- If its marked public, then you cannot override the member outside the defining module.
Can I do something with an open stored property, which I can not do with a public stored property?
- You can subclass it outside of the defining module.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can override a property but not with a stored property. When overriding properties, you have to use a computed property, e.g.:
A class with a stored property:
open class God
open var hasSuperPowers = true
The property can be overriden only with a computed property:
class HalfGod: God
override var hasSuperPowers: Bool
didSet
print("(oldValue) -> (hasSuperPowers)")
or
class HalfGod: God
var hasPowers: Bool = false
override var hasSuperPowers: Bool
get
return hasPowers
set
hasPowers = newValue
You can override properties from other modules only if they are open
. public
properties cannot be overriden from other modules.
add a comment |
You can override a property but not with a stored property. When overriding properties, you have to use a computed property, e.g.:
A class with a stored property:
open class God
open var hasSuperPowers = true
The property can be overriden only with a computed property:
class HalfGod: God
override var hasSuperPowers: Bool
didSet
print("(oldValue) -> (hasSuperPowers)")
or
class HalfGod: God
var hasPowers: Bool = false
override var hasSuperPowers: Bool
get
return hasPowers
set
hasPowers = newValue
You can override properties from other modules only if they are open
. public
properties cannot be overriden from other modules.
add a comment |
You can override a property but not with a stored property. When overriding properties, you have to use a computed property, e.g.:
A class with a stored property:
open class God
open var hasSuperPowers = true
The property can be overriden only with a computed property:
class HalfGod: God
override var hasSuperPowers: Bool
didSet
print("(oldValue) -> (hasSuperPowers)")
or
class HalfGod: God
var hasPowers: Bool = false
override var hasSuperPowers: Bool
get
return hasPowers
set
hasPowers = newValue
You can override properties from other modules only if they are open
. public
properties cannot be overriden from other modules.
You can override a property but not with a stored property. When overriding properties, you have to use a computed property, e.g.:
A class with a stored property:
open class God
open var hasSuperPowers = true
The property can be overriden only with a computed property:
class HalfGod: God
override var hasSuperPowers: Bool
didSet
print("(oldValue) -> (hasSuperPowers)")
or
class HalfGod: God
var hasPowers: Bool = false
override var hasSuperPowers: Bool
get
return hasPowers
set
hasPowers = newValue
You can override properties from other modules only if they are open
. public
properties cannot be overriden from other modules.
edited Mar 8 at 23:07
answered Mar 8 at 22:55
SulthanSulthan
99.3k16162204
99.3k16162204
add a comment |
add a comment |
From the link in the comment:
An open class is accessible and subclassable outside of the defining module. 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.
What difference does it make when marking my stored property either open or public?
- If its marked public, then you cannot override the member outside the defining module.
Can I do something with an open stored property, which I can not do with a public stored property?
- You can subclass it outside of the defining module.
add a comment |
From the link in the comment:
An open class is accessible and subclassable outside of the defining module. 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.
What difference does it make when marking my stored property either open or public?
- If its marked public, then you cannot override the member outside the defining module.
Can I do something with an open stored property, which I can not do with a public stored property?
- You can subclass it outside of the defining module.
add a comment |
From the link in the comment:
An open class is accessible and subclassable outside of the defining module. 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.
What difference does it make when marking my stored property either open or public?
- If its marked public, then you cannot override the member outside the defining module.
Can I do something with an open stored property, which I can not do with a public stored property?
- You can subclass it outside of the defining module.
From the link in the comment:
An open class is accessible and subclassable outside of the defining module. 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.
What difference does it make when marking my stored property either open or public?
- If its marked public, then you cannot override the member outside the defining module.
Can I do something with an open stored property, which I can not do with a public stored property?
- You can subclass it outside of the defining module.
answered Mar 8 at 22:52
L0uisL0uis
55935
55935
add a comment |
add a comment |
1
@Sh_Khan can you point out the sentence that would help me finding the answer to my question in your provided link? I know the difference between
open
andpublic
.– J. Doe
Mar 8 at 22:45
I think I have answered exactly your question. You can override stored property in another module only if it's public. I have shown what does it mean to override a stored property.
– Sulthan
Mar 8 at 23:06
@Sulthan 'You can override stored property in another module only if it's public' What? Clearly we can not override stored properties. And only if it is public? I don't understand.
– J. Doe
Mar 8 at 23:07
1
Clearly you can override stored properties. You cannot override them with another stored property. You can override a stored property only with a computed property.
– Sulthan
Mar 8 at 23:08
@Sulthan Wow yes you are right :/ I feel dumb now
– J. Doe
Mar 8 at 23:11