Skip to content

Instantly share code, notes, and snippets.

@vis-kid
Created February 5, 2022 23:45
Show Gist options
  • Save vis-kid/28f7d22e64eb50dea5400760cc435d74 to your computer and use it in GitHub Desktop.
Save vis-kid/28f7d22e64eb50dea5400760cc435d74 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.12+commit.7709ece9.js&optimize=false&runs=200&gist=
pragma solidity 0.5.12;
contract Struct {
struct Todo {
string text;
bool completed;
}
Todo[] public todos;
function createToDo(string memory _text) public {
todos.push(Todo(_text, false));
}
function createToDo2(string memory _text) public {
todos.push(Todo({text: _text, completed: false}));
}
function createToDo3(string memory _text) public {
Todo memory todo;
todo.text = _text;
todos.push(todo);
}
function getTodo(uint _index) public view returns (string memory, bool) {
Todo storage todo = todos[_index];
return(todo.text, todo.completed);
}
function updateText(uint _index, string memory _text) public {
Todo storage todo = todos[_index];
todo.text = _text;
}
function toggleComplete(uint _index) public {
Todo storage todo = findTodo(_index);
todo.completed = !todo.completed;
}
function findTodo(uint _index) internal view returns(Todo storage) {
Todo storage todo = todos[_index];
return(todo);
}
// toggleComplete
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment