这让我发疯,认为这是一个简单的,但任何帮助都会很棒,尝试下载远程 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