Re: NSTableView automatic column size

2014-07-02 Thread Varun Chandramohan
Thanks Ken, I was missing constrains that was causing the issue. I see the
document states that Xcode will not complain if there are not enough
constrains. It would have helped of it did. I didn¹t realise the problem
was constrains. Do you know why this behaviour and if possible someway to
enable Xcode from throwing up warning at least?

Regards,
Varun






On 2/07/2014 1:59 pm, "Ken Thomases"  wrote:

>On Jul 1, 2014, at 6:46 PM, Varun Chandramohan wrote:
>
>> I have a NSTableView (View based) with 8 NSTableColumn each of which
>>has NSTableCellView as default built from IB. I followed apple guide
>>https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Ta
>>bleView/Introduction/Introduction.html#//apple_ref/doc/uid/1026i-CH1-
>>SW1 and populated the table programatically as specified in the guide.
>>This seem to work properly. I noticed that one or more columns are
>>populated with strings that are large and so the view seem to cut them
>>off with "Blah..." which  is understandable. However when I resize the
>>that column to see the rest of the string I only see "Blah...". Its as
>>if only a part of the string was populated into the NSTextField as part
>>of NSTableCellView. I did not find any information on this in the guide.
>>Any pointers? I would have expected this to be the default behaviour.
>
>The table view will change the width of the cell view.  However, you're
>responsible for configuring the text field within the cell view so that
>it changes width with the cell view.  You would do that with either
>autoresizing masks or autolayout, depending on which you're using.
>
>Regards,
>Ken
>


___

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

NSTableView automatic column size

2014-07-01 Thread Varun Chandramohan
Hi All,

I have a NSTableView (View based) with 8 NSTableColumn each of which has 
NSTableCellView as default built from IB. I followed apple guide 
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/TableView/Introduction/Introduction.html#//apple_ref/doc/uid/1026i-CH1-SW1
 and populated the table programatically as specified in the guide. This seem 
to work properly. I noticed that one or more columns are populated with strings 
that are large and so the view seem to cut them off with "Blah..." which  is 
understandable. However when I resize the that column to see the rest of the 
string I only see "Blah...". Its as if only a part of the string was populated 
into the NSTextField as part of NSTableCellView. I did not find any information 
on this in the guide. Any pointers? I would have expected this to be the 
default behaviour.

Regards,
Varun
___

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: NSReleasePool issue

2014-06-24 Thread Varun Chandramohan
Hi All,

Apple has notified that this a known bug and they have a duplicate of the bug I 
submitted regarding this issue. They closed my bug. I am not sure if bug 
numbers will benefit anyone in this forum, if so let me know ill post it.

Regards,
Varun

From: Jens Alfke mailto:j...@mooseyard.com>>
Date: Sunday, 22 June 2014 5:24 am
To: Kyle Sluder mailto:k...@ksluder.com>>
Cc: Development 
mailto:varun.chandramo...@wontok.com>>, 
Cocoa-Dev List mailto:Cocoa-dev@lists.apple.com>>
Subject: Re: NSReleasePool issue


On Jun 21, 2014, at 11:16 AM, Kyle Sluder 
mailto:k...@ksluder.com>> wrote:

The pool will never be drained, because NSApplicationMain never returns. There 
is no wasted work here.

But it's still true that any object autoreleased into that pool is effectively 
leaked. It just won't be visible as such to the 'leaks' tool or Instruments, 
because technically that outer autorelease pool still has a reference to it. 
Nor will you be able to get that warning about an object being autoreleased 
without a pool, which is another way to catch such a leak. So it seems that all 
this does is hide potential leaks from you.

NSApplicationMain needs to interact with user defaults in order to parse the 
command line. It's kind of unreasonable to expect Apple to eschew -autorelease 
in all code that can be called during startup.

Any code that runs at startup that uses autorelease should create its own 
temporary autorelease pool. There's apparently one such routine that doesn't: 
that's the actual bug here, and as I said, it should be reported to Apple.

-Jens

___

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

NSTableHeaderView split

2014-06-23 Thread Varun Chandramohan
Hi All,

Is there ant simple to have a split header view to generalise sub header? Here 
is an example of what I want to achieve using NSTableHeaderView?

---
|header 1  |  Common Header Txt   |
|  | 
-
|  |   header 2 |   header 3 | header 4| header 5  |

|   row 1| || | 
  |


Is there any other way to do the same?

Regards,
Varun
___

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: NSReleasePool issue

2014-06-22 Thread Varun Chandramohan
I agree on the fact that if the auto pool is introduced in main then its going 
to mask all the leaks in other parts of the code leading to unknown memory 
leaks. I see a divided option on this, but in OSX world this should be taken 
care by OS itself. Perhaps I will report this to Apple and see what they have 
to say. Does anyone know where to report the issue?

Regards,
Varun

From: Jens Alfke mailto:j...@mooseyard.com>>
Date: Sunday, 22 June 2014 5:24 am
To: Kyle Sluder mailto:k...@ksluder.com>>
Cc: Development 
mailto:varun.chandramo...@wontok.com>>, 
Cocoa-Dev List mailto:Cocoa-dev@lists.apple.com>>
Subject: Re: NSReleasePool issue


On Jun 21, 2014, at 11:16 AM, Kyle Sluder 
mailto:k...@ksluder.com>> wrote:

The pool will never be drained, because NSApplicationMain never returns. There 
is no wasted work here.

But it's still true that any object autoreleased into that pool is effectively 
leaked. It just won't be visible as such to the 'leaks' tool or Instruments, 
because technically that outer autorelease pool still has a reference to it. 
Nor will you be able to get that warning about an object being autoreleased 
without a pool, which is another way to catch such a leak. So it seems that all 
this does is hide potential leaks from you.

NSApplicationMain needs to interact with user defaults in order to parse the 
command line. It's kind of unreasonable to expect Apple to eschew -autorelease 
in all code that can be called during startup.

Any code that runs at startup that uses autorelease should create its own 
temporary autorelease pool. There's apparently one such routine that doesn't: 
that's the actual bug here, and as I said, it should be reported to Apple.

-Jens

___

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: NSReleasePool issue

2014-06-21 Thread Varun Chandramohan
This is OS X not iOS. Yes main look like what is shown below without the 
autoreleasepool.

From: Sean McBride 
Sent: Saturday, June 21, 2014 2:39 AM
To: Steve Christensen; Varun Chandramohan
Cc: Cocoa-Dev List
Subject: Re: NSReleasePool issue

Given the backtrace, I'd say the OP is using Mac OS, not iOS.  I just created a 
new project in Xcode, and main() looks like this on OS X:

int main(int argc, const char * argv[])
{
return NSApplicationMain(argc, argv);
}


On Fri, 20 Jun 2014 09:32:48 -0700, Steve Christensen said:

