- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的第一次发布,因此如果我错过一两个准则,我深表歉意。随时给我打电话。无论如何。我目前正在缓慢地尝试学习Objective-c和iOS / xcode,因此正在做大量的教程。我碰到了一个并且一直在努力,但是我想尝试挑战自己并进行一些调整。最终,这是一个学习过程。所以我的主要问题如下:
在使用Xcode的Objective-C中,如何用plist将自定义类替换为NSObjects?
这是我试图找出如何替换为具有所有相同信息的plist的代码段:
@implementation RecipeBookViewController {
NSArray *recipes;
}
@synthesize tableView = _tableView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Initialize table data
// recipes = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", @"Creme Brelee", @"White Chocolate Donut", @"Starbucks Coffee", @"Vegetable Curry", @"Instant Noodle with Egg", @"Noodle with BBQ Pork", @"Japanese Noodle with Pork", @"Green Tea", @"Thai Shrimp Cake", @"Angry Birds Cake", @"Ham and Cheese Panini", nil];
Recipe *recipe1 = [Recipe new];
recipe1.name = @"Egg Benedict";
recipe1.prepTime = @"30 min";
recipe1.imageFile = @"egg_benedict.jpg";
recipe1.ingredients = [NSArray arrayWithObjects:@"2 fresh English muffins", @"4 eggs", @"4 rashers of back bacon", @"2 egg yolks", @"1 tbsp of lemon juice", @"125 g of butter", @"salt and pepper", nil];
Recipe *recipe2 = [Recipe new];
recipe2.name = @"Mushroom Risotto";
recipe2.prepTime = @"30 min";
recipe2.imageFile = @"mushroom_risotto.jpg";
recipe2.ingredients = [NSArray arrayWithObjects:@"1 tbsp dried porcini mushrooms", @"2 tbsp olive oil", @"1 onion, chopped", @"2 garlic cloves", @"350g/12oz arborio rice", @"1.2 litres/2 pints hot vegetable stock", @"salt and pepper", @"25g/1oz butter", nil];
Recipe *recipe3 = [Recipe new];
recipe3.name = @"Full Breakfast";
recipe3.prepTime = @"20 min";
recipe3.imageFile = @"full_breakfast.jpg";
recipe3.ingredients = [NSArray arrayWithObjects:@"2 sausages", @"100 grams of mushrooms", @"2 rashers of bacon", @"2 eggs", @"150 grams of baked beans", @"Vegetable oil", nil];
Recipe *recipe4 = [Recipe new];
recipe4.name = @"Hamburger";
recipe4.prepTime = @"30 min";
recipe4.imageFile = @"hamburger.jpg";
recipe4.ingredients = [NSArray arrayWithObjects:@"400g of ground beef", @"1/4 onion (minced)", @"1 tbsp butter", @"hamburger bun", @"1 teaspoon dry mustard", @"Salt and pepper", nil];
Recipe *recipe5 = [Recipe new];
recipe5.name = @"Ham and Egg Sandwich";
recipe5.prepTime = @"10 min";
recipe5.imageFile = @"ham_and_egg_sandwich.jpg";
recipe5.ingredients = [NSArray arrayWithObjects:@"1 unsliced loaf (1 pound) French bread", @"4 tablespoons butter", @"2 tablespoons mayonnaise", @"8 thin slices deli ham", @"1 large tomato, sliced", @"1 small onion", @"8 eggs", @"8 slices cheddar cheese", nil];
Recipe *recipe6 = [Recipe new];
recipe6.name = @"Creme Brelee";
recipe6.prepTime = @"1 hour";
recipe6.imageFile = @"creme_brelee.jpg";
recipe6.ingredients = [NSArray arrayWithObjects:@"1 quart heavy cream", @"1 vanilla bean, split and scraped", @"1 cup vanilla sugar", @"6 large egg yolks", @"2 quarts hot water", nil];
Recipe *recipe7 = [Recipe new];
recipe7.name = @"White Chocolate Donut";
recipe7.prepTime = @"45 min";
recipe7.imageFile = @"white_chocolate_donut.jpg";
recipe7.ingredients = [NSArray arrayWithObjects:@"3 1/4 cups flour", @"2 teaspoons baking powder", @"1/4 teaspoon salt", @"2 beaten eggs", @"2/3 cup sugar", @"2 ounces melted white chocolate", @"1/2 cup milk", nil];
Recipe *recipe8 = [Recipe new];
recipe8.name = @"White Chocolate Mocha";
recipe8.prepTime = @"5 min";
recipe8.imageFile = @"starbucks_coffee.jpg";
recipe8.ingredients = [NSArray arrayWithObjects:@"2/3 cup whole milk", @"6 tablespoons white chocolate chips", @"coffee", @"whipped cream", nil];
Recipe *recipe9 = [Recipe new];
recipe9.name = @"Vegetable Curry";
recipe9.prepTime = @"30 min";
recipe9.imageFile = @"vegetable_curry.jpg";
recipe9.ingredients = [NSArray arrayWithObjects:@"1 tablespoon olive oil", @"1 onion, chopped", @"2 cloves garlic", @"2 1/2 tablespoons curry powder", @"2 quarts hot water", nil];
Recipe *recipe10 = [Recipe new];
recipe10.name = @"Instant Noodle with Egg";
recipe10.prepTime = @"8 min";
recipe10.imageFile = @"instant_noodle_with_egg.jpg";
recipe10.ingredients = [NSArray arrayWithObjects:@"1 pack of Instant Noodle", @"2 eggs", nil];
Recipe *recipe11 = [Recipe new];
recipe11.name = @"Noodle with BBQ Pork";
recipe11.prepTime = @"20 min";
recipe11.imageFile = @"noodle_with_bbq_pork.jpg";
recipe11.ingredients = [NSArray arrayWithObjects:@"1 pack of Instant Noodle", @"BBQ pork", @"Salt and Pepper", nil];
Recipe *recipe12 = [Recipe new];
recipe12.name = @"Japanese Noodle with Pork";
recipe12.prepTime = @"20 min";
recipe12.imageFile = @"japanese_noodle_with_pork.jpg";
recipe12.ingredients = [NSArray arrayWithObjects:@"1 pack of Japanese Noodle", @"2 green onions", @"2 garlic cloves, minced", @"4 boneless pork loin chops", nil];
Recipe *recipe13 = [Recipe new];
recipe13.name = @"Green Tea";
recipe13.prepTime = @"5 min";
recipe13.imageFile = @"green_tea.jpg";
recipe13.ingredients = [NSArray arrayWithObjects:@"Green tea", nil];
Recipe *recipe14 = [Recipe new];
recipe14.name = @"Thai Shrimp Cake";
recipe14.prepTime = @"1.5 hours";
recipe14.imageFile = @"thai_shrimp_cake.jpg";
recipe14.ingredients = [NSArray arrayWithObjects:@"8 oz (250g) peeled and deveined raw shrimp", @"2 tablespoons red curry paste", @"1 large egg", @"2 teaspoon fish sauce", @"1 tablespoon sugar", @"2 tablespoons coconut milk", @"2 tablespoons roughly chopped Thai basil leaves", nil];
Recipe *recipe15 = [Recipe new];
recipe15.name = @"Angry Birds Cake";
recipe15.prepTime = @"4 hours";
recipe15.imageFile = @"angry_birds_cake.jpg";
recipe15.ingredients = [NSArray arrayWithObjects:@"12 tablespoons (1 1/2 sticks) unsalted butter", @"2 1/2 cups all-purpose flour", @"1 tablespoon baking powder", @"1 teaspoon salt", @"1 3/4 cups sugar", @"2 large eggs, plus 3 large egg yolks", @"1 cup of milk", nil];
Recipe *recipe16 = [Recipe new];
recipe16.name = @"Ham and Cheese Panini";
recipe16.prepTime = @"10 min";
recipe16.imageFile = @"ham_and_cheese_panini.jpg";
recipe16.ingredients = [NSArray arrayWithObjects:@"2 tablespoons unsalted butter", @"4 cups thinly sliced shallots", @"2 teaspoons fresh thyme", @"1/4 cup grainy Dijon mustard", @"8 slices rustic white bread", @"8 slices Gruyere cheese", @"8 ounces sliced cooked ham", nil];
recipes = [NSArray arrayWithObjects:recipe1, recipe2, recipe3, recipe4, recipe5, recipe6, recipe7, recipe8, recipe9, recipe10, recipe11, recipe12, recipe13, recipe14, recipe15, recipe16, nil];
}
#import <Foundation/Foundation.h>
@interface Recipe : NSObject
@property (nonatomic, strong) NSString *name; // name of recipe
@property (nonatomic, strong) NSString *prepTime; // preparation time
@property (nonatomic, strong) NSString *imageFile; // image filename of recipe
@property (nonatomic, strong) NSArray *ingredients; // ingredients
@end
#import "Recipe.h"
@implementation Recipe
@synthesize name;
@synthesize prepTime;
@synthesize imageFile;
@synthesize ingredients;
@end
最佳答案
由于所有属性都是属性列表对象(字符串和数组),因此可以将对象转换为字典数组。只需遍历食谱,并从每个对象创建一个字典:
NSMutableArray *recipeArray = [NSMutableArray new];
For (Recipe *obj in recipes) {
NSMutableDictionary *dict = [NSMutableDictionary new];
[dict setObject:obj.name forKey:@"name"];
[dict setObject:obj.prepTime forKey:@"prepTime"];
[dict setObject:obj.imageFile forKey:@"imageFile"];
[dict setObject:obj.ingredients forKey:@"ingredients"];
[recipeArray addObject:dict];
}
关于ios - 用plist替换NS对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20342942/
我只是在几个库中拆分了一个项目。 而且标题中出现了奇怪的错误。 我无法解释自己为什么会这样。 此外,此错误过去仅在FSI.exe中显示 我以为这是因为pb在fsi中加载了dll,但是还有更多。 这可能
我将 Android Studio 更新到 4.2.1 并删除了 jcentor。我在构建项目时收到了这样的警告。我不明白这些 URL 的含义以及如何修复它 映射新 ns http://schemas
在 DNS 响应消息中,我对出现在 Answer Section(包含由 ANCOUNT 编号引用的记录的部分)中的 NS 记录之间的差异感到困惑, 以及出现在 Authority Section 中
我有两个命名空间:第一个是 clojuresque java 中的 gui,第二个是常规 clojure 中的 gui。用户在 gui 中输入值;这些需要在非 gui ns 中“传递”到“设置”值。我
我在这里有一些代码可以使用 python 中的回溯解决 n 个皇后问题。当我运行它时,赔率总是比偶数花费的时间少得多。当 n 达到 20+ 左右时,这一点尤其明显。有人知道为什么是这样吗? impor
因此,我正在使用 Flutter 并在运行应用程序时,在调试控制台中收到如下错误: Warning: Mapping new ns http://schemas.android.com/reposit
当我尝试运行应用程序或重新构建它时,出现以下错误。 (我正在尝试在新的 Android Studio 和 SDK 中运行或重建旧项目) 警告:映射新 ns http://schemas.android
我有一个名为 query_df 的数据框,其中一些列属于 datetime[ns] 数据类型。 我想一次将所有 datetime[ns] 转换为 datetime[ns, UTC]。 到目前为止,这是
我注意到,一些服务提供商正在为其客户的域运行 DNS 服务,其中为该区域设置了 NS 名称,并由权威名称服务器返回(在权限部分/NS 和 SOA 记录中),这些名称与上游服务器(例如 TLD 服务器)
我正在研究 Karatsuba 数字乘法算法的实现,但与大多数使用字符串而不是 BigNumber 或 long 的实现不同。我已经为该问题编写了一个递归解决方案,该解决方案似乎适用于所有 n < 6
我在 Route 53 上注册了一个域。该域指向旧 Route53 路由的一些名称服务器。我现在正在构建我的 Terraform 脚本来创建一个新的 Route53 区域。创建时是否可以设置名称服务器
我想从 dataframe data 读取两列 S1_max 和 S2_max。无论 S1_max 列中存在值,我都想检查每个 S1_max 后面是否有相应的 S2_max 信号。如果是这样,我计算
我正在尝试通过以下方式获取 ns-3-dev 版本: [root@localhost ns-3-allinone]# ./download.py -n ns-3-dev # # Get NS-3 #
我在 pandas 中创建了一个 TimeSeries: In [346]: from datetime import datetime In [347]: dates = [datetime(201
我正在尝试访问 XML http://webservices.ns.nl/ns-api-stations使用 ASIHTTPRequest。但是我现在用的好像不行。它说无法访问主机。所以我假设它在 A
我正在尝试将 mp-olsr(ns 2.29) 添加到 ns 2.34 中,并且在编译时遇到了一些错误。 源代码(甲子乙):http://www.jiaziyi.com/index.php/resea
为什么ns(0.8)或ns(c(0.8))返回NA/NaN/Inf in foreign function call (arg 1) ? ns(c(0.8, 1.0))工作正常,但我想知道为什么只给
我正在创建一个PySpark 3.4.1应用程序在与Python3.11.5对接开发,它应该能够连接到多种类型的数据库通过JDBC连接。我正在测试与本地Oracle数据库的连接,该数据库是我在另一个容
我正在创建一个PySpark 3.4.1应用程序在与Python3.11.5对接开发,它应该能够连接到多种类型的数据库通过JDBC连接。我正在测试与本地Oracle数据库的连接,该数据库是我在另一个容
来自 dns newb 的两个问题: 子域是否可以使用与其父域不同的一组名称服务器? 例如:abc.ca 使用 ns.whatever.com 和 ns2.whatever.com,而 sub.abc
我是一名优秀的程序员,十分优秀!