Struggling with SwiftUi Assignment - swiftui

How do I fix this error? I'm trying to have Ticks and Crosses. The Error will be Listed below.
I need to create a "Show all Completed tasks" Sliding button, in which will display the "Ticked" tasks.
note: don't mind the "contacts" variables and functions as it was originally a contacts assignment.
I've tried adding brackets around bits of code.
Here's my Pastebin With all the code:
https://pastebin.com/BpvWSVpP
By the way, the error is in the complete:bool
Cannot convert value of type 'Bool.Type' to expected argument type 'Bool'
let newContact = Contact( id: UUID().uuidString, firstName: self.firstName,
lastName: self.lastName, complete: Bool)

Your class Contact needs a Bool, not a type declaration.
var complete = false
...
let newContact = Contact(id: UUID().uuidString, firstName: self.firstName,
lastName: self.lastName, complete: complete)

Related

AWS Amplify GraphQL mutation is not updating a boolean field

I'm playing with the AWS Amplify GraphQL console and I've noticed that updating a boolean field is not working and I'm not sure exactly why. This is also not working from my React Native app. Basically, what I'm trying to do, is at onPress, change the isOnline to true or false (see full code below):
isOnline: !car.isOnline
schema.graphql
type Car #model
#key(name: "byUser", fields: ["userId"])
{
id: ID!
type: String!
latitude: Float
longitude: Float
heading: Float
plate: String
isOnline: Boolean
isActive: Boolean
orders: [Order] #connection(keyName: "byCar", fields: ["id"])
userId: ID!
user: User #connection(fields: ["userId"])
}
mutations.js
export const updateCar = /* GraphQL */ `
mutation UpdateCar(
$input: UpdateCarInput!
$condition: ModelCarConditionInput
) {
updateCar(input: $input, condition: $condition) {
id
type
latitude
longitude
heading
plate
isOnline
isActive
userId
_version
_deleted
_lastChangedAt
createdAt
updatedAt
}
}
`;
index.js
try {
const userData = await Auth.currentAuthenticatedUser();
const input = {
id: userData.attributes.sub,
isOnline: !car.isOnline,
}
const updatedCarData = await API.graphql(
graphqlOperation(
updateCar, {
input
})
)
console.log("Updated car: ", updatedCarData.data.updateCar)
setCar(updatedCarData.data.updateCar);
} catch (e) {
console.error(e);
}
From the app, every time I get the isOnline field set to true, even if I tried setting it to false instead of !car.isOnline.
I also tried creating a new field called isActive which was null initially, I created a mutation on AWS AppSync GraphQL console and was able to set it to false, but then, when trying to set it to true, updating is not working, it's always returning false.
As a note, updating the other fields, for example String fields, is working.
Can you please guide me into this issue?
I was able to solve this issue by:
Running the below command:
amplify update api
Select GraphQL, then Disable Conflict Detection
Last, but not least, run:
amplify push
I haven't found any explanation for this on the Amplify Docs, but if you're running into this issue, make sure to follow the above steps.

Github template yml field with no answer

I have the following template for the issues, I would like to do that when for example the second field Additional context is empty, then the user does not put any text.
When the issues is created, instead of writing me "No response", I would like the Additional context field not to be put.
Can you tell me if it can be done?
name: 🐛 Bug Report
description: Create a report to help us improve
title: "🐛 [BUG] - YOUR_DESCRIPTION"
labels: [🐛 bug]
body:
- type: textarea
attributes:
label: Describe the bug
placeholder: A clear and concise description of what the bug is.
- type: textarea
attributes:
label: Additional context
placeholder: Add any other context about the problem here.

AppSync - unable to create a schema with an array when the array property has `#key` directive associated with it

I recently added a #key directive to a schema field so that I could search by that field, although I now get an error implying the previously correct data type is not what is expected. It says it expects a string but got a list, although the field is a list containing an enum.
Is it possible to query by a specific field without using #key? If not, how can I create records when the #key (seemingly) changes the expected type of a list to a string?
Below is my code, I added the #key to the categories list, but now when I try to create a new Journey I get the error shown below.
This is the schema:
type Journey #model
#auth(rules: [{ allow: owner, operations: [create, delete, update] }])
#key(name: "getJourneysByCategories", fields: ["categories"], queryField: "getJourneysByCategories")
#key(name: "getJourneysByName", fields: ["name"], queryField: "getJourneysByName") {
id: ID!
name: String!
description: String
coverImage: String
isPrivate: Boolean!
members: [JourneyUsersBridge] #connection(name: "JourneyUsers")
moderators: [JourneyModeratorsBridge] #connection(name: "ModeratedBy")
creator: User! #connection(name: "JourneyCreator")
goals: [Goal] #connection(name: "JourneyGoals")
posts: [Post] #connection(name: "JourneyPosts")
categories: [JourneyCategory!]!
}
This is an example of the code used to create a Journey:
type CreateJourneyInput = {
name: string;
description?: string | null;
coverImage?: string | null;
isPrivate: boolean;
categories: Array<JourneyCategory | null>;
journeyCreatorId: string;
};
const journey: CreateJourneyInput = {
name: 'My GraphQL Journey',
description: 'This Journey was made using GraphQL minus DataStore!',
isPrivate: false,
categories: [JourneyCategory.EXMAMPLE],
journeyCreatorId: userId
};
const result = await API.graphql(
graphqlOperation(mutations.createJourney, { input: journey })
);
This is the full error:
"One or more parameter values were invalid: Type mismatch for Index Key categories Expected: S Actual: L IndexName: getJourneysByCategories (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: U4EB7HPO1GU5LHVAOPMGAJJHANVV4KQNSO5AEMVJF66Q9ASUAAJG)"
So I removed the getJourneysByCategories key and the upload worked fine. What's happening here and why?
I just want to be able to query by categories - perhaps #key wasn't the right route to take? Does the key directive not work with lists?