>My main() looks like this. Does yours specify an autorelease pool?
>
>int main(int argc, char* argv[])
>{
>   @autoreleasepool
>   {
>   return UIApplicationMain(argc, argv, nil, 
> @"MyDelegateClassName");
>   }
>}
>
>
>On Jun 19, 2014, at 5:45 PM, Varun Chandramohan
> wrote:
>
>> I was playing around with OBJ_DEBUG_MISSING_POOL env variable and set
>it to YES. I was able to debug most of the issues in my code where I
>missed auto release pools. This is the last one remaining. However I am
>not sure where the leak is happening. It looks like NSApplicationMain,
>do that also need this auto release pool?
>>
>> objc[26109]: MISSING POOLS: Object 0x618410e0 of class
>NSUserDefaults autoreleased with no pool in place - just leaking - break
>on objc_autoreleaseNoPool() to debug
>>
>> (lldb) bt
>>
>> * thread #1: tid = 0x3d3c5f, 0x7fff91da8604
>libobjc.A.dylib`objc_autoreleaseNoPool, queue = 'com.apple.main-thread',
>stop reason = breakpoint 1.1
>>frame #0: 0x7fff91da8604 libobjc.A.dylib`objc_autoreleaseNoPool
>>frame #1: 0x7fff91d95488 libobjc.A.dylib`(anonymous
>namespace)::AutoreleasePoolPage::autoreleaseSlow(objc_object*) + 72
>>frame #2: 0x7fff91da8781 lib
>objc.A.dylib`_objc_rootAutorelease2(objc_object*) + 75
>>frame #3: 0x7fff895528a3 AppKit`_NSGetBoolAppConfig + 85
>>frame #4: 0x7fff89571566 AppKit`-[NSApplication
>_installMemoryPressureDispatchSources] + 161
>>frame #5: 0x7fff89565861 AppKit`-[NSApplication run] + 206
>>frame #6: 0x7fff895507a3 AppKit`NSApplicationMain + 940
>>  * frame #7: 0x00012022 TOS`main(argc=3,
>argv=0x7fff5fbffa90) + 34 at main.m:13



___

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

NSReleasePool issue

2014-06-19 Thread Varun Chandramohan
Hi All,

I was playing around with OBJ_DEBUG_MISSING_POOL env variable and set it to 
YES. I was able to debug most of the issues in my code where I missed auto 
release pools. This is the last one remaining. However I am not sure where the 
leak is happening. It looks like NSApplicationMain, do that also need this auto 
release pool?


objc[26109]: MISSING POOLS: Object 0x618410e0 of class NSUserDefaults 
autoreleased with no pool in place - just leaking - break on 
objc_autoreleaseNoPool() to debug

(lldb) bt

* thread #1: tid = 0x3d3c5f, 0x7fff91da8604 
libobjc.A.dylib`objc_autoreleaseNoPool, queue = 'com.apple.main-thread', stop 
reason = breakpoint 1.1

frame #0: 0x7fff91da8604 libobjc.A.dylib`objc_autoreleaseNoPool

frame #1: 0x7fff91d95488 libobjc.A.dylib`(anonymous 
namespace)::AutoreleasePoolPage::autoreleaseSlow(objc_object*) + 72

frame #2: 0x7fff91da8781 
libobjc.A.dylib`_objc_rootAutorelease2(objc_object*) + 75

frame #3: 0x7fff895528a3 AppKit`_NSGetBoolAppConfig + 85

frame #4: 0x7fff89571566 AppKit`-[NSApplication 
_installMemoryPressureDispatchSources] + 161

frame #5: 0x7fff89565861 AppKit`-[NSApplication run] + 206

frame #6: 0x7fff895507a3 AppKit`NSApplicationMain + 940

  * frame #7: 0x00012022 TOS`main(argc=3, argv=0x7fff5fbffa90) + 34 
at main.m:13

(lldb) c



Regards,
Varun
___

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: Question on NSTableViewDataSource Protocol

2014-05-18 Thread Varun Chandramohan
Interesting, so lets say I avoid [_tableContents removeAllObjects] but I
have to change the data source, may be add new entry or remove 1 entry.
What will be the difference between removing 1 entry and all
entry(objects) from the source? I mean, what can I do to remove an entry
which may be a valid row in table code? Could I do something like this
before removing the objects? [ltableView removeRowsAtIndexes:indexes
withAnimation:NSTableViewAnimationSlideDown];

Regards,
Varun

On 16/05/2014 4:45 pm, "Graham Cox"  wrote:

>
>On 16 May 2014, at 11:18 am, Varun Chandramohan
> wrote:
>
>> [_tableContents removeAllObjects];
>
>
>I wouldn't do this, because it invalidates the value of 'row', which may
>be assumed by the table code to remain valid. Implementation details may
>change on different systems, and so this might be OK on 10.9, but fail on
>earlier. The assertion seems definitely to do with an invalid row index.
>
>--Graham
>
>


___

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

Question on NSTableViewDataSource Protocol

2014-05-15 Thread Varun Chandramohan
Hi All,

I was playing around with dragging items into NSTableView and I ran into a 
interesting problem. When I drag an item into my table, the following delegate 
gets called.


- (BOOL)tableView:(NSTableView *)tableView acceptDrop:(id)info 
row:(NSInteger)row dropOperation:(NSTableViewDropOperation)dropOperation {

[self performInsertWithDragInfo:info row:row];

return YES;

}

Since I am returning YES, we are accepting this drop. In 
"performInsertWithDragInfo", I have a requirement to save the new add into a 
file and then parse through NSArray which is my data source and might make some 
modifications. After the modifications, I reload the datasource and repopulate 
the tableview.


[_tableContents removeAllObjects];

