Cheddar for iOS 开源项目教程

Cheddar for iOS 开源项目教程

cheddar-iosCheddar for iOS项目地址:https://gitcode.com/gh_mirrors/ch/cheddar-ios

项目介绍

Cheddar for iOS 是一个简单且即时任务管理器的应用程序,适用于 iPhone 和 iPad。该项目由 Nothing Magical Inc 开发,现已开源,允许开发者自由使用和修改其源代码。Cheddar for iOS 的源代码基于 Simplified BSD License 发布,但请注意,该许可证不包括图像资产,所有图像资产仍属于 Nothing Magical Inc。

项目快速启动

克隆项目

首先,克隆 Cheddar for iOS 项目到本地:

git clone --recursive https://github.com/nothingmagical/cheddar-ios.git

设置项目

进入项目目录并运行设置脚本:

cd cheddar-ios
rake setup

打开并构建项目

打开 Xcode 项目并构建:

open Cheddar\ for\ iOS.xcodeproj

在构建过程中,您可能会看到一个错误提示,要求您填写 API 凭证。如果您还没有 API 凭证,请访问 Cheddar 开发者网站获取,并确保设置 cheddar://oauth 作为您的重定向 URI。

应用案例和最佳实践

应用案例

Cheddar for iOS 可以作为一个基础模板,用于开发其他任务管理或待办事项应用程序。开发者可以根据自己的需求,添加或修改功能,以适应特定的业务场景。

最佳实践

  • 自定义界面:根据您的品牌风格,自定义应用程序的界面和用户体验。
  • 扩展功能:添加新的功能,如提醒、标签、优先级等,以增强任务管理的能力。
  • 集成第三方服务:将 Cheddar 与其他服务(如日历、邮件等)集成,提供更全面的工作流程支持。

典型生态项目

Cheddar for iOS 作为一个开源项目,可以与其他开源工具和框架结合使用,构建更强大的生态系统。以下是一些可能的生态项目:

  • 后端服务:使用开源的后端即服务(BaaS)平台,如 Firebase 或 Parse,来管理任务数据。
  • 前端框架:结合 React Native 或其他跨平台框架,开发多平台的任务管理应用。
  • 自动化工具:使用 Jenkins 或 GitHub Actions 进行持续集成和持续部署,确保代码质量和快速迭代。

通过这些生态项目的结合,开发者可以构建一个完整的、高效的、跨平台的任务管理解决方案。

cheddar-iosCheddar for iOS项目地址:https://gitcode.com/gh_mirrors/ch/cheddar-ios

