1

これは私を夢中にさせています。単純なものだと思いますが、リモート PLIST をダウンロードして、それを使用してアプリ内の構成を駆動しようとするのは素晴らしいことです....

取得

IMProductsDataSource.m:57:11: エラー: 予想される識別子または '('
NSURL = *remoteURL = [NSURL URLWithString:@"IOS/"];
^
IMProductsDataSource.m:58:94: エラー: 宣言されていない識別子 'remoteURL' の使用
NSMutableDictionary *remoteDictionary = [NSMutableDictionary dictionaryWithContentsOfURL:remoteURL];
^
2 つのエラーが生成されました。

どんな助けでも素晴らしいでしょう...

.H

#import <Foundation/Foundation.h>


@class ProductItem;

@interface IMProductsDataSource : NSObject

@property (nonatomic, strong) NSMutableArray* productsList;

@property (nonatomic, strong) ProductItem *selectedProduct;




+ (IMProductsDataSource *)sharedInstance;

@end

.M

#import "IMProductsDataSource.h"
#import "ProductItem.h"
#import "AppConstants.h"

@interface IMProductsDataSource ()


@property(nonatomic, assign) NSInteger currentRegion;

@end



@implementation IMProductsDataSource


+ (IMProductsDataSource *)sharedInstance
{
    static IMProductsDataSource *instance = nil;
    @synchronized(self) {
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            instance = [[IMProductsDataSource alloc] init];
        });
    }
    return instance;
}

-(id)init
{
    if (self = [super init])
    {
        self.productsList = [[NSMutableArray alloc] init];
        self.currentRegion = REGIONUK;
        [self loadProducts];
    }

    return self;
}


-(void)loadProducts {

    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *dir = [path objectAtIndex:0];
    NSString *filePath = [dir stringByAppendingPathComponent:@"Region1Products.plist"];

    NSMutableDictionary *localDictionary;
    NSURL = *remoteURL = [NSURL URLWithString:@"http://URL/IOS/"];
    NSMutableDictionary *remoteDictionary = [NSMutableDictionary dictionaryWithContentsOfURL:remoteURL];
    if(remoteDictionary != nil) {
        [remoteDictionary writeToFile:filePath atomically:YES];
        localDictionary = remoteDictionary;
    }
    else {
        localDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
        if(localDictionary == nil) localDictionary = [NSMutableDictionary dictionary];
    }



//  NSString *plistName = [NSString stringWithFormat:@"Region%dProducts", self.currentRegion];

 // NSString *dataSourceFile = [[NSBundle mainBundle] pathForResource:
   //                                                      ofType:@"plist"];

 // NSArray* productsItems = [NSArray arrayWithContentsOfURL:[NSURL fileURLWithPath:filePath]];

   NSArray* productsItems =  [NSMutableDictionary dictionaryWithContentsOfFile:filePath];


    for (NSDictionary* productDictionary in productsItems) {
        ProductItem* productItem = [[ProductItem alloc] init];

        productItem.picturesCount = [productDictionary objectForKey:@"PicturesCount"];
        productItem.maxPicturesCount = [productDictionary objectForKey:@"MaxPicturesCount"];
        productItem.size = [productDictionary objectForKey:@"Size"];
        productItem.previewImageName = [productDictionary objectForKey:@"ImageName"];
        productItem.sequence = [productDictionary objectForKey:@"Sequence"];
        productItem.productName = [productDictionary objectForKey:@"Name"];
        productItem.type = [productDictionary objectForKey:@"ProductType"];
        productItem.prices = [productDictionary objectForKey:@"Prices"];
        productItem.shippingPrices = [productDictionary objectForKey:@"ShippingPrices"];
        productItem.description = [productDictionary objectForKey:@"Description"];
        productItem.popupMessage = [productDictionary objectForKey:@"PopupMessage"];
        productItem.popupDetailMessage = [productDictionary objectForKey:@"PopupDetailMessage"];
        productItem.incrementalPricing = [[productDictionary objectForKey:@"IncrementalPricing"] boolValue];
        if (YES == productItem.incrementalPricing) {
            productItem.incrementalPrices = [productDictionary objectForKey:@"IncrementalPrices"];
        }

        NSArray *previewItems = [productDictionary objectForKey:@"PreviewItems"];
        for (NSDictionary* previewItem in previewItems) {
            [productItem addProductPreviewItemFromDictionary:previewItem];
        }

        [self.productsList addObject:productItem];
    }

    NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"sequence" ascending:YES];
    self.productsList = [NSMutableArray arrayWithArray:[self.productsList sortedArrayUsingDescriptors:[NSArray arrayWithObject:sort]]];
}

@end
4

2 に答える 2

2

変数宣言が正しくありません:

NSURL = *remoteURL = [NSURL URLWithString:@"http://URL/IOS/"];

次のようにする必要があります。

NSURL *remoteURL = [NSURL URLWithString:@"http://URL/IOS/"];

余分な等号があり、その後NSURLに構文エラーが発生していることに注意してください。

于 2013-05-24T18:03:54.287 に答える
0

これは単純な構文エラーです。あなたのコードのこの行は有効ではありません Objective-C:

NSURL = *remoteURL = [NSURL URLWithString:@"http://URL/IOS/"];

最初の=.

于 2013-05-24T18:04:05.037 に答える