#GestureState cannot be used used as an attribute - swift

In a project I want to declare a variable #GestureState, however I get the following error for no reason: "enum 'GestureState' cannot be used as an attribute".
I've worked with this kind of wrapper property before and didn't get this error at the time.
If anyone has an idea where this error might come from, I'll take it.
#GestureState var selected = false // error here :/

This happening because somewhere in the project you're creating an enum named GestureState rename it to something else and you're good to go.
Modify this:
enum GestureState { ... }
To this:
enum GestureStateType { ... }

Related

UStruct: type must be a UCLASS, USTRUCT or UENUM

I’m probably missing something simple but I can’t find it. The struct is marked as USTRUCT() but still it complains about it not being a USTRUCT. It’s not caused by the TArray because removing that still gives the same error. Also I can use the struct FCrusherTrigger in blueprints without a problem at all. But c++ gives me an error.
USTRUCT(BlueprintType)
struct FCrusherTrigger
{
GENERATED_USTRUCT_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CrusherTrigger")
ECollisionShapeEnum CollisionType;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "CrusherTrigger")
FTransform RelativeTransform;
FCrusherTrigger()
{
CollisionType = ECollisionShapeEnum::CollisionShape_Box;
}
};
...
// BaseCrusher.h
public:
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "BaseCrusher")
TArray<FCrusherTrigger> TriggersSetup; // <<<<<<<<<<<<< error here ```
Try to place your constructor above your properties, and call it public. My guess, the issue is around your Construct.

Xcode unit test warning when declare variable

Can anyone explain me why when i declare variable like this:
private let viewModel = TermsAndConditionViewModel()
// TermsAndConditionViewModel
class TermsAndConditionViewModel {
private let permissionsModel: PermissionsModel
private let userSession: UserSessionManager
init(
permissionsModel: PermissionsModel = PermissionsModelImpl(),
userSession: UserSessionManager = UserSessionManager.shared
) {
self.permissionsModel = permissionsModel
self.userSession = userSession
}
}
and run test in Xcode I got warning like
update: there is no message about warning.
and this is when I check in Xcode/Coverage
Thank for your help.
Hi #user2629744 welcome to StackOverflow.
The red bar you are seeing in the right gutter is not a warning but Xcode's Code Coverage Annotation.
It's red and it shows a 0 because there is no test exercising that code path.
It's hard to be sure without having access to your codebase, but since we're talking about a view model in your example I'm guessing that line of code comes from the view layer. Right?
If that's the case, it might be okay if you don't test it. If all the business logic lives in the view model (which you can throughly test) and you keep your view layer humble, then you'll still have the majority of your behavior covered.

EXC_BAD_INSTRUCTION when trying to print error from Swift 4 do-try-catch, skipping specified catch conditions