for (NSString *fileStr in filtered) {

NSURL *fileURL = [NSURL URLWithString:[fileStr 
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

DesktopEntity *entity = [DesktopEntity entityForURL:fileURL];

if ([entity isKindOfClass:[DesktopEntity class]])

[_tableContents addObject:entity];

}

[ltableView reloadData];

This is bad idea as I am doing this inside " performInsertWithDragInfo" before 
I return from tableView:(NSTableView *)tableView 
acceptDrop:(id)info row:(NSInteger)row 
dropOperation:(NSTableViewDropOperation)dropOperation which looks wrong to me. 
However I did not observe any issues on 10.9 where I extensively tested this. 
When I ran the same code on 10.7 I started noticing issues.

May 16 09:49:55 Mac-107-Test-Machine GUD[13022]: *** Assertion failure in 
-[NSTableRowData _addRowViewForVisibleRow:withPriorView:], 
/SourceCache/AppKit/AppKit-1138.51/TableView.subproj/NSTableRowData.m:2484
May 16 09:49:55 Mac-107-Test-Machine GUD[13022]: Row 1 should be in the valid 
visible section
I don't know why this is not seen in 10.9.
Is there any delegate that would get called after acceptDrop? In the 
documentation I saw tableView:draggingSession:endedAtPoint:operation: but I 
don't think its relevant here. Am I missing something?

Regards,
Varun
___

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: NSWorkspace issue

2014-05-07 Thread Varun Chandramohan
Ah yes, that was the mistake. I did not notice it. Probably its always a
good idea to use fileURLWithPath as I always deal with file urls and not
http://.


On 7/05/2014 3:58 pm, "Ken Thomases"  wrote:

>On May 7, 2014, at 12:02 AM, Varun Chandramohan wrote:
>
>>NSURL *fileURL = [NSURL
>>URLWithString:@"/Users/usr/Desktop/libd.dylib"];
>
>This is not correct.  +[NSURL URLWithString:] expects a valid URL string.
> What you're providing is a file path string, which is not a URL string.
>A URL string might be "http://www.apple.com"; or
>"file:///Users/usr/Desktop/libd.dylib".  However, never just prepend
>"file://" to a file path to try to make it into a URL string.  That
>doesn't correctly handle a path which contains characters which are not
>valid in URLs.
>
>The correct thing to do is use +[NSURL fileURLWithPath:] or a similar
>method.
>
>Regards,
>Ken
>


___

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

NSWorkspace issue

2014-05-06 Thread Varun Chandramohan
Hi All,

I wanted to open a Finder window from my app with a file pre-selected. The user 
could perform any Finder operations needed. I looked around the internet and it 
turns out the best way to do this is using NSWorkspace.


- (void)applicationDidFinishLaunching:(NSNotification *)aNotification

{

// Insert code here to initialize your application

NSURL *fileURL = [NSURL URLWithString:@"/Users/usr/Desktop/libd.dylib"];

NSArray *fileURLs = [NSArray arrayWithObjects:fileURL, nil];

[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs];

}

However, I am not sure what is going on. The Finder window never pops up. I do 
see the top bar change to Finder bar but then the window is never present. The 
file I am trying to highlight is present. Is there anyway to know error code? 
The method is void.

Regards,
Varun
___

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: Question on NSScrollView

2014-05-04 Thread Varun Chandramohan
Hi Quincey,

You are right, the code is taken from the link you posted. Actually I
understand that group rows were demonstrated in that code. Actually when I
remove group code I get desired result. I was trying to include group rows
so that in future should I need that feature, I need not revisit the
implementation. I tried to make group rows behave as normal. For now I
decided to comment out the code that makes it group rows. Thanks for your
help.

Regards,
Varun

On 3/05/2014 8:06 am, "Quincey Morris"
 wrote:

>On May 2, 2014, at 14:06 , Lee Ann Rucker  wrote:
>
>> You might find it useful to get one of the Apple sample apps, like
>>TableViewPlayground, and experiment with that - it's easier to figure
>>out what's happening when you have a fully-implemented example than it
>>is to start from scratch.
>
>FWIW, the code being used by the OP has every appearance of being taken
>from this tutorial:
>
>   
> https://github.com/lucasderraugh/AppleProg-Cocoa-Tutorials/blob/master/Le
>sson%2053/Lesson%2053/AppDelegate.m
>
>but it seems to me that the class name ŒDesktopFolderEntity¹ suggests an
>origin in a predecessor to the current TableViewPlayground, where there¹s
>currently a class name ŒATDesktopFolderEntity¹.
>
>However, now that I look at it, this tutorial seems to be intended to
>show how to use group rows, which isn¹t what the OP wants.
>
>___
>
>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/varun.chandramohan%40won
>tok.com
>
>This email sent to varun.chandramo...@wontok.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: Question on NSScrollView

2014-05-01 Thread Varun Chandramohan
I ran 'tableView:viewForTableColumn and it is always tableColumn == nil as I 
have just 1 column. I noticed that I never hit anything that is not 
"GroupCell". However this does not solve the grey background right?

Also I tried [ltableView setSelectionHighlightStyle:  
NSTableViewSelectionHighlightStyleSourceList];
It at least gets me the blue highlight colour. However there is some weird blue 
background now.
http://snag.gy/a1AC3.jpg is how it looks now. Still not a white background.

Regards,
Varun

From: Quincey Morris 
mailto:quinceymor...@rivergatesoftware.com>>
Date: Friday, 2 May 2014 3:12 pm
To: Development 
mailto:varun.chandramo...@wontok.com>>
Cc: Cocoa dev mailto:Cocoa-dev@lists.apple.com>>
Subject: Re: Question on NSScrollView

On May 1, 2014, at 17:25 , Varun Chandramohan 
mailto:varun.chandramo...@wontok.com>> wrote:

Yes I have implemented tableView:isGroupRow.
- (BOOL)tableView:(NSTableView *)tableView isGroupRow:(NSInteger)row {
DesktopEntity *entity = _tableContents[row];
if ([entity isKindOfClass:[DesktopFolderEntity class]]) {
return YES;
}
return NO;
}

What is wrong with this?

Nothing at all! Rows corresponding to a 'DesktopFolderEntity' are group rows, 
and all the others are not.

Also I implemented
- (NSView *)tableView:(NSTableView *)tableView 
viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
DesktopEntity *entity = _tableContents[row];
if ([entity isKindOfClass:[DesktopFolderEntity class]]) {
NSTableCellView *groupCell = [tableView 
makeViewWithIdentifier:@"GroupCell" owner:self];
[groupCell.textField setStringValue:entity.name];
return groupCell;
}
return nil;
}

Are you saying I should not return nil here?

Well, you are returning nil for rows that aren't 'DesktopFolderEntity', which 
doesn't seem a good idea, but that isn't the issue you asked about.

In this code, you should return a view with identifier "GroupCell" - as you 
have done - for rows that are 'DesktopFolderEntity'. Since these are indeed 
group rows, this correctly gives them the group-row appearance (the one with 
the gray background).

That is, your table view is showing exactly what you asked it to show.

Your 'tableView:viewForTableColumn:' method is, however, missing some code. You 
need to return a view for non-group rows (that would probably be a view with 
identifier 'DataCell', if you have the default setup in IB), and you need to 
test tableColumn (and possibly tableColumn.identifier). ('tableColumn == nil' 
means that you're being asked for a group-row view. Otherwise you're being 
asked for a per-column view.)
___

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: Question on NSScrollView

2014-05-01 Thread Varun Chandramohan
Hi Quincey,

Yes I have implemented tableView:isGroupRow.

- (BOOL)tableView:(NSTableView *)tableView isGroupRow:(NSInteger)row {

DesktopEntity *entity = _tableContents[row];

if ([entity isKindOfClass:[DesktopFolderEntity class]]) {

return YES;

}

return NO;

}

What is wrong with this?

Also I implemented

- (NSView *)tableView:(NSTableView *)tableView 
viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {

DesktopEntity *entity = _tableContents[row];

if ([entity isKindOfClass:[DesktopFolderEntity class]]) {

NSTableCellView *groupCell = [tableView 
makeViewWithIdentifier:@"GroupCell" owner:self];

[groupCell.textField setStringValue:entity.name];

return groupCell;

}

return nil;

}

Are you saying I should not return nil here?

Regards,
Varun

From: Quincey Morris 
mailto:quinceymor...@rivergatesoftware.com>>
Date: Friday, 2 May 2014 9:10 am
To: Development 
mailto:varun.chandramo...@wontok.com>>
Cc: Cocoa dev mailto:Cocoa-dev@lists.apple.com>>
Subject: Re: Question on NSScrollView

On May 1, 2014, at 15:16 , Varun Chandramohan 
mailto:varun.chandramo...@wontok.com>> wrote:

However this is not the case with the same table
populated manually using NSPasteboardReading and NSTableViewDataSource,
NSTableViewDelegate. I noticed a grey background to all the entries to the
table.

It looks like you have inadvertently turned all the rows into group rows. There 
are a couple of ways this might happen, that I can think of offhand. One is 
(obviously) if you implemented the 'tableView:isGroupRow:' delegate method and 
returned YES. Otherwise, make sure in methods like 'tableView:objectValue...' 
and 'tableView:willDisplayCell...' or 'tableView:viewForTableColumn...' that 
you don't return a non-nil value when the column is nil. (A nil column is how 
the table view asks the delegate/data source for per-row values that span 
columns.)