不使用LINQ查询和操作集合 改进代码 namespace SandwichCalories { class Program { static void Main(string[] args) { // sandwich ingredients and their associated calories Dictionary<string, int> ingredients = new Dictionary<string, int>() { { "Bread", 66 }, { "Ham", 72 }, { "Bologna", 57 }, { "Chicken", 17 }, { "Corned Beef", 53 }, { "Salami", 40 }, { "Cheese, American", 104 }, { "Cheese, Cheddar", 113 }, { "Cheese, Havarti", 105 }, { "Mayonnaise", 94 }, { "Mustard", 10 }, { "Butter", 102 }, { "Garlic Aioli", 100 }, { "Sriracha", 15 }, { "Dressing, Ranch", 73 }, { "Dressing, 1000 Island", 59 }, { "Lettuce", 5 }, { "Tomato", 4 }, { "Cucumber", 4 }, { "Banana Pepper", 10 }, { "Green Pepper", 3 }, { "Red Onion", 6 }, { "Spinach", 7 }, { "Avocado", 64 } }; // prompt user for calorie range Console.Write("Enter minimum calories: "); int min_calories = int.Parse(Console.ReadLine()); Console.Write("Enter maximum calories: "); int max_calories = int.Parse(Console.ReadLine()); // calculate the minimum and maximum calories for the sandwich int min_sandwich_calories = 2 * ingredients["Bread"] + ingredients.Values.Min() * 2; int max_sandwich_calories = 2 * ingredients["Bread"] + ingredients.Values.Max() * 2; // check if the calorie range is valid if (max_calories < min_sandwich_calories) { Console.WriteLine("Sorry, it is impossible to create a sandwich within the given calorie range."); } else { // create the sandwich List<string> sandwich = new List<string> { "Bread" }; int sandwich_calories = 1 * ingredients["Bread"]; while (sandwich_calories < min_calories) { // add random ingredient string ingredient = ingredients.Keys.ElementAt(new Random().Next(ingredients.Count)); sandwich.Add(ingredient); sandwich_calories += ingredients[ingredient]; } while (sandwich_calories <= max_calories) { // add random ingredient string ingredient = ingredients.Keys.ElementAt(new Random().Next(ingredients.Count)); // check if the ingredient is the same as the previous one if (sandwich.Count >= 3 && ingredient == sandwich[sandwich.Count - 2]) { continue; } sandwich.Add(ingredient); sandwich_calories += ingredients[ingredient]; // check if the sandwich is already at the maximum calorie limit if (sandwich_calories == max_sandwich_calories) { break; } } // add the last slice of bread sandwich.Add("Bread"); // print the sandwich and its total calories Console.WriteLine("Your sandwich: " + string.Join(", ", sandwich)); Console.WriteLine("Total calories: " + sandwich_calories); } } } }
06-10
以下是不使用LINQ查询和操作集合改进的代码,这里使用了foreach循环和if条件语句来实现相同的功能: ```csharp using System; using System.Collections.Generic; namespace SandwichCalories { class Program { static void Main(string[] args) { // sandwich ingredients and their associated calories Dictionary<string, int> ingredients = new Dictionary<string, int>() { { "Bread", 66 }, { "Ham", 72 }, { "Bologna", 57 }, { "Chicken", 17 }, { "Corned Beef", 53 }, { "Salami", 40 }, { "Cheese, American", 104 }, { "Cheese, Cheddar", 113 }, { "Cheese, Havarti", 105 }, { "Mayonnaise", 94 }, { "Mustard", 10 }, { "Butter", 102 }, { "Garlic Aioli", 100 }, { "Sriracha", 15 }, { "Dressing, Ranch", 73 }, { "Dressing, 1000 Island", 59 }, { "Lettuce", 5 }, { "Tomato", 4 }, { "Cucumber", 4 }, { "Banana Pepper", 10 }, { "Green Pepper", 3 }, { "Red Onion", 6 }, { "Spinach", 7 }, { "Avocado", 64 } }; // prompt user for calorie range Console.Write("Enter minimum calories: "); int min_calories = int.Parse(Console.ReadLine()); Console.Write("Enter maximum calories: "); int max_calories = int.Parse(Console.ReadLine()); // calculate the minimum and maximum calories for the sandwich int min_sandwich_calories = 2 * ingredients["Bread"] + GetMinValue(ingredients.Values) * 2; int max_sandwich_calories = 2 * ingredients["Bread"] + GetMaxValue(ingredients.Values) * 2; // check if the calorie range is valid if (max_calories < min_sandwich_calories) { Console.WriteLine("Sorry, it is impossible to create a sandwich within the given calorie range."); } else { // create the sandwich List<string> sandwich = new List<string> { "Bread" }; int sandwich_calories = 1 * ingredients["Bread"]; while (sandwich_calories < min_calories) { // add random ingredient string ingredient = GetRandomIngredient(ingredients); sandwich.Add(ingredient); sandwich_calories += ingredients[ingredient]; } while (sandwich_calories <= max_calories) { // add random ingredient string ingredient = GetRandomIngredient(ingredients); // check if the ingredient is the same as the previous one if (sandwich.Count >= 3 && ingredient == sandwich[sandwich.Count - 2]) { continue; } sandwich.Add(ingredient); sandwich_calories += ingredients[ingredient]; // check if the sandwich is already at the maximum calorie limit if (sandwich_calories == max_sandwich_calories) { break; } } // add the last slice of bread sandwich.Add("Bread"); // print the sandwich and its total calories Console.WriteLine("Your sandwich: " + string.Join(", ", sandwich)); Console.WriteLine("Total calories: " + sandwich_calories); } } // helper methods static int GetMinValue(IEnumerable<int> values) { int minValue = int.MaxValue; foreach (int value in values) { if (value < minValue) { minValue = value; } } return minValue; } static int GetMaxValue(IEnumerable<int> values) { int maxValue = int.MinValue; foreach (int value in values) { if (value > maxValue) { maxValue = value; } } return maxValue; } static string GetRandomIngredient(Dictionary<string, int> ingredients) { int index = new Random().Next(ingredients.Count); int i = 0; foreach (string key in ingredients.Keys) { if (i == index) { return key; } i++; } return null; } } } ``` 在这个改进的代码中,我们使用了GetMinValue和GetMaxValue方法来获取字典中值的最小值和最大值,使用GetRandomIngredient方法来获取随机的食材名称。虽然这种方式代码量增加了,但是这种方式可以更好地理解代码的每个步骤,也可以更好地掌控代码的细节。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

瞿旺晟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值