I want my custom Error type has name "Error" [closed] - swift

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
Not "MyError" or with any other prefixes or suffixes. I want it to be just "Error". Because when I refer this type in the code it would be like: MyApp.Error. Nice and simple.
enum MyApp {
enum SomeModel {}
enum OneMoreModel {}
enum Error: Error {
}
}
It does't compile:
'Error' has a raw type that depends on itself
I tried Error: swift.Error but
Cannot find type 'swift' in scope
What else can I try?

The name of the module is Swift, with a capital "S".
enum Error: Swift.Error {
}

Related

Why you not use an open keyword with structs in swift? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 14 days ago.
This post was edited and submitted for review 14 days ago.
Improve this question
everywhere talk about only classes with open/public keyword so it would be great if swift experts can provide satisfying answers with an example.
for eg: we can do this in class but don't do it in the struct!
open class Animal {
var name: String
var age: Int
init(name: String, age: Int) {
self.name = name
self.age = age
}
}
open is irrelevant to structs, since they don't have inheritance. public relates to visibility from outside the module, so it is relevant to all types.

scala : method not getting called without adding private modifier [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 months ago.
Improve this question
i am new to scala and cant seem to notice any issue here. As mentioned in code comments, if(enableXMLMessageLog(method)) is evaluating to false without executing the method enableXMLMessageLog . Once i add private to this method, it starts to work as expected and returns true on evaluation.
The methods are member of an abstract class.
Any idea what is happening here and why is it only getting called after adding private ?
i think i got it . the method was being called from a unit test class and only the logBookingMessage method was set to when(messageLogger.logBookingMessage(any[LoggingMethod])).thenCallRealMethod() hence it was not able to call the method enableXMLMessageLog as it was being mocked and thus returning false.
On adding private to the method, mocking framework does not mock and call the actual implementation of the method hence returning true.

Non-nullable instance field _repository must be initialized. Try adding an initializer expression, or add a field initializer in this constructor [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
Improve this question
enter image description here
Non-nullable instance field '_repository' must be initialized. Try adding an initializer expression, or add a field initializer in this constructor, or mark it 'late'.dartnot_initialized_non_nullable_instance_field in the flutter
In Dart constructors don't use their body to initialize properties. What you are looking for is the following snippet:
class NewsService {
Repository _repository;
NewsService() : _repository = Repository();
}

In Scala how can I cast a value without asInstanceOf? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have code that returns a value as Any. I have a way to get the actual type of this value. This is part of a very reflection-oriented solution.
// Reflecting on a class I have info about its constructor fields:
val fieldMembers: fieldMembersByName: ListMap[String,ClassFieldMember] = ...
// ClassField member has a method valueIn(inst:T): Any, where T is the type
// of the parent class
val nameField = fieldMembers("name").valueIn(personObject)
// This obtains the value of some instance's (personObject's) name field,
// but to Scala the type of nameField is Any. I need to cast it, but to what?
val realType: Type = ... // a bunch of ugly reflection that returns the acutal
// type of the name field, i.e. String here
What I'm looking for is the equivalent of the (syntactically invalid):
val purifiedValue = nameField.asInstanceOf[realType]
This is not possible for the simple reason that the type of a variable is defined at compile time not at run time.
So when you write
val purifiedValue = nameField.asInstanceOf[realType]
the compiler needs to decide what is the type of purifiedValue. There is no way that it can do this if realType is not defined until run time.
It is also not clear how this would help even if it did work. What are you going to do with purifiedValue once you have assigned it? You can't call any methods on it because you don't know what type it is going to have. You can't pass it to a function because you don't know if the type matches the argument type of the function argument. The only things that you can do with purifiedValue are the things you can do with Any, which is the type it had in the first place.

When do I need to declare class data members as public? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Is there any situation when I need to declare the class data members as public?
Are there any chances of errors with such declarations?
Need to? No.
Any data access can be done through getters and setters:
(the truth of the above statement may depend on the language)
private member
public getMember()
return member
public setMember(newValue)
member = newValue
Instead of
public member
Errors? No. Well, apart from having to change your code to use the getters and setters instead.
Want to? Possibly.
The main disadvantage of using getters and setters is how pretty your code looks - how readable it is and code bloating.
See this for advantages of using getters and setters.
If using getters and setters classifies as similar to making the member public for you, then there are many scenario's where you need this at one of these kinds of access. Consider an artificial example of having a Car class. There would be many reasons why you'd want to get the windscreen member variable.