gpt4 book ai didi

ios - 分配给 'NSArray' 到 'NSString' 的不兼容指针类型

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:41:23 27 4
gpt4 key购买 nike

RecipeBookViewController.m 文件在 Xcode 中显示警告“分配给‘NSArray’到‘NSString’的指针类型不兼容

谁能修复这个警告。

我正在从教程 Tutorial #14 的 appcoda 网站开发 RecipeBook 应用程序

这是我的 Recipe.h 文件

#import <Foundation/Foundation.h>

@interface Recipe : NSObject

@property (strong, nonatomic) NSString *name;
@property (strong, nonatomic) NSString *prepTime;
@property (strong, nonatomic) NSString *imageFile;
@property (strong, nonatomic) NSString *ingredients;

@end

这是我的 Recipe.m 文件

#import "Recipe.h"

@implementation Recipe
@synthesize name,prepTime,imageFile,ingredients;

@end

这是我的 RecipeBookViewController.m 文件

#import "RecipeBookViewController.h"
#import "RecipeDetailViewController.h"
#import "Recipe.h"

@interface RecipeBookViewController ()

@end

@implementation RecipeBookViewController

- (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];
}

最佳答案

问题是配料是一个NSString,即

@property (strong, nonatomic) NSString *ingredients;

但是,正如错误所述,您正在尝试将数组分配给 NSString,即

recipe1.ingredients = [NSArray arrayWithObjects:@"2 fresh English muffins", @"4 eggs",...

因此您可以将成分更改为 NSArray 以更正此错误,例如:

@property (strong, nonatomic) NSArray *ingredients;

关于ios - 分配给 'NSArray' 到 'NSString' 的不兼容指针类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28513317/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com