___

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: Question on NSScrollView

2014-05-01 Thread Varun Chandramohan
Thanks a lot. I did implement it and everything seems to be working fine.
Although I did see one major issue. When I used arrayController on the
same table I used get my entries in white background and when clicked on
gets highlighted in blue. However this is not the case with the same table
populated manually using NSPasteboardReading and NSTableViewDataSource,
NSTableViewDelegate. I noticed a grey background to all the entries to the
table. This is weird as I did not change any properties in the textField
to get this colour. The example of this is http://snag.gy/0m8xi.jpg. Does
anyone know why this is happening and how to get rid of this?

Regards,
Varun

On 30/04/2014 12:40 pm, "Graham Cox"  wrote:

>
>On 30 Apr 2014, at 12:20 pm, Varun Chandramohan
> wrote:
>
>> Can someone tell me if NSScrollView can be extended to work like that?
>>Any suggestions?
>
>
>You don't want to extend or subclass NSScrollView. Instead just put a
>custom view inside it. You can set up drag and drop in any view - check
>out the NSDraggingDestination protocol.
>
>--Graham
>
>


___

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

Question on NSScrollView

2014-04-29 Thread Varun Chandramohan
Hi Guys,

In my app I have a scrollview that displays a list of file paths which is 
populated by NSArrayController. This work well, except that I wanted to add 
some fancy functionality to it. I have seen some apps allow dragging a file 
from Finder into scroll view to add it. This is a neat functionality without 
the need to have buttons to manipulate the list. Can someone tell me if 
NSScrollView can be extended to work like that? Any suggestions?

Regards,
Varun
___

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: Memory Leaks and ARC

2014-04-22 Thread Varun Chandramohan
That makes sense. I am now able to see the issue after setting
OBJC_DEBUG_MISSING_POOLS=YES. My original code was using CoreFoundation
extensively and I introduced Foundation APIs recently. I think this issue
got introduced after that.
Since this is non-cocoa application (daemon), what I have is basically,

