Skip to content

Instantly share code, notes, and snippets.

@Neurone
Last active July 23, 2020 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Neurone/83876bb40c75640d5fa13cb0b4a0ed78 to your computer and use it in GitHub Desktop.
Save Neurone/83876bb40c75640d5fa13cb0b4a0ed78 to your computer and use it in GitHub Desktop.
Load this file into remix-ide (Realtime Ethereum Contract Compiler and Runtime) by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.6.9+commit.3e3065ac.js&optimize=false&gist=83876bb40c75640d5fa13cb0b4a0ed78
// https://ethereum.stackexchange.com/questions/84109/solidity-0-4-26-check-if-element-already-exists-in-array
// SPDX-License-Identifier: MIT
pragma experimental ABIEncoderV2;
pragma solidity >=0.6.9 <0.7.0;
contract stackExchange_84109_structWithMapping {
struct User {
string username;
string category;
string data;
bool initialized;
}
mapping(string => User) public users;
function setUserData(string memory _username, string memory _category, string memory _data) public{
require(!users[_username].initialized);
users[_username].username = _username;
users[_username].category = _category;
users[_username].data = _data;
users[_username].initialized = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment