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 回答