0
我想學習目標C的Realm模型。我想知道如何創建我們自己的.realm文件並在領域瀏覽器中查看領域文件。以下是我的代碼。如何創建我自己的領域模型?
-In Specimen.h
#import <Foundation/Foundation.h>
#import <Realm/Realm.h>
@interface Specimen : RLMObject//: NSObject
@property NSString *name;
@property NSString *specDescription;
@property NSInteger latitude;
@property NSInteger longitude;
@property NSDate *date;
@end
-In UIViewController.m
#import "ViewController.h"
#import "Specimen.h"
@interface ViewController()
{
Specimen *first;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
first = [[Specimen alloc] init];
first.name = @"first specimen";
first.specDescription = @"some description";
first.latitude = 12;
first.longitude = 15;
first.date = [NSDate date];
RLMRealm *realm = [RLMRealm defaultRealm];
[realm transactionWithBlock:^{
[realm addObject:first];
}];
NSLog(@"Object added in realm");
}
構建得到成功。最後一個日誌也顯示在控制檯上。但我不明白在哪裏可以看到Specimen對象,因爲默認域總是隻有人和狗對象。 所以我需要知道如何創建我自己的領域,然後添加對象並通過領域瀏覽器訪問它。
謝謝!:)會試試這個。 – pz26