How to create a multi-use partial "template" in AngularJS?

I have a large list of items. Each item has it's own details.
In my main view/partial, I simply display a large list list of the item names.
When the user clicks on an item, I want the page to go to a partial which works as a "template", displaying information based on which list item is clicked, and hence possibly what the URL looks like. E.g. /listItem1/
This diagram below hopefully sums up what I want to achieve pretty clearly.
How can I do this?
Right now, I have a pretty standard set up in which I have all the information for each list item in an array of object literals, which is contained in a controller injected into the main app module. Like so:
var app = angular.module('app', [/*nodependencies*/]);
var controllers = {};
app.controller(controllers);
controllers.listController = function ($scope){
$scope.list = [
{name: 'List Item 1 Name', detail1: 'blahblah1', detail2: 'blahblah2'},
{name: 'List Item 2 Name', detail1: 'blahblah1', detail2: 'blahblah2'},
{name: 'List Item 3 Name', detail1: 'blahblah1', detail2: 'blahblah2'}
..... and so on
I know how to create basic views/partials as well. But what would be my next steps?
You can do what you want, using the built-in router which ships with AngularJS.
var app = angular.module('app', [/*nodependencies*/])
.config(function($routeProvider) {
$routeProvider
.when('/:itemId', {
templateUrl: '/path/to/partial',
controller : function($scope, $routeParams) {
$scope.item = $routeParams.itemId;
}
})
});
Basically, what the above means, is that if you browse to pdf/item/1
Then you will have access in your controller to $routeParams.itemId which will be equal to 1. You can then do whatever logic is necessary with this information on your partial to show the information you want.
Hope this helps.
Update
Please look at the controller, this is how you would get the param you passed via the URL, you would then do whatever it is you need to do with that param in the controller, and pass the data back to the view.
You can create a small directive that will use the multi-use partial to display each item on the list
Take a look at this working example (http://plnkr.co/edit/0jNVxRg6g3p8uxpustzz?p=preview)
var myApp = angular.module('myApp', []);
myApp.controller('listController', ['$scope', function ($scope) {
$scope.list = [
{
name: 'List Item 1 Name',
url: 'pdfs/item1.pdf',
detail: 'blahblah'
},
{
name: 'List Item 2 Name',
url: 'pdfs/item2.pdf',
detail: 'blahblah'
},
{
name: 'List Item 3 Name',
url: 'pdfs/item3.pdf',
detail: 'blahblah'
}
];
$scope.selectItem = function(item){
$scope.selected = item;
}
}]);
myApp.directive('listItem', [function () {
return {
restrict: 'A',
scope: {
item: '='
},
templateUrl: 'multiple-partial.html',
link: function (scope, element, iAttrs) {
}
};
}])

How to get records in JSON format from the model in emberjs?

I am accessing model data using the .find method but how to get records in JSON format from the model? I am getting output from .find() as: (Console log view)
Class {type: function, store: Class, isLoaded: true, isUpdating: true, toString: function…}
ember1375269653627: "ember313" __ember1375269653627_meta: Meta _super: undefined get content: function () { isLoaded: true isUpdating: false set content: function (value) { store: Class toString: function () { return ret; } type: Grid.ModalModel __proto: Object
I am new user of this community, so unable to upload image.
If you're using Ember Model, you do model.toJSON(). If you are trying to get values from the model you should use the getter model.get('name').
In javascript to create a JSON out of javascript object you may want to use:
JSON.stringify({name: "John"}); // => "{"name":"John"}"
It works pretty good for plain Ember.Objects. But you may not want to stringify all properties of given object. In such case you should use getProperties method of EmberObject. For example:
var john = Ember.Object.create({firstName: "John", lastName: "Doe", title: "CEO"});
JSON.stringify(john); // => "{"firstName":"John","lastName":"Doe", "title": "CEO"}"
var namesOnly = john.getProperties("firstName","lastName");
JSON.stringify(namesOnly); // => "{"firstName":"John","lastName":"Doe"}"