verify input parameter of init method and return nil before invoke [super init]

2013-01-29 Thread Bob Cromwell
Hi All,

if below code valid ?   All sample codes I could find invoke self = [super 
init] first and then check the input parameter inside if (self) block.  

@implementaion Bla

- (id)initWithFoo:(NSString *)foo
{
if (foo == nil) {
return nil;
}
self = [super init];
if (self) {
_foo = foo;
.
}
return self;
}

I had thought there would be memory leak.   Bla * b =  [Bla alloc ] 
initWithFoo:nil]; .  However under ARC using Instruments Leaks, there are no 
leak found. 

Thanks in advance!

Bob Cromwell

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Questions about CoreData and object graphs

2012-11-14 Thread Bob Cromwell

Actually your guess is wrong.  Core Data could handle this by turn the object 
to fault.  Have a look at the method refreshObject:mergeChanges.


Bob Cromwell

On 2012-11-15, at 上午10:30, William Squires wrote:

 1) Can CoreData properly manage an object graph where the objects form a 
 circular reference (i.e.)
 
 Entity Node
  int nodeType
  Node onTopOf // 1:1 relationship to another Node entity
  Node under // another 1:1 relationship
 End
 
 This would be a doubly-linked list in a circular queue so that you could go 
 either direction from any Node entity. My guess is… no.
 
 2) Without CoreData, if I simply declare in my model classes that they 
 implement NSCoding (and I implement all the initWithCoder: and 
 encodeWithCoder: methods), will this properly handle such a situation (i.e. a 
 possibly circular object graph)?
 
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 https://lists.apple.com/mailman/options/cocoa-dev/bob.cromwell2012%40gmail.com
 
 This email sent to bob.cromwell2...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Core Data : Batch Faulting while take advantage of cache

2012-11-13 Thread Bob Cromwell
Hi there,

In Core Data Programming Guide  Apple recommend a way to batch fire fault a 
collection of objects,  It should be implemented as below:
 
  NSArray * arrayOfFaults = [NSArray arrayWithObjects:object1,object2,nil];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@self IN %@, 
arrayOfFaults];
  NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] 
initWithEntityName:@Foo];
  [fetchRequest setPredicate:predicate];
  [fetchRequest setReturnsObjectsAsFaults:NO];
  [managedObjectContext executeFetchRequest:fetchRequest error:NULL];

However using Core Data Instrument on iOS 6 simulator,  I found this fetch 
almost as same time as other fetch. In other words, it goes to disk and did not 
use the cache. It's unreasonable .  Since it's an  IN  clause , Core Data 
could use the objectID to find object in cache. There are no need to go to the 
disk if all of them could be found in cache.

I am pretty sure these objects in arrayOfFaults are in cache.  If I replace 
above code with this one, not cache miss are reported:

   for (NSManagedObject *object in arrayOfFaults){
   [object willAccessValueForKey:nil];
   }

So my question is : are there any way to batch fault objects while take 
advantage of the cache ? 

Bob Cromwell

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Core Data fetch performance

2012-11-12 Thread Bob Cromwell
Hi Hunter,

I am very interested in what  bugs they fixed.  Could you please share more 
about it , e.g.  an official bug fix report ?  

Thanks

Bob

 The API changes came in iOS 5 but in iOS 6 they fixed enough bugs to make it 
 work right. :-)

 On Nov 11, 2012, at 4:50 PM, Rick Mann rm...@latencyzero.com wrote:
 
 GCD, along with the Core Data changes in iOS 5 and 6 for handling 
 concurrency, make this much easier than it used to be (or at least cleaner 
 and harder to screw up as badly).
 
 By the way, what were the changes in iOS 6? I can't find specific Core Data 
 notes for iOS 6, only iOS 5. Thanks!
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 https://lists.apple.com/mailman/options/cocoa-dev/bob.cromwell2012%40gmail.com
 
 This email sent to bob.cromwell2...@gmail.com


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: ARC issue

2012-11-07 Thread Bob Cromwell
According to ARC documentation,  out parameter will be changed to auto release 
one:

NSError ** error  will be auto changed to  NSError * __autorelease * error.

So It's expected behavior that crash happens.  An article about this here 
http://blog.pioneeringsoftware.co.uk/2012/03/06/out-parameters-when-arcing

On 2012-11-7, at 下午9:05, Andreas Grosam wrote:

 Xcode 4.5.1, ARC enabled.
 
 I've this C++ member function, for a testing environment (gtest):
 
 
 NSDictionary* fetchUser(NSNumber* ID, NSError** error)
 {
id user = nil;
//@autoreleasepool   // crashes when @autoreleasepool is enabled
{
id data = ...; // response body of a HTTP Response (NSData) or NSError 
 object, never nil.
if ([data isKindOfClass:[NSData class]]) {
user = [NSJSONSerialization JSONObjectWithData:data
  options:0
error:error];
}
else if (error) {
*error = data;
}
} // autoreleasepool
return user;
 }
 
 
 
 The problem here is, if the autorelease pool is **enabled**, I get a crash in 
 the caller's code:
NSError* err = nil;
NSDictionary* deletedUser = this-fetchUser(userID, err);
EXPECT_TRUE(deletedUser == nil);== the crash occurs 
 **before** this statement, but **after** the return statement of the function 
 fetch user.
 
 The debugger does not show a stack frame to confirm this, though.
 
   libobjc.A.dylib`objc_msgSend:
   0x7fff86b2fe80:  testq  %rdi, %rdi
   0x7fff86b2fe83:  je 0x7fff86b2feb0; objc_msgSend + 48
   0x7fff86b2fe85:  testb  $1, %dil
   0x7fff86b2fe89:  jne0x7fff86b2fec7; objc_msgSend + 71
   0x7fff86b2fe8c:  movq   (%rdi), %r11  
   0x7fff86b2fe8f:  pushq  %rax
 ==   0x7fff86b2fe90:  movq   16(%r11), %r10  // Thread 1: 
 EXC_BAD_ACCESS (code=13, address=0x0)
   0x7fff86b2fe94:  movl   %esi, %eax
   0x7fff86b2fe96:  andl   (%r10), %eax
   0x7fff86b2fe99:  movq   16(%r10,%rax,8), %r11
   0x7fff86b2fe9e:  incl   %eax
   0x7fff86b2fea0:  testq  %r11, %r11
   0x7fff86b2fea3:  je 0x7fff86b2fedb; objc_msgSend + 91
...
 
 There is no stack frame.
 
 
 This has something to do with the error parameter. If I pass nil for the 
 error parameter, the crash does not occur anymore.
 
 
 Any hints?
 
 
 Thanks in advance!
 
 Andreas
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 Please do not post admin requests or moderator comments to the list.
 Contact the moderators at cocoa-dev-admins(at)lists.apple.com
 
 Help/Unsubscribe/Update your Subscription:
 https://lists.apple.com/mailman/options/cocoa-dev/bob.cromwell2012%40gmail.com
 
 This email sent to bob.cromwell2...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com