Main(){

Init code

InstallRunLoopSources();
// Go go gadget server!

if (err == 0) {
asl_log(gAslClient, NULL, ASL_LEVEL_NOTICE,  "Initialisation
successful. Entering run loop.\n");

CFRunLoopRun();



}

This is just a brief overview, so my guess is that I need to put create
auto release pool here for NS objects that are used. Is it a good idea to
put in pools for each runloop callbacks? I already have pool in place for
all threads I created using pthread_create. The only place is missing is
the main thread as show above.

Regards,
Varun

On 23/04/2014 2:05 pm, "Greg Parker"  wrote:

>On Apr 22, 2014, at 6:49 PM, Jens Alfke  wrote:
>> On Apr 22, 2014, at 6:38 PM, Varun Chandramohan
>> wrote:
>>> However when I
>>> run the same code in older OS 10.7.x and run leaks there I noticed big
>>> dump of leaks and my daemon (runs without a UI) has numerous
>>>_NSCFString
>>> autoreleased with no pool in place - just leaking -
>> 
>> If you¹re creating NSThreads, make sure the main/top-level method of
>>each thread has an autorelease pool. I seem to recall some change in
>>functionality there in recent OS versions.
>> 
>>> break on objc_autotreleaseNoPool() to debug
>> 
>> Šbut instead of listening to me speculate, you could set a breakpoint
>>on that function and find out exactly where the leak is happening.
>
>In recent OS versions, calls to +load methods are automatically wrapped
>in autorelease pools. Older OS versions did not do this. This is one
>possible cause of "autoreleased with no pool in place" on older OS
>versions. In this case there is no leaked or abandoned memory on recent
>OS versions, but there will be leaks on older OS versions.
>
>In recent OS versions, the runtime automatically creates an autorelease
>pool on a thread if you call -autorelease without one in place. This pool
>will live as long as the thread does. This is another possible cause of
>"autoreleased with no pool in place" on older OS versions. In this case
>there may be abandoned memory on recent OS versions, if your thread is
>long-lived and lots of objects fall into this pool. You can run with
>OBJC_DEBUG_MISSING_POOLS=YES to get "autorelease with no pool in place"
>messages here that are similar to the ones you get on older OS versions.
>
>(History: some OS version accidentally introduced the
>create-new-pool-automatically behavior in some cases. We couldn't undo
>that without breaking some apps that shipped in the meantime, so instead
>we formalized it and added the OBJC_DEBUG_MISSING_POOLS=YES log.
>Somewhere around here I have a feature request for Instruments detection
>of "old" autorelease pools that are hanging on to objects that should be
>dead.)
>
>
>-- 
>Greg Parker gpar...@apple.com Runtime Wrangler
>
>


___

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: Memory Leaks and ARC

2014-04-22 Thread Varun Chandramohan
Hi Guys,

Since we are on the topic I noticed something interesting in my code. My
development environment is 10.9.1, and when ever I run ³leaks² command to
check for memory leaks I get none. It seems pretty clean. However when I
run the same code in older OS 10.7.x and run leaks there I noticed big
dump of leaks and my daemon (runs without a UI) has numerous _NSCFString
autoreleased with no pool in place - just leaking - break on
objc_autotreleaseNoPool() to debug. This is bizarre as I would have
expected to see this problem on 10.9 as well. Can someone explain what is
going on here?

Regards,
Varun

On 23/04/2014 9:18 am, "Quincey Morris"
 wrote:

>On Apr 22, 2014, at 15:18 , Dave  wrote:
>
>> I assumed that ARC would release myImage on each interation of the
>>loop, however, this seems not to be the case
>
>The ŒmyImage¹ variable gives up *ownership* of the previous image object
>when you create a new one in the loop, but whether that leads to a
>deallocation of the object is an implementation detail. If it¹s
>autoreleased anywhere in its [short] lifetime, the image object will
>linger in the autorelease pool until the pool is drained, as Keary said.
>
>If you want to avoid autoreleases, you should ensure that the image is
>returned from the download method with +1 ownership semantics. As far as
>that method is concerned, you can do this by changing its name to start
>with ŒnewŠ¹, or decorate its declaration with
>Œ__attribute__((ns_returns_retained))¹. You would, of course, have to
>ensure that the download method and the methods it calls don¹t do
>anything else that¹s likely to retain/autorelease the image.
>
>This sort of thing is a bit messy because it relies on presumed (but
>partially documented) knowledge of the ARC implementation. It¹s more
>robust and straightforward to do what Keary says. However, if you really
>wanted to avoid autoreleases completely, there are ARC strategies that
>can help.
>
>___
>
>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/varun.chandramohan%40won
>tok.com
>
>This email sent to varun.chandramo...@wontok.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: NSOperation Issues

2014-04-21 Thread Varun Chandramohan
Hi Ken,

You are right this is not NSOp issues as it seems to have finished.

[queue waitUntilAllOperationsAreFinished];
[op isCancelled] replied with NO

[op isFinished] with YES

So this has to be some QCCAESPadCryptor internal error. Ill investigate
this further. Thank you.

Regards,
Varun




On 22/04/2014 9:10 am, "Ken Thomases"  wrote:

>On Apr 21, 2014, at 5:47 PM, Varun Chandramohan wrote:
>
>>op = [[QCCAESPadCryptor alloc] initToDecryptInputData:[NSData
>> dataWithBytes:cyphertext_dat length:sizeof(cyphertext_dat)]
>>  keyData:[NSData
>> dataWithBytes:key_dat length:sizeof(key_dat)]
>>  ];
>>op.ivData = [NSData dataWithBytes:iv_dat length:sizeof(iv_dat)];
>>queue = [[NSOperationQueue alloc] init];
>>[queue addOperation:op];
>>[queue waitUntilAllOperationsAreFinished];
>
>> After [queue waitUntilAllOperationsAreFinished];
>
>> op.outputData is nil. This was not the case before. I don¹t know how to
>> debug this.
>
>It sounds like the operation's internal code failed or, possibly, that
>the operation was cancelled.
>
>Check the value of [op isCancelled] and [op isFinished].  If it's
>finished and not cancelled, then it ran to completion and the problem has
>nothing to do with the operation queue.  I don't have any idea why it
>might have failed.  That would be a matter of the implementation of
>QCCAESPadCryptor and/or the specific cypher text, key, and input data
>you're passing it.
>
>Regards,
>Ken
>


___

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: NSOperation Issues

2014-04-21 Thread Varun Chandramohan
Hi Ken,

Sorry for opening up old thread. I noticed that the code I shared earlier
has stopped working in my app.

 QCCAESPadCryptor *  op;
NSString *licenseKey = nil;
NSOperationQueue *queue;
op = [[QCCAESPadCryptor alloc] initToDecryptInputData:[NSData
dataWithBytes:cyphertext_dat length:sizeof(cyphertext_dat)]
  keyData:[NSData
dataWithBytes:key_dat length:sizeof(key_dat)]
  ];
op.ivData = [NSData dataWithBytes:iv_dat length:sizeof(iv_dat)];
queue = [[NSOperationQueue alloc] init];
[queue addOperation:op];
[queue waitUntilAllOperationsAreFinished];


The thread was created to ask about this behaviour in daemon. However this
was working fine on my app for a while and now stopped working. I am not
even sure why its not working.
After [queue waitUntilAllOperationsAreFinished];

if (op.outputData != nil) {
authString = [[[NSString alloc] initWithData:op.outputData
encoding:NSUTF8StringEncoding] autorelease];
}

op.outputData is nil. This was not the case before. I don’t know how to
debug this. During the last discussion there was discussion about
mainThread. So I even tried a little experiment



- (void) runOp:(id) obj
{
QCCAESPadCryptor *  op = obj;
[queue addOperation:op];
[queue waitUntilAllOperationsAreFinished];
}



[self performSelectorOnMainThread:@selector(runOp:) withObject:op
waitUntilDone:YES];


Neither did this work. Any suggestions?

Regards,
Varun

On 4/04/2014 11:16 am, "Ken Thomases"  wrote:

>On Apr 3, 2014, at 7:02 PM, Varun Chandramohan wrote:
>
>> On 4/04/2014 10:47 am, "Jerry Krinock"  wrote:
>> 
>>> On 2014 Apr 03, at 16:11, Varun Chandramohan
>>>  wrote:
>>> 
>>>> when I port the same code to be used as a user daemon, I noticed that
>>>> NSOperationQueue fails.
>>> 
>>> I¹d suspect a run loop issue.  For example, maybe your daemon is
>>>exitting
>>> before the operation begins.
>> 
>> Oh you mean, the runloop has not been initialised and the daemon is
>> exiting before that?
>> That could be the cause. Thanks I will investigate.
>
>If the code that was shown was running on the main thread, then the
>process should not have exited.  The code called [queue
>waitUntilAllOperationsAreFinished].
>
>In general, operation queues don't rely on the run loop.
>
>It is correct that if the code shown was in a background thread and
>nothing was keeping the main thread from exiting, then the process will
>be terminated, likely before the operation finished (or maybe even
>started) executing.  Parking the main thread in a loop running its run
>loop, assuming the run loop has at least one input source, is one way of
>preventing the main thread from exiting.  But that's the only tenuous
>relationship between run loops and operation queues.
>
>Regards,
>Ken
>


___

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: Fast NSArray compare

2014-04-15 Thread Varun Chandramohan
To summarise what was discussed,

- I think the folder hierarchy problem is easily solvable as I always
traverse from top of the tree. If an entry for one of the folders is found
in my set I stop the traversal to lower leaves of the tree.
- I would be using NSSet to store my “restrict list”. However I will be
using file names instead of resource identifier object because I need to
preserve this across reboots. However I could always extract the resource
identifier object for these NSURL objects and do the comparison. There is
always a possibility that one of the files stored in “restricted list”
could be removed or changed automatically by user or program. If this
happens, I am holding a useless value that is no longer present in file
system. This is not a big issue as I see other than wasteful entry in the
set. Upon application restart when reading from the file which stored the
restricted list, I could do a file existence check for all entries in the
restricted set. 
- I will be converting the NSSet to NSArray and save it in file. I read
the array as NSSet when the application starts.

Is there something else I am missing?

Regards,
Varun 

On 16/04/2014 4:17 am, "Gary L. Wade"  wrote:

>Also, if your folder hierarchy, traversal code, and checks can deal well
>with it, you¹ll get better performance by short-circuiting based on upper
>directory checks.
>
>For example, if you know you¹re in /Downloads, don¹t compare against
>/Documents/AboutUs.pdf. Just use the /Documents set of file objects when
>you¹re in /Documents.
>--
>Gary L. Wade
>http://www.garywade.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/varun.chandramohan%40won
>tok.com
>
>This email sent to varun.chandramo...@wontok.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: Fast NSArray compare

2014-04-14 Thread Varun Chandramohan
Thanks Guys,

Yes I was not planning to use -[NSURL isEqual:]. Interestingly, Graham¹s
suggestion was to use NSSet, I was thinking what if I want to keep this
persistent? I would be writing this set to a file? I have used NSArray
writeToFile before but I don¹t see that method for NSSet. Do I have to
convert it to NSArray and store? Am I missing something?

I figured if I put resource identifier object into the NSMutableSet then
will I be able to write this into a file? I know it is possible if I store
it as NSString but might not allow id?

Regards,
Varun

On 15/04/2014 12:01 pm, "Ken Thomases"  wrote:

>On Apr 14, 2014, at 7:02 PM, Varun Chandramohan wrote:
>
>> I have a question about efficiency when trying to compare NSURL. The
>>requirement is quite simple. I try and iterate through a directory to
>>all subdirectories and files. While doing this walk-through, I need to
>>check against an array of NSURLs which are restricted files and folders.
>> This means if I find a match of file I am trying to access in the array
>>then I don't do any operations on that file and continue.
>
>You don't say how you're comparing URLs.  Just in case, you should not
>use -[NSURL isEqual:] or any method which relies on string comparison.
>That can be confused by case differences, the presence of hard or
>symbolic links, and extraneous path elements (e.g. "foo/./bar" vs.
>"foo/bar").
>
>You should obtain the resource identifier object of each URL using
>-getResourceValue:forKey:error: with NSURLFileResourceIdentifierKey, then
>compare those two objects using -isEqual:.
>
>If you take Graham's suggestion of using an NSSet or similar hash-based
>collection to test, then put the resource identifiers of the restricted
>files into the set and check a candidate URL's resource identifier
>against that set.
>
>For what it's worth, comparing resource identifiers may be faster than
>the string comparison otherwise inherent in -[NSURL isEqual:].  The
>identifier is likely to be a number or pair of numbers internally and so
>is quick to compare.  That said, the improvement may be swamped by the
>cost of obtaining the resource identifier object.
>
>
>> Secondly, I plan to store array of NSURL for restricted files and
>>folders. What is the best way to get partial compare?
>> 
>> Eg: Entry in array : /XYZ/abc
>> This means I should not iterate into the abc folder. So any files
>>/XYZ/abc/1.c or /XYZ/abc/def/2.c should all be skipped. Whats the best
>>way to do partial NSURL compare? Or is it better I store it as NSString
>>instead of NSURL?
>
>Don't try to do substring compares.  Since you're iterating a directory
>hierarchy, you should simply not iterate a subdirectory if it matches.
>When using NSDirectoryEnumerator, that's easy to do: just call
>-skipDescendants.
>
>If you feel you must compare two URLs to see if one is contained in the
>other, you'll probably have to successively obtain the parent directory
>URL from the candidate URL using -getResourceValue:forKey:error: with
>NSURLParentDirectoryURLKey until you've reached the top of the hierarchy
>or you have matched one of your restricted file URLs.
>
>You _might_ want to optimize that by obtaining the
>NSURLVolumeIdentifierKey of each URL and then determining that one
>doesn't contain the other if the two URLs are for different volumes.
>Whether that's appropriate or not depends on whether you care about
>path-based containment or file-system-based containment.  "/foo/bar/baz"
>may be on a different volume than "/foo" and you have to decide whether
>that means that it's not contained by "/foo".
>
>Regards,
>Ken
>


___

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

Fast NSArray compare

2014-04-14 Thread Varun Chandramohan
Hi All,

I have a question about efficiency when trying to compare NSURL. The 
requirement is quite simple. I try and iterate through a directory to all 
subdirectories and files. While doing this walk-through, I need to check 
against an array of NSURLs which are restricted files and folders.
This means if I find a match of file I am trying to access in the array then I 
don't do any operations on that file and continue.

Lets say I walkthrough 1000 files and folders, for each file/folder I need to 
compare against this array list. This might be slow or inefficient. Is there a 
faster way to do something like this?

Secondly, I plan to store array of NSURL for restricted files and folders. What 
is the best way to get partial compare?

Eg: Entry in array : /XYZ/abc
This means I should not iterate into the abc folder. So any files /XYZ/abc/1.c 
or /XYZ/abc/def/2.c should all be skipped. Whats the best way to do partial 
NSURL compare? Or is it better I store it as NSString instead of NSURL?

Regards,
Varun
___

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: Retain count in non ARC

2014-04-06 Thread Varun Chandramohan
Thanks guys, really appreciate it.

On 7/04/2014 1:25 pm, "Ken Thomases"  wrote:

>On Apr 6, 2014, at 9:18 PM, Graham Cox wrote:
>
>> On 7 Apr 2014, at 10:35 am, Varun Chandramohan
>> wrote:
>> 
>>> @property (retain) NSArray* contents;
>> 
>> Should be:
>> 
>> @property (copy) NSArray* contents;
>
>> @synthesize contents = ivarContents;
>> 
>> Having done that you'll now only have one ivar, the one you declared,
>>and it will be associated with the property 'contents'. You won't need
>>to write your own getter, but the setter should look something like:
>
>Be careful.  If the property is atomic (i.e. not declared nonatomic) and
>you implement any of the accessors, then you have to implement them all
>to ensure they use the same synchronization scheme to achieve atomicity.
>Usually, it's better/easier to simply declare the property nonatomic.
>
>Regards,
>Ken
>


___

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: NSOperation Issues

2014-04-06 Thread Varun Chandramohan
Thanks for the answers guys, I agree that Authorization Services API is
not feasible in many cases. However I did make sure that daemon that runs
as root has very minimal to do and hopefully well written code that is not
exploitable. My only worry was that the code I wrote for root daemon was
using CoreFoundation and later replaced with Foundation APIs as they lot
easier to code and maintain. I saw few people warning against that as
there might be some bugs in Foundation API that could exploit my daemon
and gain root access. While that is very much a possibility, I was hoping
that such issues would be addressed very quickly by Apple? No?

Regards,
Varun

On 4/04/2014 4:07 pm, "Kyle Sluder"  wrote:

>On Apr 3, 2014, at 9:54 PM, Jens Alfke  wrote:
>> 
>> 
>>> On Apr 3, 2014, at 7:47 PM, Varun Chandramohan
>>> wrote:
>>> 
>>> I understand what you mean, but are you saying that I should not use
>>>any Foundation library functions when running as root user?
>> 
>> I¹m saying you shouldn¹t run *anything*, Foundation or not, as root
>>unless there is a very good reason to.
>> 
>>> There are sometimes needs to have super user permission, how do we
>>>address that? I mean, lets say we need to add a rule in fw (ipfw) which
>>>requires to be root user right?
>> 
>> That¹s exactly what the Authorization Services API is for ‹ letting a
>>normal process request the ability to temporarily do something with root
>>privileges. You see it all the time, whenever an app pops up a ³This app
>>needs to do such-and-such, please enter an administrator password² panel.
>
>A process cannot elevate its own privileges to root level, even
>temporarily. So doing anything that requires root privileges necessarily
>requires running an entire process as root.
>
>Varun, you should create a separate setuid process that does the
>_absolute minimum_ amount of work that can be encapsulated under root
>privileges. This process should be launched by your non-setuid main
>process via Authorization Services.
>
>--Kyle Sluder


___

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: Retain count in non ARC

2014-04-06 Thread Varun Chandramohan
Hi Graham,

Thank you for such detailed explanation. I made a few changes except the
type check of what NSPropertyListSerialization returns. Ill be adding that
soon. Other than that, I wanted you to take a look at the changes I made
and let me know if you see any problems. I tested it, at it seems fine and
the warnings went away.

@interface TempConfig : NSObject {
NSMutableArray* ivarContents;
}

@property (retain) NSArray* contents;




- (void) setContents:(NSArray *)serializeObj
{
if (serializeObj) {
ivarContents = [serializeObj mutableCopy];
} else {
ivarContents = [[NSMutableArray alloc] initWithCapacity:10 ];
}
contents = ivarContents;
}

- (id) contents
{
return contents;
}

- (void) addTempObject: (id)object
{
[ivarContents addObject:object];
}

- (void) dealloc
{
[ivarContents release];
contents = nil;
[super dealloc];
}

+ (id) newTempConfigWithSource:(NSString*)source
{
TempConfig* config = [[[self class] alloc] init];

// Read contens from file
NSError *errorDesc = nil;
NSPropertyListFormat format;
NSData *plistXML = [[NSFileManager defaultManager]
contentsAtPath:source];

if( plistXML == nil ) {
[config release];
return nil;
}
// Serialize to array
[config setContents:(NSArray *)[NSPropertyListSerialization
  propertyListWithData:plistXML
  options:0
  format:&format
  error:&errorDesc]];
if( [config contents] == nil ) {
[config release];
return nil;
}
return config;
}

There are other methods where I would not be doing
NSPropertyListSerialization, in which case if I pass nil, the API will
allocate mutable array which will be used later using addTempObject method.



Regards,
Varun



On 4/04/2014 2:59 pm, "Graham Cox"  wrote:

>
>On 4 Apr 2014, at 2:40 pm, Graham Cox  wrote:
>
>> Thirdly, casting the return value of [NSPropertyListSerialization
>>propertyListWithData...] to NSMutableArray doesn't turn that object into
>>a mutable array - you've just forced the type system to stop helping
>>you. Certainly retaining it here is the wrong thing to do as well, since
>>this code doesn't own that object, and has no business retaining it.
>>That's what the analyser is trying to tell you.
>
>
>I've just noticed that the situation is even worse than that.
>
>[NSPropertyListSerialization ...] is declared to return an id. What is
>it? Could be anything. It might be an NSArray, might be a NSDictionary,
>might be a string - in fact there's no way to know unless you ask it.
>There is a way to specify that mutable objects are returned, though it's
>not that clear if this method supports it (the documentation appears to
>have a cut/paste error that suggests options are mutability options, but
>elsewhere they are read options which are unimplemented and require that
>you pass 0), but even if it does, you haven't asked for mutable objects.
>
>In this situation I definitely would be writing my own -setContents:
>method, and first thing it would do is to assert that the class of the
>parameter is NSArray. That way if someone screws up and deserializes a
>valid but unexpected property list, your code won't fail horribly, but
>instead can politely throw an exception. I'd also be copying that array
>into a mutable one if you need it to be mutable. Everyone's happy,
>including the crappy documentation writer who hasn't noticed his error.
>
>Code defensively.
>
>--Graham


___

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

Retain count in non ARC

2014-04-03 Thread Varun Chandramohan
Hi Guys,

I was looking into an older project which does not use ARC and I noticed new 
static code analysis issues with leaks. Here is a little sample code of the 
object in question.


@interface TempConfig : NSObject


@property (assign) NSMutableArray* contents;


+(id)newTempConfigWithSource:(NSString*)source;


@end


+ (id) newTempConfigWithSource:(NSString*)source

{

ScanConfig* config = [[[self class] alloc] init];



// Read contens from file

NSError *errorDesc = nil;

NSPropertyListFormat format;

NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:source];


if( plistXML == nil ) {

[config release];

return nil;

}

// Serialize to array

[config setContents:(NSMutableArray *)[[NSPropertyListSerialization

  propertyListWithData:plistXML

  options:0

  format:&format

  error:&errorDesc] retain]];

if( [config contents] == nil ) {<---Static analysis points out to 
potential leak of object.

[config release];

return nil;

}

return config;

}


The way I use the code.

TempConfig* innerPList = [TempConfig newTempConfigWithSource:fullPath ];

[innerPList release];


Interestingly, the static code analysis find the call of "retain" as a leak. 
How do I address this issue? What is correct way to rewrite this code to make 
static analyser understand that I will be releasing the resource? If I removed 
the retain count, the warning goes away but it contents is freed and I crash.


Regards,

Varun

___

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: NSOperation Issues

2014-04-03 Thread Varun Chandramohan
Thanks Ken,

That helped.

Regards,
Varun

On 4/04/2014 11:16 am, "Ken Thomases"  wrote:

>On Apr 3, 2014, at 7:02 PM, Varun Chandramohan wrote:
>
>> On 4/04/2014 10:47 am, "Jerry Krinock"  wrote:
>> 
>>> On 2014 Apr 03, at 16:11, Varun Chandramohan
>>>  wrote:
>>> 
>>>> when I port the same code to be used as a user daemon, I noticed that
>>>> NSOperationQueue fails.
>>> 
>>> I¹d suspect a run loop issue.  For example, maybe your daemon is
>>>exitting
>>> before the operation begins.
>> 
>> Oh you mean, the runloop has not been initialised and the daemon is
>> exiting before that?
>> That could be the cause. Thanks I will investigate.
>
>If the code that was shown was running on the main thread, then the
>process should not have exited.  The code called [queue
>waitUntilAllOperationsAreFinished].
>
>In general, operation queues don't rely on the run loop.
>
>It is correct that if the code shown was in a background thread and
>nothing was keeping the main thread from exiting, then the process will
>be terminated, likely before the operation finished (or maybe even
>started) executing.  Parking the main thread in a loop running its run
>loop, assuming the run loop has at least one input source, is one way of
>preventing the main thread from exiting.  But that's the only tenuous
>relationship between run loops and operation queues.
>
>Regards,
>Ken
>


___

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: NSOperation Issues

2014-04-03 Thread Varun Chandramohan
Hi Jens,

I understand what you mean, but are you saying that I should not use any 
Foundation library functions when running as root user? There are sometimes 
needs to have super user permission, how do we address that? I mean, lets say 
we need to add a rule in fw (ipfw) which requires to be root user right?

Regards,
Varun

From: Jens Alfke mailto:j...@mooseyard.com>>
Date: Friday, 4 April 2014 11:47 am
To: Development 
mailto:varun.chandramo...@wontok.com>>
Cc: "cocoa-dev@lists.apple.com<mailto:cocoa-dev@lists.apple.com>" 
mailto:cocoa-dev@lists.apple.com>>
Subject: Re: NSOperation Issues


On Apr 3, 2014, at 4:11 PM, Varun Chandramohan 
mailto:varun.chandramo...@wontok.com>> wrote:

I suspect that NSOperationQueue cannot be used as daemon running as root user?

This isn't directly related to your question, but you almost certainly 
shouldn't be running your code as root. That's a bad security practice - it 
means that security problems in your code might be exploitable to take control 
of the entire OS. If your code shouldn't run as any specific user account, the 
usual approach is to create a special account for it.

-Jens
___

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: NSOperation Issues

2014-04-03 Thread Varun Chandramohan
Oh you mean, the runloop has not been initialised and the daemon is
exiting before that?
That could be the cause. Thanks I will investigate.

On 4/04/2014 10:47 am, "Jerry Krinock"  wrote:

>
>On 2014 Apr 03, at 16:11, Varun Chandramohan
> wrote:
>
>>  when I port the same code to be used as a user daemon, I noticed that
>>NSOperationQueue fails.
>
>I¹d suspect a run loop issue.  For example, maybe your daemon is exitting
>before the operation begins.
>___
>
>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/varun.chandramohan%40won
>tok.com
>
>This email sent to varun.chandramo...@wontok.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

NSOperation Issues

2014-04-03 Thread Varun Chandramohan
Hi All,

I have some basic decryption I do with common crypto that works very well when 
I use in my app, some sample code below.

 QCCAESPadCryptor *  op;

NSString *licenseKey = nil;

NSOperationQueue *queue;

op = [[QCCAESPadCryptor alloc] initToDecryptInputData:[NSData 
dataWithBytes:cyphertext_dat length:sizeof(cyphertext_dat)]

  keyData:[NSData 
dataWithBytes:key_dat length:sizeof(key_dat)]

  ];

op.ivData = [NSData dataWithBytes:iv_dat length:sizeof(iv_dat)];

queue = [[NSOperationQueue alloc] init];

[queue addOperation:op];

[queue waitUntilAllOperationsAreFinished];

However,  when I port the same code to be used as a user daemon, I noticed that 
NSOperationQueue fails. I suspect that NSOperationQueue cannot be used as 
daemon running as root user?

If so are there any other alternates?


Regards,

Varun
___

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: NSBox Border Width Property

2014-03-31 Thread Varun Chandramohan
Ok, Setting it to 1 solved it. Looks like it should not be 0.

Regards,
Varun

On 1/04/2014 2:57 pm, "Varun Chandramohan" 
wrote:

>Hi Graham,
>
>I checked that before posting here. In Size Inspector for ³Box"
>Margins (Horizontal) 0 (Vertical) 0
>Border (Width) 0 (Radius) 0.
>
>That¹s what I am not able to understand where the problem is.
>
>- Varun
>
>On 1/04/2014 2:53 pm, "Graham Cox"  wrote:
>
>>
>>On 1 Apr 2014, at 1:14 pm, Varun Chandramohan
>> wrote:
>>
>>>  have a view which has a NSBox. The view is designed and managed by IB
>>>and I am doing nothing from code.  The NSBox is of type (primary, the
>>>way I want it), and border type is Line. When I use this, I get warning
>>>"Border width requires NSCustomBox type and NSLineBorder" type. To get
>>>rid of this warning, if I simply select type of box as Custom it works.
>>>However I want the box to be Primary. How do I "not use border width
>>>property"? I don't even know how this is getting added. Perhaps because
>>>of width constrains? If so is there a way to get rid of this?
>>
>>
>>You must have a border width >1. Click the sizing tab and set the border
>>width to 1.
>>
>>--Graham
>>
>>
>
>
>___
>
>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/varun.chandramohan%40won
>tok.com
>
>This email sent to varun.chandramo...@wontok.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: NSBox Border Width Property

2014-03-31 Thread Varun Chandramohan
Hi Graham,

I checked that before posting here. In Size Inspector for ³Box"
Margins (Horizontal) 0 (Vertical) 0
Border (Width) 0 (Radius) 0.

That¹s what I am not able to understand where the problem is.

- Varun

On 1/04/2014 2:53 pm, "Graham Cox"  wrote:

>
>On 1 Apr 2014, at 1:14 pm, Varun Chandramohan
> wrote:
>
>>  have a view which has a NSBox. The view is designed and managed by IB
>>and I am doing nothing from code.  The NSBox is of type (primary, the
>>way I want it), and border type is Line. When I use this, I get warning
>>"Border width requires NSCustomBox type and NSLineBorder" type. To get
>>rid of this warning, if I simply select type of box as Custom it works.
>>However I want the box to be Primary. How do I "not use border width
>>property"? I don't even know how this is getting added. Perhaps because
>>of width constrains? If so is there a way to get rid of this?
>
>
>You must have a border width >1. Click the sizing tab and set the border
>width to 1.
>
>--Graham
>
>


___

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

NSBox Border Width Property

2014-03-31 Thread Varun Chandramohan
Hi All,

I have a view which has a NSBox. The view is designed and managed by IB and I 
am doing nothing from code.  The NSBox is of type (primary, the way I want it), 
and border type is Line. When I use this, I get warning "Border width requires 
NSCustomBox type and NSLineBorder" type. To get rid of this warning, if I 
simply select type of box as Custom it works. However I want the box to be 
Primary. How do I "not use border width property"? I don't even know how this 
is getting added. Perhaps because of width constrains? If so is there a way to 
get rid of this?

Regards,
Varun
___

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