I recently discovered a nutrition concept called 'if it fits your macros' or 'IIFYM', which basically revolves around having a set amount of carbohydrates, protein and fats per day and from there you can eat whatever you want as long as by the end of the day all of your macro nutrients (macros) are balanced.
With a controlled yet flexible diet, weight loss or weight gain is easily achievable by altering the macro content per day. For example for weight loss you may decrease fats and carbohydrates, and for muscle gain you may increase protein.
A simple macro calculator, like the one below, can be used to work out the quantity of each macro needed to satisfy your goals (e.g. weight loss or muscle gain). From there all you need to do is look at the nutritional information displayed on food packaging to calculate the macro content for each meal/snack throughout the day and keep a running total.
Although, IIFYM seems like an easily diet for achieving goals, it should be ensured that a balanced diet remains to encourage a healthy lifestyle. As with any nutrition/diet plan exercise should be recommended in conjunction.