要运行示例项目,请先克隆仓库,并在 Example 目录中先运行 pod install
。
ASNRealm 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'ASNRealm'
@property int productId; @property NSString *title; @property NSString *descriptions; @property RLMArray *images; @property RLMArray *prices; @property RLMArray *stocks; @property RLMArray *variants; @property BOOL wishlist;
RLMResults <0x7f94b8f6f990> (
[0] Product {
productId = 7;
title = title2;
descriptions = desc2;
images = RLMArray <0x7f94b8f74c90> (
[0] Image {
image = http://proprofs-cdn.s3.amazonaws.com/images/games/user_images/misc/1141652403.png;
productIdImage = 7;
},
[1] Image {
image = https://pixabay.com/static/uploads/photo/2013/08/11/19/37/flower-171644_960_720.jpg;
productIdImage = 7;
}
);
prices = RLMArray <0x7f94b8f75ed0> (
[0] Price {
price = 140;
productIdPrice = 7;
},
[1] Price {
price = 150;
productIdPrice = 7;
}
);
stocks = RLMArray <0x7f94b8f76970> (
[0] Stock {
stock = 15;
productIdStock = 7;
},
[1] Stock {
stock = 25;
productIdStock = 7;
}
);
variants = RLMArray <0x7f94b8f75c90> (
[0] Variant {
variant = red;
productIdVariant = 7;
},
[1] Variant {
variant = black;
productIdVariant = 7;
}
);
wishlist = 0;
}
#import <ASNRealm/Product.h>
属性排序是属性名
RLMResults *result = [product getAllProductWithPropertyForSort:@"productId" withAscending:YES];
NSLog(@"result: %@",result);
Product *product = [[Product alloc]init];
RLMResults *result = [product getAllProductWithPropertyForSort:@"productId" withAscending:YES];
NSLog(@"result %lu: %@",(unsigned long)result.count,result);
Product *productAtIndex = [result objectAtIndex:1];
NSLog(@"title : %@:",productAtIndex.title);
NSLog(@"descriptions : %@:",productAtIndex.descriptions);
NSArray *getImages = [product getImagesByProductObject:productAtIndex];
NSArray *getStocks= [product getStockByProductObject:productAtIndex];
NSArray *getPrices= [product getPriceByProductObject:productAtIndex];
NSArray *getVariant= [product getVariantByProductObject:productAtIndex];
NSLog(@"images : %@",getImages);
NSLog(@"stocks : %@",getStocks);
NSLog(@"price : %@",getPrices);
NSLog(@"variant : %@",getVariant);
Product *product = [[Product alloc]init];
RLMResults *result = [product searchProductWithKeyword:@"Chunky Heels"];
NSLog(@"result: %@",result);
Product *product = [[Product alloc]init];
RLMResults *result = [product getProdutById:10];
NSLog(@"result: %@",result);
首先定义图像、价格、库存和变体的数组
NSArray *images = @[@"http://proprofs-cdn.s3.amazonaws.com/images/games/user_images/misc/1141652403.png", @"https://pixabay.com/static/uploads/photo/2013/08/11/19/37/flower-171644_960_720.jpg"];
NSArray *prices = @[@140.0, @150.0];
NSArray *stocks = @[@"15", @"25"];
NSArray *variants = @[@"red", @"black", @"blue"];
从产品类创建对象
Product *product = [[Product alloc]init];
使用默认的 wishlist(false)值创建产品
[product createDefaultProductWithId:7 withTitle:@"Croco Bag" andDescriptions:@"Nice handbag for women" andImages:images andPrices:prices andStocks:stocks andVariants:variants];
使用自定义的 wishlist(false/true)值创建产品 YES:true,NO:false
[product createProductWithId:10 withTitle:@"Chelsea Chunky Heels Boot" andDescriptions:@"Stylist boot for this winter" andImages:images andPrices:prices andStocks:stocks andVariants:variants andWishlist:YES];
Product *product = [[Product alloc]init];
[product deleteProductWithProductId:7];
Product *product = [[Product alloc]init];
RLMResults *result = [product getAllWishlistWithPropertyForSort:@"productId" withAscending:YES];
NSLog(@"result: %@",result);
Product *product = [[Product alloc]init];
[product addProductToWishlist:10];
Product *product = [[Product alloc]init];
[product removeProductFromWishlist:5];
Product *product = [[Product alloc]init];
[product emptyWishlist];
Product *product = [[Product alloc]init];
[product emptyProduct];
首先定义图像、价格、库存和变体的数组
NSArray *images = @[@"http://proprofs-cdn.s3.amazonaws.com/images/games/user_images/misc/1141652403.png", @"https://pixabay.com/static/uploads/photo/2013/08/11/19/37/flower-171644_960_720.jpg"];
NSArray *prices = @[@80.0, @50.0, @70];
NSArray *stocks = @[@"10", @"5"];
NSArray *variants = @[@"red", @"black", @"blue"];
从产品类创建对象
Product *product = [[Product alloc]init];
编辑产品
[product editProductWithId:7 withTitle:@"Croco Bag Sale!" andDescriptions:@"Now favorite item on SALE" andImages:images andPrices:prices andStocks:stocks andVariants:variants andWishlist:YES];
Annisa Sofia Noviantina, [email protected]