I'm trying to catch my custom Error, but for some reason my catch statements where I name the error that I know is being thrown, it skips those, goes to the default catch, and then gives me a EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0) when I try to do print("Unexpected error \(error)")
Here's some abbreviated code:
This is the error that I have declared in my file that houses the class that I'm calling the method on (the class is called CC8DB):
public enum CC8RSVPError: Error {
case noEventOnDate
case invalidRSVPValue
}
I have a method declared as:
public func rsvpForEvent(_ inEventDate:Date?, forUserID inUserID:String, withValue inRSVPValue:String) throws -> CC8RSVPStatus
In another class were I'm calling this method, I have this:
do {
let rsvpResponse = try self.cc8DB.rsvpForEvent(inRSVPDate, forUserID: String(inMessage.author.id.rawValue), withValue: inRSVPValue);
...(other code to do when this doesn't fail)...
} catch CC8RSVPError.invalidRSVPValue {
...(Report specific error to user)...
} catch CC8RSVPError.noEventOnDate {
...(Report specific error to user)...
} catch {
...(Report general error to user)...
print("Error doing RSVP: \(error)");
}
And finally, in the CC8DB.rsvpForEvent() method, I'm triggering an error that does this:
throw CC8RSVPError.invalidRSVPValue;
The germane part of this method is:
public func rsvpForEvent(_ inEventDate:Date?, forUserID inUserID:String, withValue inRSVPValue:String) throws -> CC8RSVPStatus
{
var retStatus = CC8RSVPStatus(eventDate: nil, previousRSVP: "", newRSVP: "");
var upperRSVPValue:String = inRSVPValue.uppercased();
if (["YES", "MAYBE", "NO"].contains(upperRSVPValue)) {
//...(Code to do things when the info is correct)...
} else {
throw CC8RSVPError.invalidRSVPValue;
}
return retStatus;
}
For my test case where I'm seeing this, the inRSVPValue is "bla", to test what happens when a user doesn't enter a valid status value.
What I'm seeing is that rather than going into the catch that's specific for the CC8RSVPError.invalidRSVPValue case, it's going down to the general catch. In addition, I'm getting the EXC_BAD_INSTRUCTION on the line where I try and print the error value.
I've stepped through it to verify that I am indeed hitting the throw line that I think I am, and I can see in the debugger that the value of error is CC8DB.CC8RSVPError.invalidRSVPValue, but even if I try to do po error from the lldb command, I get the same exception error.
Has anyone seen this or know what I could have done to make do-try-catch not work right?
You could assign a constant named error inside your catch statement and inside the catch block read the constant and figure out what to do with it.
do something like:
} catch let error {
switch error {
case CC8RSVPError.noEventOnDate:
// code
case CC8RSVPError.invalidRSVPValue:
// code
}
}
Ok, I figured it out. I realized that somewhere along the way, some build setting got set so that I was statically linking into the binary (this is a command-line tool, a bot for Discord to be specific).
I saw some warnings about some of the Swift runtime libs being found in both the binary and the XCode developer runtime area, and realized that it might be that the error object was being used both in my CC8DB module in the binary and in the built-modules folder (or something to that effect).
I need to statically link for when I actually deploy the bot to where it's going to run, so I must have turned something on that won't turn off (I deleted the extra flags that I thought turned that on, but that wasn't fixing it).
Basically, I recreated my .xcodeproj file with swift package generate-xcodeproj to clear out whatever I broke, and now it works as expected.
Thanks to everyone who looked at this and offered help (especially #gmogames for his time and help). I'm sure it helped lead me down the path of figuring this out.

How to use Dropbox Sync API enumerations in Swift?

Given a DBFile object, I kept getting compiler errors if I tried to compare the DBFileState to the enumerated values, e.g.
var file : DBFile = <some file>
var state = file.status.state
if state == DBFileStateUploading { do something }
The compiler error would say that '==' cannot compare (DBFileState, DBFileState)
The answer turned out to be quite simple:
if state.value == DBFileStateUploading.value { do something }
This has something to do with the fact the the Dropbox enumerations are imported C-style enumerations, but this wasn't easy to find.
Just thought I'd share to help anyone else that might be struggling with this.

FluentMongo throwing error all of a sudden

I am using FluentMongo and the MongoDBCSharpDriver. My code was working fine for a while, but after updating my MongoCSharpDriver, I now I keep getting this error when I try to query the database:
"Discriminators can only be registered for classes, not for interface MyLib.Services.IRepoData."
The interface IRepoData is just one that I use for all my objects saved to MongoDB. It just defines _id for everything. Here is the line that is breaking:
var item = Collection.AsQueryable().SingleOrDefault(a => a.Id == itemID);
Can anyone shed some light on this one? If I just use .SingleOrDefault() with no lambda then it works fine, its passing a lambda that breaks it.
EDIT
In case this helps...
var Collection = GetCollection<MyClass>();
private MongoCollection<T> GetCollection<T>() where T : class, new()
{
string typeName = typeof(T).Name;
var collection = db.GetCollection<T>(typeName, safeMode);
return collection;
}
Found it! I was calling GetCollection() from within another generic method, like this:
public T Save<T>(T item) where T : class, IRepoData, new()
{
GetCollection<T>().Save(item);
}
This caused GetCollection to see T as the interface instead of the actual instance class. GetCollection works fine anywhere else.
For anyone else with this problem, I just used a low level query like this instead... Collection.FindOneAs<T>(Query.EQ("Id", itemID.ToString()));