forked from bububa/MongoHub-Mac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConnectionsArrayController.m
63 lines (54 loc) · 1.54 KB
/
ConnectionsArrayController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// DatabasesArrayController.m
// MongoHub
//
// Created by Syd on 10-4-24.
// Copyright 2010 MusicPeace.ORG. All rights reserved.
//
#import "ConnectionsArrayController.h"
@implementation ConnectionsArrayController
- (void)awakeFromNib
{
if ([NSArrayController instancesRespondToSelector:@selector(awakeFromNib)])
{
[super awakeFromNib];
}
[self setClearsFilterPredicateOnInsertion:NO];
}
- (id)newObject
{
id newObj = [super newObject];
//NSDate *now = [NSDate date];
//[newObj setValue:now forKey:@"createdDatetime"];
return newObj;
}
- (void)remove:(id)sender
{
if (![self selectedObjects]){
return;
}
[super remove:sender];
}
- (BOOL)checkDuplicate:(NSString *)alias
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"alias=%@", alias];
if ([[self itemsUsingFetchPredicate:predicate] count]>0) {
return YES;
}else {
return NO;
}
}
- (NSArray *)itemsUsingFetchPredicate:(NSPredicate *)fetchPredicate
{
NSError *error = nil;
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:[NSEntityDescription entityForName:[self entityName]
inManagedObjectContext:[self managedObjectContext]]];
NSArray *objects = [[self managedObjectContext]
executeFetchRequest:request error:&error];
if (error) {
NSLog(@"Fetch error! In AWViewPositionArrayController:itemsUseingFetchPredicate");
}
return [objects filteredArrayUsingPredicate:fetchPredicate];
}
@end