Re: Swift and Threads

2016-09-13 Thread Stephen J. Butler
This site suggests a version using withUnsafeMutableBufferPointer:

http://blog.human-friendly.com/swift-arrays-are-not-threadsafe

let nbrOfThreads = 8
let step = 2
let itemsPerThread = number * step
let bitLimit = nbrOfThreads * itemsPerThread
var bitfield = [Bool](count: bitLimit, repeatedValue: false)

let queue = dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_HIGH, 0 );

bitfield.withUnsafeMutableBufferPointer { (inout bitfieldBuffer :
UnsafeMutableBufferPointer) -> () in
dispatch_apply( Int(nbrOfThreads), queue ) { ( idx: size_t) -> Void in
let startIndex = itemsPerThread * Int(idx)
let endIndex = min( startIndex + itemsPerThread, bitLimit )
if talk { print("Thread[\(idx)] does \(startIndex) ..<
\(endIndex)") }

var currIndex = startIndex
while( currIndex < endIndex )
{
bitfieldBuffer[currIndex] = true
currIndex += step
}
}
}


On Tue, Sep 13, 2016 at 1:52 AM, Gerriet M. Denkmann 
wrote:

>
> > On 12 Sep 2016, at 22:49, Jens Alfke  wrote:
> >
> >
> >> On Sep 12, 2016, at 6:42 AM, Gerriet M. Denkmann 
> wrote:
> >>
> >> So: is the code ok and the compiler broken in Debug mode?
> >> Or is the code fundamentally wrong and that it works in Release is just
> a fluke?
>
> I tried a variation of my function. This does not crash (not even in Debug
> builds), but takes twice the memory and is about four times slower:
>
> func markAndTell_2( talk: Bool, number: Int) -> [Bool]
> {
> [...]
> let bitLimit = nbrOfThreads * itemsPerThread
> var bitfield = [Bool](count: bitLimit, repeatedValue: false)
>
> var outputSlice0: ArraySlice = []
> [...]
> var outputSlice7: ArraySlice = []
>
> let queue = dispatch_get_global_queue(
> DISPATCH_QUEUE_PRIORITY_HIGH, 0 );
> dispatch_apply( Int(nbrOfThreads), queue,
> { ( idx: size_t) -> Void in
>
> let startIndex = itemsPerThread * Int(idx)
> let endIndex = min( startIndex + itemsPerThread,
> bitLimit )
>
> var tempSlice: ArraySlice = bitfield[
> startIndex ..< endIndex ]
>
> var currIndex = startIndex
> while( currIndex < endIndex )
> {
> tempSlice[currIndex] = true
> currIndex += step
> }
>
> switch(idx)
> {
> case 0: outputSlice0 = tempSlice
> [...]
> case 7: outputSlice7 = tempSlice
> default: print("Thread[\(idx)] does not
> know where to put its slice")
> }
> }
> )
>
> bitfield = []
> bitfield += outputSlice0
> [...]
> bitfield += outputSlice7
>
> return bitfield
> }
>
> Gerriet.
>
>
> ___
>
> 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/
> stephen.butler%40gmail.com
>
> This email sent to stephen.but...@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: Where are my bytes hiding?

2016-05-05 Thread Stephen J. Butler
Those files are compressed by the filesystem. In HFS+/MacOS Extended that
means that the data fork is empty and the file contents are stored in the
resource fork or extended attributes structure.

http://wiki.sleuthkit.org/index.php?title=HFS#HFS.2B_File_Compression

If it's in the extended attributes, then it's part of the file metadata
(like name, timestamps, etc), whereas Finder is probably using the size of
the datafork to arrive at 0 bytes. If you get the afsctool (from MacPorts
for example) then you can get all sorts of detailed info:

File is HFS+ compressed.

File content type: public.xml

File size (uncompressed data fork; reported size by Mac OS 10.6+ Finder):
2005 bytes / 2 KB (kilobytes) / 2 KiB (kibibytes)

File size (compressed data fork - decmpfs xattr; reported size by Mac OS
10.0-10.5 Finder): 0 bytes / 0 KB (kilobytes) / 0 KiB (kibibytes)

File size (compressed data fork): 895 bytes / 1 KB (kilobytes) / 1 KiB
(kibibytes)

Compression savings: 55.4%

Number of extended attributes: 0

Total size of extended attribute data: 0 bytes

Approximate overhead of extended attributes: 268 bytes

Approximate total file size (compressed data fork + EA + EA overhead + file
overhead): 1411 bytes / 1 KB (kilobytes) / 1 KiB (kibibytes)

You might want to take a look at the source code of that tool to see how
they calculated all those numbers. Be careful of licensing though.

On Wed, May 4, 2016 at 11:47 PM, Gerriet M. Denkmann 
wrote:

> I just did:
> > cd
> /Applications/Xcode.app/Contents/Developer/Documentation/DocSets/com.apple.adc.documentation.watchOS.docset/Contents/Resources/Tokens/C/tag/-
> > ls -skl
>
> There are 8 files. Finder → File → Get Info → Size: has for each: xxx
> bytes (Zero bytes on disk), where “xxx” is the same number as reported by
> “ls -skl”.
>
> First question:
> How does one achieve this phenomenal compression: 0 bytes on disk - but
> can expand to several thousand bytes? If this is not a creatio ex nihilo,
> then: where are these bytes hiding?
>
> Second question:
> Finder says about the containing folder: 11,239 bytes (33 KB on disk) for
> 9 items
> 11,239 = sum of TotalFileSizes of the 8 files in this folder.
> But where do the “33 KB on disk” come from? 8 times “Zero bytes on disk”
> should be zero, shouldn’t it?
>
> The reason for these questions:
> I want to write an app, which counts (for a given folder) the number of
> bytes stored on disk.
>
> Gerriet.
>
>
> ___
>
> 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/stephen.butler%40gmail.com
>
> This email sent to stephen.but...@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: Diff view framework?

2016-01-25 Thread Stephen J. Butler
How about using a webkit view and one of these diff2html scripts:

http://stackoverflow.com/questions/641055/diff-to-html-diff2html-program

On Mon, Jan 25, 2016 at 3:08 AM, Jonathan Guy  wrote:

> Hi all
> Does anyone know of a cocoa framework which provides a view for showing
> file differences?
> I am aware there are plenty of free and paid apps to do this but I really
> need this view to be built into my app if possible.
> Thanks for any help.
> Jonathan
> ___
>
> 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/stephen.butler%40gmail.com
>
> This email sent to stephen.but...@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: Handling http:// URLs

2015-10-13 Thread Stephen J. Butler
I think you're talking about Seamless Linking/Universal Links. Introduced
in iOS 9

https://developer.apple.com/videos/play/wwdc2015-509/

https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html

On Tue, Oct 13, 2015 at 7:20 PM, Rick Mann  wrote:

> I thought iOS 8 (or 7?) introduced support for iOS apps to handle http
> URLs. Specifically, I could register to be launched when the user taps on a
> URL in Safari, say, that matches http://my.company.com/foo*.
>
> But when I google for this, all I get is the old stuff about custom
> schemes. Did this go away?
>
> --
> Rick Mann
> rm...@latencyzero.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/stephen.butler%40gmail.com
>
> This email sent to stephen.but...@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: Question about enums

2015-07-17 Thread Stephen J. Butler
How about using a Custom option with an associated String value?

enum Foo:String {

case Bar = “Bar
case Etc = “Etc
case Etc_Etc = “Etc Etc
case Custom(String)
 }


On Fri, Jul 17, 2015 at 2:53 PM, Michael de Haan  m...@comcast.net wrote:

 I wonder if I can get some input as I seemed to have hit a wall in Swift,
 2.0

 My App uses structs and enums to hold the bulk of the data needed for
 it’s  default values (probably over 95%). So, for example,

 enum Foo:String {

 case Bar = “Bar
 case Etc = “Etc
 case Etc_Etc = “Etc Etc
  }


 As a very small percentage of the app, I want to allow the user to add a
 custom “raw-Value of Type Foo. In essence, it would be as if the user had
 added another case to the enum.



  let x = Foo(rawValue: “newRawValue”) not unsurprisingly,  returns “nil.

 I know that I could use Core Data to store the data, but it seems that for
 so trivial amount of user data,I should be able to do it without resorting
 to Core Data.

 Or, I may be approaching it the wrong way entirely.

 Your thoughts would be greatly appreciated.





 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: Question about enums

2015-07-17 Thread Stephen J. Butler
Or what about this? Tested this time...

enum Foo {
case Bar
case Etc
case Etc_Etc
case Custom(String)

func asString() - String {
switch self {
case .Bar: return Bar
case .Etc: return Etc
case .Etc_Etc: return Etc Etc
case .Custom(let value): return value
}
}

init(withString value: String) {
switch value {
case Bar: self = .Bar
case Etc: self = .Etc
case Etc Etc: self = .Etc_Etc
default:
self = .Custom(value)
}

}
}

let a = Foo(withString: Bar)
let b = Foo(withString: Something Else)

print(a = \(a.asString()); b = \(b.asString()))

I guess more typing, and some room for error in the initializer, but it
does do away with the wrapper class.

On Fri, Jul 17, 2015 at 3:39 PM, Quincey Morris 
quinceymor...@rivergatesoftware.com wrote:

 On Jul 17, 2015, at 13:33 , Stephen J. Butler stephen.but...@gmail.com
 wrote:


 How about using a Custom option with an associated String value?

 enum Foo:String {

case Bar = “Bar
case Etc = “Etc
case Etc_Etc = “Etc Etc
case Custom(String)
 }


 Unfortunately that won’t compile. One alternative is:

 enum Foo: String {
 case Bar = Bar
 case Etc = Etc
 case Etc_Etc = Etc Etc
 }

 enum FooPlus {
 case AFoo (Foo)
 case AString (String)

 var asString: String {
 switch self
 {
 case let .AFoo (foo): return foo.rawValue
 case let.AString (string): return string
 }
 }
 }




___

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 about enums

2015-07-17 Thread Stephen J. Butler
Oops, yes, obviously I haven't played much with raw representable enums yet
:) Thanks for the correction.

On Fri, Jul 17, 2015 at 3:39 PM, Quincey Morris 
quinceymor...@rivergatesoftware.com wrote:

 On Jul 17, 2015, at 13:33 , Stephen J. Butler stephen.but...@gmail.com
 wrote:


 How about using a Custom option with an associated String value?

 enum Foo:String {

case Bar = “Bar
case Etc = “Etc
case Etc_Etc = “Etc Etc
case Custom(String)
 }


 Unfortunately that won’t compile. One alternative is:

 enum Foo: String {
 case Bar = Bar
 case Etc = Etc
 case Etc_Etc = Etc Etc
 }

 enum FooPlus {
 case AFoo (Foo)
 case AString (String)

 var asString: String {
 switch self
 {
 case let .AFoo (foo): return foo.rawValue
 case let.AString (string): return string
 }
 }
 }




___

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: cannot invoke 'substringToIndex' with an argument list of type '(Int)'

2015-07-07 Thread Stephen J. Butler
You should file a documentation bug. The signature is actually:

func substringFromIndex(index: String.Index) - String

So what you really want I believe is:

s = s.substringToIndex(advance(s.endIndex, -1))


On Tue, Jul 7, 2015 at 2:02 AM, Rick Mann rm...@latencyzero.com wrote:

 What? The docs say that substringToIndex is declared like this:

 func substringToIndex(_ to: Int) - String

 So, why can't I call that here:

 extension
 NSURL
 {
func
normalizedURLByAppendingPathComponent(var inComponent : String)
- NSURL
{
var s = self.absoluteString;
if s.hasSuffix(/)
{
s = s.substringToIndex(s.characters.count - 1)
}

if inComponent.hasPrefix(/)
{
inComponent = inComponent.substringFromIndex(1);
}

s = s.stringByAppendingString(/);
s = s.stringByAppendingString(inComponent);

let u = NSURL(string: s);
return u;
}
 }


 --
 Rick Mann
 rm...@latencyzero.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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: Swift 2 init() with CF types and throws

2015-07-01 Thread Stephen J. Butler
You're focusing on the wrong part :) Which element of your code has a type
of NSGraphicsContext? It's cocoaCTX! The compiler error is suggesting you
do one of these:

cocoaCTX?.graphicsPort
cocoaCTX!.graphicsPort


On Wed, Jul 1, 2015 at 6:28 PM, Rick Mann rm...@latencyzero.com wrote:

 I'm trying to do this:

 class
 Context
 {
 init()
 throws
 {
 let cocoaCTX = NSGraphicsContext.currentContext()
 guard let sysCTX = cocoaCTX.graphicsPort as! CGContextRef else {
 throw Errors.InvalidContext }
 CGContext = sysCTX;
 }

 var CGContext : CGContextRef
 }


 But I'm getting

 error: value of optional type 'NSGraphicsContext?' not unwrapped; did you
 mean to use '!' or '?'?
 guard let sysCTX = cocoaCTX.graphicsPort as! CGContextRef
 else { throw Errors.InvalidContext }
^
!
 In the typical if-let, you don't add the ?. If I do add the ?, I get:

 error: '_??' is not convertible to '_??'
 guard let sysCTX = cocoaCTX.graphicsPort? as! CGContextRef
 else { throw Errors.InvalidContext }
~^

 Errors is an enum I created in a different file.

 I always seem to trip up on the conditional optional unwrapping. Not sure
 what I'm doing wrong here. Help is much appreciated. Thanks!

 --
 Rick Mann
 rm...@latencyzero.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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: Swift program termination...

2015-05-24 Thread Stephen J. Butler
I think you should use GCD by creating a dispatch source of type
DISPATCH_SOURCE_TYPE_SIGNAL (the handle is the signal enum, eg
SIGTERM), add an event handler, and then resume it.

On Sun, May 24, 2015 at 10:40 AM, Randy Widell randy.wid...@gmail.com wrote:
 I’m messing around with Swift to create a network server daemon.  Maybe I am 
 thinking too much like a C / C++ programmer, but I am trying to figure out 
 how to gracefully exit when launchd unloads the daemon.  Normally, you would 
 just trap SIGTERM, but I’m just not finding anything online about how to do 
 something similar in Swift.
 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: Best way to move a file out of the way?

2015-03-24 Thread Stephen J. Butler
I would say rename the new destination file if you think you should
keep the old one around.

However, if it's always the case that the new file should replace the
old one when it finishes downloading, then you should save the new
file under a temporary name and use -[NSFileManager
replaceItemAtURL:withItemAtURL:backupItemName:options:resultingItemURL:error:].
Look at the documentation for that. I think you'll also want to
research using -[NSFileManager
URLForDirectory:inDomain:appropriateForURL:create:error:] with
NSItemReplacementDirectory.

On Tue, Mar 24, 2015 at 7:55 PM, Daryle Walker dary...@mac.com wrote:
 Right now, my command-line tool errors out if the destination filename, 
 chosen automatically from the NSURLResponse object, already exists in the 
 working directory. Should I keep it that way, or put the new file there 
 anyway? If the latter, this involves doing something to the previous file 
 with that name (or keeping it the same and renaming the new file instead). 
 Should I delete the old file (causing problems if transferring the new one 
 fails), try replacing (does it work across volumes), or trashing the old file 
 (does this send the instant-delete GUI alert if it happens while current 
 Trash items are emptied)?

 If renaming is the answer, is there any sample code to do this safely, taking 
 care of all cases?  (For example, replacement name already taken, or adding 
 an extension if the file doesn’t start with one, etc.)

 —
 Daryle Walker
 Mac, Internet, and Video Game Junkie
 darylew AT mac DOT 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: Crash in libsystem_kernel.dylib`__workq_kernreturn:

2015-01-25 Thread Stephen J. Butler
I agree that it sounds like a memory management bug. Especially since
you aren't using ARC. Try turning on NSZombies and see if it crashes
at a more helpful point.

http://michalstawarz.pl/2014/02/22/debug-exc_bad_access-nszombie-xcode-5/

On Sun, Jan 25, 2015 at 4:57 PM, Trygve Inda cocoa...@xericdesign.com wrote:
 On Jan 25, 2015, at 12:33 , Trygve Inda cocoa...@xericdesign.com wrote:

 It does seem like if I remove a call to

 NSData* imageData = [[self myImageRep]
 representationUsingType:NSJPEGFileType properties:imageProperties];

 It no longer crashes, but the crash happens 3-5 seconds after this call when
 my program should be idle.

 It sounds like a memory management bug. What’s the context of the above line
 of code? Is it in a block? Are you using ARC?



 No ARC and not in a block. I am trying to make a jpg file from a
 NSBitmapImageRep which works fine, but sometimes I get a crash... Even
 though the file is correctly produced.





 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: URLByResolvingBookmarkData not case sensitive

2015-01-06 Thread Stephen J. Butler
What about this (caveat: only works if the file exists):

@interface NSArray (FileNSURL)
- (NSUInteger) indexOfFileNSURL:(NSURL*)aFileURL error:(NSError**)error;
@end

@implementation NSArray (FileNSURL)

- (NSUInteger) indexOfFileNSURL:(NSURL *)aFileURL error:(NSError**)error {
id srcResourceID;

if (![aFileURL getResourceValue:srcResourceID
forKey:NSURLFileResourceIdentifierKey error:error])
return NSNotFound;

// NSNotFound from now will not signal an error
if (error)
*error = nil;
return [self indexOfObjectPassingTest:^BOOL(id obj, NSUInteger
idx, BOOL *stop) {
id objResourceID;

// skip this obj if there is an error getting the ID key
if (![obj getResourceValue:objResourceID
forKey:NSURLFileResourceIdentifierKey error:nil])
return NO;
else
return [objResourceID isEqual:srcResourceID];
}];
}

@end

On Tue, Jan 6, 2015 at 10:43 PM, Trygve Inda cocoa...@xericdesign.com wrote:
 On Jan 6, 2015, at 7:40 PM, Kyle Sluder k...@ksluder.com wrote:

 On Jan 6, 2015, at 5:05 PM, Trygve Inda cocoa...@xericdesign.com wrote:

 If I bookmark a file and the case of any folders or the file itself 
 changes,
 then later when I extract the path from the bookmark I want it to reflect
 the new case of the path as it now exists.

 Use -[NSFileManager componentsToDisplayForPath:]. Then you don’t even need 
 to
 canonicalize anything yourself.

 Yes.  Also, the components to display for a path are *not* the display name
 for each path component.  For example, the user never sees /Volumes.

 You should try to avoid displaying file paths to the user if at all possible.
 If you must, try using an NSPathControl.  That does additional simplification
 of the path, like starting paths inside the user's home at the home folder 
 and
 not showing the parent directories of the home folder (e.g. /Users).

 If you really, really need to canonicalize a URL, you can try converting it 
 to
 a file reference URL using -fileReferenceURL and then back to a file path URL
 using -filePathURL.  See the documentation for -fileReferenceURL for caveats.
 Also, this conversion can produce unexpected results in the face of symlinks
 and/or hard links.

 Ultimately what I need to able to do is compare a bookmark to a path. I
 would like to do this using NSArray's indexOfObject with a path derived from
 the bookmark, but because the bookmark's path is not updated when only the
 case changes, this sort of comparison will not work.

 Basically I would like a method like:

 [bookmarkData isEqualToPath:path]





 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: NSRegularExpression segfault

2014-12-15 Thread Stephen J. Butler
If you read the ICU docs on regular expressions you'll see that it sets an
8MB limit on head size when evaluating. My guess is that you've run into
this and NSRegularExpression misses a return code somewhere.

But your pattern is really suboptimal for what you're trying to accomplish.
For example, this pattern is functionally equivalent and doesn't cause a
crash for me:

@(([0-9a])\\2*)

That matches a single character, and then the same character 0 or more
times.

On Mon, Dec 15, 2014 at 10:38 AM, ecir hana ecir.h...@gmail.com wrote:

 Hi!

 I recently needed to match some patterns but I encountered a problematic
 situation.

 Please, can anyone explain to me why does the following program
 consistently segfault after 5 characters? I'm running 10.9.5...

 #import Cocoa/Cocoa.h

 int main () {
 NSString *pattern =
 @(1+)|(2+)|(3+)|(4+)|(5+)|(6+)|(7+)|(8+)|(9+)|(0+)|(a+);
 NSRegularExpression *expression = [NSRegularExpression
 regularExpressionWithPattern:pattern options:0 error:nil];
 for (NSUInteger i = 0; i  10; i += 1) {
 NSString *string = [@ stringByPaddingToLength:i withString:@
 a
 startingAtIndex:0];
 NSTextCheckingResult *result = [expression
 firstMatchInString:string options:0 range:NSMakeRange(0, i)];
 NSLog(@%@, NSStringFromRange([result range]));
 }
 return 0;
 }

 It says:

 {0, 0}
 {0, 1}
 {0, 2}
 {0, 3}
 {0, 4}
 {0, 5}
 Segmentation fault: 11

 Thanks in advance!
 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: NSRegularExpression segfault

2014-12-15 Thread Stephen J. Butler
It seems to be related to the number of capture groups you have. For
example, this also succeeds for me:

((?:1+)|(?:2+)|(?:3+)|(?:4+)|(?:5+)|(?:6+)|(?:7+)|(?:8+)|(?:9+)|(?:0+)|(?:a+))

Do you really need the 11 capture groups?

On Mon, Dec 15, 2014 at 11:20 AM, ecir hana ecir.h...@gmail.com wrote:



 On Mon, Dec 15, 2014 at 6:09 PM, Stephen J. Butler 
 stephen.but...@gmail.com wrote:

 If you read the ICU docs on regular expressions you'll see that it sets
 an 8MB limit on head size when evaluating. My guess is that you've run into
 this and NSRegularExpression misses a return code somewhere.


 I would have thought 50 000 characters is not that much. But then again, I
 don't really know how ICU works... Reading the ICU docs further, there it
 says:

 Because ICU does not use program recursion to maintain its backtracking
 state, stack usage during matching operations is minimal, and does not
 increase with complex patterns or large amounts of backtracking state.



 But your pattern is really suboptimal for what you're trying to
 accomplish.


 It's really a reduced test case.

___

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: hueComponent not valid for the NSColor

2014-11-01 Thread Stephen J. Butler
It's a color space that only contains a white and alpha component. Hue
doesn't make sense in an all white space. It's like if we were talking
about a train that only goes between NYC and DC, and you asked How long
does it take for that train to reach London? You can't ask that question
because the train doesn't go there. It doesn't have that degree of freedom.

Your second example has white in a RGB color space. That does have the
freedom to give you hue.

On Sat, Nov 1, 2014 at 2:36 PM, Torsten Curdt tcu...@vafer.org wrote:

 I am struggling to understand why this causes an exception

 NSColor *base = [NSColor whiteColor];
 NSColor *stroke = [NSColor colorWithCalibratedHue:base.hueComponent

  saturation:base.saturationComponent
brightness:0.4
 alpha:base.alphaComponent];

  -hueComponent not valid for the NSColor NSCalibratedWhiteColorSpace 1 1;
 need to first convert colorspace.

 While the following colors work OK

 - [NSColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]
 - [NSColor redColor]

 Can anyone offer some insights?

 cheers,
 Torsten
 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: How to convert String.Index to UInt?

2014-08-16 Thread Stephen J. Butler
Try:

import Cocoa

let s = hallo\there
let aas = NSMutableAttributedString(string: s, attributes: nil)

if let rangeOfTab = s.rangeOfString( \t ) {
let colour = NSColor.grayColor()
let length = distance(s.startIndex, rangeOfTab.startIndex)
let aRange = NSRange(location: 0, length: length)
aas.addAttribute(NSForegroundColorAttributeName, value: colour, range:
aRange)
}

Maybe read more:

http://oleb.net/blog/2014/07/swift-strings/



On Sat, Aug 16, 2014 at 3:30 AM, Gerriet M. Denkmann gerr...@mdenkmann.de
wrote:

 import Cocoa

 let s = hallo\there
 let aas = NSMutableAttributedString( string: s, attributes: nil )

 let rangeOfTab = s.rangeOfString( \t )
 if rangeOfTab != nil
 {
 let colour = NSColor.grayColor()
 let locationOfTab = rangeOfTab!.startIndex
 let aRange = NSRange( location: 0, length: locationOfTab ) --
 error: 'String.Index' is not convertible to 'Int'
 aas.addAttribute( NSForegroundColorAttributeName, value: colour,
 range: aRange )
 }

 How can I convert a String.Index into an UInt (or Int or whatever)?

 Gerriet.


 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: Class in Swift

2014-08-16 Thread Stephen J. Butler
I'm still learning Swift, but extrapolating from what I might do in Python
or Ruby...

protocol MyProtocol { ... }

func myFunction(generator: (MyParameterType) - MyProtocol) {
  for ... {
let p : MyParameterType = ...
if not p special { continue }

let obj = generator(p)
...
  }
}

class Foo : MyProtocol {}

myFunction() { p in Foo(p) }

You should always be looking for the idiomatic way to do something in a
language, and not just translate line from line your old code. There's
probably an even slicker way to do this, but here's what immediately popped
into my head. It's even more flexible than your Obj-C example since the
closure captures the caller's context, and you can use all that to
construct Foo if you want, yet type safety is always assured.


On Sat, Aug 16, 2014 at 6:32 AM, Gerriet M. Denkmann gerr...@mdenkmann.de
wrote:

 How to translate into Swift:

 - (void)myFunctionWithClass: (Class)someClass
 {
 for(...)
 {
 p = ...
 if ( p is not special ) continue;

 id MyProtocol aClass = [[ someClass alloc]
 initWithParameter: p ];
 ... do something with aClass ...
 }
 }

 Assuming that someClass is costly to initialize and myFunctionWithClass
 does so only under certain circumstances.
 Or that myFunctionWithClass creates many instances of someClass.

 Assuming also, that there is an unlimited number of classes (all
 implementing MyProtocol).

 Which means that there is no way that the caller of myFunctionWithClass
 could create a someClass and pass it to the method.

 How to do this in Swift?

 Gerriet.


 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: How do I temporary retain self, under ARC?

2014-07-17 Thread Stephen J. Butler
Do you know this code will always run on the main thread? Because you could
fix this from the other side, in the delegate. Use
dispatch_async(dispatch_get_main_queue(), ...) to un-assign the property.
But this won't work if you're on a non-main thread when you call back into
the delegate.


On Thu, Jul 17, 2014 at 10:01 PM, Jens Alfke j...@mooseyard.com wrote:

 Every once in a while I run into a bug in my code that’s triggered by self
 getting dealloced in the middle of a method. It’s usually something like
 - (void) someMethod {
 doSomeStuff;
 [self.delegate object: self didSomeStuff: yeah];
 doSomeMoreStuff;
 }
 where it turns out that the delegate method clears its reference to me,
 and that was the last reference, causing self to get dealloced during the
 delegate call, causing doSomeMoreStuff to crash.

 Once I’ve identified such a bug, the fix is easy: put a [[self retain]
 autorelease] at the top of the method. Except now I’m using ARC, and I
 can’t find a simple way of doing it. I tried adding
 __unused id retainedSelf = self;
 but the optimizer recognizes that retainedSelf isn’t used and strips it
 out, making this a no-op. The only thing I’ve found that works is
 CFRetain((__bridge CFTypeRef)self);
 at the top of the method, and a corresponding CFRelease at the end, but
 this is pretty ugly and could cause leaks if the method returns early.

 Am I missing some convenient way of doing this? I looked through the ARC
 docs, at least those I could find, and didn’t see anything relating to this.

 —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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: NSStrings to CStrings and hex encoding...

2014-06-24 Thread Stephen J. Butler
Those are the UTF-8 sequences for smart quotes. It's not coming from
cStringUsingEncoding, but directly from NSTextView:

http://stackoverflow.com/questions/19801601/nstextview-with-smart-quotes-disabled-still-replaces-quotes

Rant: This has been a super annoying Mavericks feature IMHO. Even when you
put TextEdit into plain text mode it still does the smart quotes.


On Tue, Jun 24, 2014 at 9:15 PM, Andrew Satori d...@druware.com wrote:

 Alright, I am stumped so I am asking for help (and it is annoying me
 because I am 100% certain that the answer will be stupid simple).

 I have a bit of code (old code I might add) that I am updating to ARC and
 other such modern features.  Unfortunately, I have run into a little snag.
  The code calls out to a C library that expects good old fahsioned C
 Strings of the UCHAR * variety. In prior versions of OS X and Cocoa
 cStringUsingEncoding would return the string and things would be ducky.
  However, starting with Mavericks and Xcode 5 I am seeing a problem where
 the resulting char * is encoding characters to hex representations.  So for
 example, the following NSString taken from an NSTextView content

 NSString myValue = select * from some_table where column_name = 'value'

 becomes

 (UCHAR *)szValue = select * from some_table where column_name =
 \xe2\x80\x98value\xe2\x80\x99

 Even more disturbing is that it only happens when typed into the
 NSTextView.  Pasting the above NSString value into the NSTextView results
 in the unescaped output. I am guessing that is has to do with the settings
 on the  NSTextView, but I do not see what changed to cause this.  I am
 hoping someone can clue me into the probably dead obvious problem.
 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: string literals and performance

2014-05-24 Thread Stephen J. Butler
You misunderstand the point of the Stackoverflow answer. In the first
example you've given it looks like s is just a stack local variable. In
that case there is no difference between the two examples. Actually, in the
face of optimization I bet the assembly turns out exactly the same. Use the
later because it is more clear what's going on.

If you did use the same string literal in multiple .m files then you might
get a tiny performance benefit from the extern NSString* const. But I'd
argue that the real benefit to that is if you ever decide to change the
value then you don't have to worry about updating multiple locations and/or
projects (in the case of a framework).


On Sat, May 24, 2014 at 11:08 PM, 2551 2551p...@gmail.com wrote:

 Are there any performance implications that would suggest preferring one
 or the other of these different styles?

 NSString *s = @sing me a song;
 [myClass aMethod: s];

 and

 [myClass aMethod: @sing me a song];

 I have a lot of the first kind in my code, and I'm thinking of simplifying
 it by turning them all into the second kind. A discussion on stackoverflow
 here:


 http://stackoverflow.com/questions/25746/whats-the-difference-between-a-string-constant-and-a-string-literal

 seems to suggest (if I've understood it correctly) that I'd be better off
 sticking with the first style to avoid errors and to speed up comparisons.
 However, since in my code they're all one-off 'throw away strings that
 don't get used elsewhere, that doesn't seem relevant. Is there any other
 reason why I should stick with the first style rather than the second?


 Thanks for your thoughts.

 P

 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: NSSharingService with Animated GIFs?

2014-05-17 Thread Stephen J. Butler
On Sat, May 17, 2014 at 12:41 AM, Charles Carver charlescar...@mac.comwrote:

 NSURL *saveUrl = [NSURL URLWithString:[NSString stringWithFormat:@file://%@,
 NSTemporaryDirectory()]];
 saveUrl = [saveUrl URLByAppendingPathComponent:fileName];


You shouldn't construct file URLs like this. There has been an approved API
for do this for ages. Use:

NSURL *saveURL = [NSURL  fileURLWithPathComponents:@[NSTemporaryDirectory(),
fileName]];
___

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: How to convert a UTF-8 byte offset into an NSString character offset?

2014-05-05 Thread Stephen J. Butler
What's your next step after doing the UTF8 to UTF16 range conversion? If
it's just going to be -[NSString substringWithRange:] then I'd strongly
suggest just doing -[NSString initWithBytes:length:encoding:] on the UTF8
string. At least profile it and see what the penalty is. You've already
paid the UTF16 to UTF8 conversion price once. It's not clear that going
UTF8 to UTF16 again will be a big penalty vs. the range conversion.

But profile would show.


On Mon, May 5, 2014 at 2:06 PM, Jens Alfke j...@mooseyard.com wrote:

 How can I map a byte offset in a UTF-8 string back to the corresponding
 character offset in the NSString it came from?

 I’m writing an Objective-C wrapper around a C text-tokenizer API that
 takes a UTF-8 string as input, and as part of its output returns byte
 ranges of words that it found. So my API takes an NSString, converts it to
 UTF-8, passes that to the C API, and then gets these byte offsets that it
 needs to convert into character offsets in the NSString.

 I’ve looked through both the NSString and CFString APIs and didn’t see
 anything relevant to this. I know UTF-8 isn’t rocket science and I could
 pretty easily write my own function to scan through it counting characters,
 but I suspect I’d run into the differences between Unicode characters and
 the UTF-16 code points that NSString actually considers “characters”. I’d
 much rather let CF do this for me in an internally-consistent way.

 —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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: NSURLSession + Bonjour to do peer-to-peer file transfers?

2013-12-25 Thread Stephen J. Butler
NSURLSession is a fancy HTTP client. It needs to talk to an HTTP server.
None of the included iOS and OS X frameworks (that I'm aware of) include an
HTTP server.

You can either run an HTTP server on the device in your app (
https://www.google.com/search?q=ios+http+server) or you can write your own
protocol and implement it.


On Wed, Dec 25, 2013 at 9:26 AM, Eric Wing ewmail...@gmail.com wrote:

 Is it possible to use NSURLSession + Bonjour to do peer-to-peer like
 file transfers? My example situation is that I have a Mac and iPhone.
 The iPhone has a generated file I want to copy over to the Mac through
 the wireless.

 I can publish my iPhone via Bonjour and make my Mac discover and
 resolve the address. I try to create a NSURLSessionDownloadTask on my
 Mac and a NSURLSessionUploadTask on my iPhone.

 My DownloadSession (from Mac) connects to the advertised Bonjour
 service (iPhone). But when I create the UploadSession (iPhone), I get
 a NSErrorFailingURLStringKey.


 Networks are not my strong suit, so I really don’t know if I'm on the
 right path. (On the iPhone, I picked a random socket to advertise on.
 When I resolve it on my Mac and create the DownloadSession, it
 connects on that same port which triggers the iPhone to create an
 UploadSession. I originally tried using getpeername to reuse the same
 port, but also tried hardcoding a free port that both could connect
 to. Neither seemed to help.) I’m also a bit confused on how to convert
 NSNetService to NSURLs which can be fed to NSURLRequests for
 NSURLSessions. (I basically take the NSNetService hostName and port
 properties and generate a string of the form:
 http://hostName:port/;).


 My eventual goal is to make this work with non-Apple devices too, e.g.
 a Mac pulls from an Android device instead of iPhone. So I was looking
 at NSURLSession because I assumed it used a standard protocol that
 would be easy to talk with on other platforms.

 Thanks,
 Eric
 --
 Beginning iPhone Games Development
 http://playcontrol.net/iphonegamebook/

 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: _NSWarnForDrawingImageWithNoCurrentContext

2013-12-16 Thread Stephen J. Butler
Did you try the suggestion the warning listed? Breaking on void
_NSWarnForDrawingImageWithNoCurrentContext()? Because a stack trace for
when the error occurs would be helpful.


On Sat, Dec 14, 2013 at 6:32 AM, Leonardo mac.iphone@gmail.com wrote:

 Hi, when I rotate my NSView, my image disappears for a second from the
 screen and I get this error message

 It does not make sense to draw an image when [NSGraphicsContext
 currentContext] is nil.  This is a programming error. Break on void
 _NSWarnForDrawingImageWithNoCurrentContext() to debug.  This will be logged
 only once.  This may break in the future.

 So I have put a symbolic breakpoint there and I have found the line causing
 the error, which is in NSView's drawRect method:

 [mImage drawInRect:inRect fromRect:fillRect operation:NSCompositeSourceOver
 fraction:mOpacity];

 When the image disappears, I can quite see a white rectangle coming from my
 line

 NSRectFillUsingOperation(myBounds, NSCompositeSourceOver);

 So I'm sure myBounds rect is ok. To tune up my test I made sure that mImage
 is never nil and has positive size, iRect and fillRect have always positive
 size too and they never change, mOpacity is always 1.0 and the current
 context is always not nil. As my log says:

 imageSize 1251 x 705, inRect {{0, 0}, {300, 200}}, fillRect {{97, 0},
 {1057,
 705}}, mOpacity 1.0, frameCenterRotation 2.647995, current context is not
 nil

 The error occurs when I rotate the view with frameCenterRotation, but not
 at
 any degree.

 - (void)setMAngle:(CGFloat)value
 {
 mAngle = value;
 [self setFrameCenterRotation:mAngle];
 [self setNeedsDisplay:YES];
 }

 For example, if I still rotate the NSView to frameCenterRotation 4.689613 I
 can quite see the image and I don't get the error.
 Furthermore, if I replace mOpacity with a fixed value 1.0 in the code

 [mImage drawInRect:inRect fromRect:fillRect operation:NSCompositeSourceOver
 fraction:1.0];

 the error NEVER occurs. However even using the CGFload variable mOpacity
 always = 1.0, the problem sometimes occurs when I rotate the view.
 Just to be sure I have even overrided the isOpaque method returning NO.
 Same
 trouble.
 I'm really puzzled. Any idea?


 Regards
 -- Leonardo


 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: rangeOfString behaves wierd

2013-12-09 Thread Stephen J. Butler
I don't get the same result. 10.9.0, Xcode 5.0.2. I created an empty
command line utility, copied the code, and I get NSNotFound.

2013-12-09 02:50:19.822 Test[73850:303] main 见≠見 (3 shorts) occurs in
见=見見 (4 shorts) at {9223372036854775807, 0}



On Mon, Dec 9, 2013 at 2:43 AM, Gerriet M. Denkmann gerr...@mdenkmann.dewrote:


 On 9 Dec 2013, at 15:05, Quincey Morris 
 quinceymor...@rivergatesoftware.com wrote:

  On Dec 8, 2013, at 23:46 , Gerriet M. Denkmann gerr...@mdenkmann.de
 wrote:
 
  NSString *b = @见≠見;//  0x89c1  0x2260  0x898b
 
  So what are the results with:
 
  NSString *b = @见”;
  NSString *b = @≠”;
  NSString *b = @見”;
  ?
 
   Does specifying an explicit locale make any difference?

 Explicit specifying en_US (as probably the best tested and debugged) makes
 no difference.

 Gerriet.



 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: rangeOfString behaves wierd

2013-12-09 Thread Stephen J. Butler
OK, you are right. Copy+paste didn't preserve the compatibility character.
Does look like a bug of sorts, or at least something a unicode expert
should explain.


On Mon, Dec 9, 2013 at 3:20 AM, Gerriet M. Denkmann gerr...@mdenkmann.dewrote:


 On 9 Dec 2013, at 16:00, Stephen J. Butler stephen.but...@gmail.com
 wrote:

  I don't get the same result. 10.9.0, Xcode 5.0.2. I created an empty
 command line utility, copied the code, and I get NSNotFound.
 
  2013-12-09 02:50:19.822 Test[73850:303] main 见≠見 (3 shorts) occurs in
 见=見見 (4 shorts) at {9223372036854775807, 0}

 Copying might invoke another bug.
 Better check the characters, like:

 - (void)printString: (NSString *)line
 {
 NSLog(@%s \%@\ has characters:,__FUNCTION__, line);

 [ line  enumerateSubstringsInRange: NSMakeRange( 0, [ line
 length ] )
 options:
  NSStringEnumerationByComposedCharacterSequences
 usingBlock: ^(NSString *currChar, NSRange
 currCharRange, NSRange enclosingRange, BOOL *stop)
 {
 (void)enclosingRange;
 (void)stop;

 #ifdef __LITTLE_ENDIAN__
 NSStringEncoding encoding
 = NSUTF32LittleEndianStringEncoding;
 #else
 NSStringEncoding encoding
 = NSUTF32BigEndianStringEncoding;
 #endif
 NSData *data = [ currChar
 dataUsingEncoding: encoding ];

 NSUInteger nbrBytes = [ data
 length ];
 NSUInteger nbrChars = nbrBytes /
 sizeof(unsigned int);

 if ( nbrChars * sizeof(unsigned
 int) != nbrBytes )  //  error
 {
 NSLog(@%s Error: strange
 nbr of bytes %lu,__FUNCTION__, nbrBytes);
 return;
 };

 unsigned int codePoint[nbrChars];
 [ data getBytes: codePoint
  length: nbrBytes ];

 NSMutableString *s =[
 NSMutableString stringWithFormat: @%@ = ,

   NSStringFromRange(currCharRange)

   ];
 for( NSUInteger i = 0; i 
 nbrChars; i++ )
 {
 [ s appendFormat: @%#06x
 , codePoint[i] ];
 };

 [ s appendFormat: @= \%@\,
 currChar ];

 fprintf(stderr, %s\n, [ s
 UTF8String]);
 }
 ];
 }

 and check for:
 见=見見 has characters:
 {0, 1} = 0x89c1 = 见
 {1, 1} = 0x003d = =
 {2, 1} = 0xfa0a = 見
 {3, 1} = 0x898b = 見
 见≠見 has characters:
 {0, 1} = 0x89c1 = 见
 {1, 1} = 0x2260 = ≠
 {2, 1} = 0x898b = 見

 
  On Mon, Dec 9, 2013 at 2:43 AM, Gerriet M. Denkmann 
 gerr...@mdenkmann.de wrote:
 
  On 9 Dec 2013, at 15:05, Quincey Morris 
 quinceymor...@rivergatesoftware.com wrote:
 
   On Dec 8, 2013, at 23:46 , Gerriet M. Denkmann gerr...@mdenkmann.de
 wrote:
  
   NSString *b = @见≠見;//  0x89c1  0x2260  0x898b
  
   So what are the results with:
  
   NSString *b = @见”;
   NSString *b = @≠”;
   NSString *b = @見”;
   ?
  
Does specifying an explicit locale make any difference?
 
  Explicit specifying en_US (as probably the best tested and debugged)
 makes no difference.
 


___

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: rangeOfString behaves wierd

2013-12-09 Thread Stephen J. Butler
Would converting each string to NFD (decomposedStringWithCanonicalMapping)
be an acceptable work around in this case?


On Mon, Dec 9, 2013 at 3:43 AM, Stephen J. Butler
stephen.but...@gmail.comwrote:

 OK, you are right. Copy+paste didn't preserve the compatibility character.
 Does look like a bug of sorts, or at least something a unicode expert
 should explain.


 On Mon, Dec 9, 2013 at 3:20 AM, Gerriet M. Denkmann 
 gerr...@mdenkmann.dewrote:


 On 9 Dec 2013, at 16:00, Stephen J. Butler stephen.but...@gmail.com
 wrote:

  I don't get the same result. 10.9.0, Xcode 5.0.2. I created an empty
 command line utility, copied the code, and I get NSNotFound.
 
  2013-12-09 02:50:19.822 Test[73850:303] main 见≠見 (3 shorts) occurs in
 见=見見 (4 shorts) at {9223372036854775807, 0}

 Copying might invoke another bug.
 Better check the characters, like:

 - (void)printString: (NSString *)line
 {
 NSLog(@%s \%@\ has characters:,__FUNCTION__, line);

 [ line  enumerateSubstringsInRange: NSMakeRange( 0, [ line
 length ] )
 options:
NSStringEnumerationByComposedCharacterSequences
 usingBlock: ^(NSString *currChar, NSRange
 currCharRange, NSRange enclosingRange, BOOL *stop)
 {
 (void)enclosingRange;
 (void)stop;

 #ifdef __LITTLE_ENDIAN__
 NSStringEncoding encoding
 = NSUTF32LittleEndianStringEncoding;
 #else
 NSStringEncoding encoding
 = NSUTF32BigEndianStringEncoding;
 #endif
 NSData *data = [ currChar
 dataUsingEncoding: encoding ];

 NSUInteger nbrBytes = [ data
 length ];
 NSUInteger nbrChars = nbrBytes /
 sizeof(unsigned int);

 if ( nbrChars * sizeof(unsigned
 int) != nbrBytes )  //  error
 {
 NSLog(@%s Error: strange
 nbr of bytes %lu,__FUNCTION__, nbrBytes);
 return;
 };

 unsigned int codePoint[nbrChars];
 [ data getBytes: codePoint
  length: nbrBytes ];

 NSMutableString *s =[
 NSMutableString stringWithFormat: @%@ = ,

   NSStringFromRange(currCharRange)

   ];
 for( NSUInteger i = 0; i 
 nbrChars; i++ )
 {
 [ s appendFormat: @%#06x
 , codePoint[i] ];
 };

 [ s appendFormat: @= \%@\,
 currChar ];

 fprintf(stderr, %s\n, [ s
 UTF8String]);
 }
 ];
 }

 and check for:
 见=見見 has characters:
 {0, 1} = 0x89c1 = 见
 {1, 1} = 0x003d = =
 {2, 1} = 0xfa0a = 見
 {3, 1} = 0x898b = 見
 见≠見 has characters:
 {0, 1} = 0x89c1 = 见
 {1, 1} = 0x2260 = ≠
 {2, 1} = 0x898b = 見

 
  On Mon, Dec 9, 2013 at 2:43 AM, Gerriet M. Denkmann 
 gerr...@mdenkmann.de wrote:
 
  On 9 Dec 2013, at 15:05, Quincey Morris 
 quinceymor...@rivergatesoftware.com wrote:
 
   On Dec 8, 2013, at 23:46 , Gerriet M. Denkmann gerr...@mdenkmann.de
 wrote:
  
   NSString *b = @见≠見;//  0x89c1  0x2260  0x898b
  
   So what are the results with:
  
   NSString *b = @见”;
   NSString *b = @≠”;
   NSString *b = @見”;
   ?
  
Does specifying an explicit locale make any difference?
 
  Explicit specifying en_US (as probably the best tested and debugged)
 makes no difference.
 



___

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: Download fileSystem data

2013-11-30 Thread Stephen J. Butler
Have you profiled your code to see what calls exactly are taking the most
time? I have a feeling it's these:

isFilePackageAtPath
kLSItemInfoIsInvisible
kFSNodeLockedMask
kFSCatInfoCreateDate
kFSCatInfoContentMod
kFSCatInfoBackupDate
kFSCatInfoAccessDate

And parsing ls output won't get you these (besides, parsing ls is a
dirty hack anyway). You probably want to try dropping down to
CFURLEnumerator and asking it to prefetch the desired attributes. Or, if
you're targeting pre-10.6 then FSGetCatalogInfoBulk().



On Sat, Nov 30, 2013 at 3:40 AM, Leonardo mac.iphone@gmail.com wrote:

 Hi,
 actually I ask a remote machine for
 contentsOfDirectoryAtPath
 Then for each file I ask for
 attributesOfItemAtPath
 And check the NSFileType to verify whether the file is
 NSFileTypeDirectory
 NSFileTypeRegular
 NSFileTypeSymbolicLink
 Then I check
 isFilePackageAtPath
 kLSItemInfoIsInvisible
 kFSNodeLockedMask
 kFSCatInfoCreateDate
 kFSCatInfoContentMod
 kFSCatInfoBackupDate
 kFSCatInfoAccessDate

 These queries take a long time on a remote machine.
 Is a faster way to get all of that? I thought to use a Terminal command
 throughan NSTask (e.g. ls -la plus other options), but honestly I don't
 know how to filter the query and get the smallest necessary data. Any hint?



 Regards
 -- Leonardo


 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: Sending a message to a Toll free bridge

2013-11-25 Thread Stephen J. Butler
I don't believe that the array that CTFontCopyAvailableTables() returns
contains CFTypes. So yes, CFArray is bridgeable. But in this case that
isn't so useful since the values aren't.


On Mon, Nov 25, 2013 at 3:23 AM, Gerriet M. Denkmann
gerr...@mdenkmann.dewrote:

 The documentation states: CFArray is “toll-free bridged” with its Cocoa
 Foundation counterpart, NSArray. This means that the Core Foundation type
 is interchangeable in function or method calls with the bridged Foundation
 object. Therefore, in a method where you see an NSArray * parameter, you
 can pass in a CFArrayRef

 Does this also mean: any message you can send to an NSArray, you can send
 also to an CFArrayRef?

 NSFont *fo = [ NSFont fontWithName: @Thonburi size: 0 ];
 CTFontRef font = (__bridge CTFontRef)fo;
 CFArrayRef tags = CTFontCopyAvailableTables ( font, 0 );
 NSArray *tagsArray = CFBridgingRelease(tags);
 // next  line prints: class __NSCFArray count: 18
 NSLog(@%s class %@ count: %lu,__FUNCTION__, [tagsArray class],
 [tagsArray count]);

 So sending messages to an CFArrayRef seems to be ok. Or not?

 But then this line crashes:

 NSString *tagDescription = [ tagsArray description ];

 My mistake? My false assumption?

 Gerriet.



 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: How to fix warning?

2013-08-28 Thread Stephen J. Butler
Are those really always constant? Why not:

NSCharacterSet *stopCharacters = [NSCharacterSet
characterSetWithCharactersInString:@ \t\n\r\x85\x0C\u2028\u2029];


On Wed, Aug 28, 2013 at 3:26 PM, Dave d...@looktowindward.com wrote:

 Hi,

 I am getting the following warning

 warning: format specifies type 'unsigned short' but the argument has type
 'int' [-Wformat]

 on this statement:

 NSCharacterSet *stopCharacters = [NSCharacterSet
 characterSetWithCharactersInString:[NSString stringWithFormat:@
 \t\n\r%C%C%C%C, 0x0085, 0x000C, 0x2028, 0x2029]];

 What is the best way to fix this?

 Thanks a lot
 Dave


 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: Ownership follows the 'Create' Rule' - not literally

2013-08-25 Thread Stephen J. Butler
What they're saying here is that that parameter is following the Create
Rule even though the function doesn't have a normal name for following the
rule. They are documenting an exception to the ownership rule.

If the function name did follow the rule it would be redundant to document
it as such. The documentation is there to tell you this function doesn't
follow the ownership rule its name suggests, but rather the Create Rule.



On Fri, Aug 23, 2013 at 11:13 PM, Jerry Krinock je...@ieee.org wrote:

 OS X app, manual retain/release.

 According to 'leaks' with MallocStackLoggingNoCompact, I was leaking a
 CFData object when I called CFMessagePortSendRequest().

 Indeed, the last parameter of CFMessagePortSendRequest() returns a CFData
 object by reference, and the documentation states that Ownership follows
 the 'Create Rule' for this parameter.  When I wrote this code, I read the
 Create Rule, looked at the name CFMessagePortSendRequest, did not see the
 word Create or Copy and so said, that CFData is not mine to release.

 Now, faced with the leak, I added a -release when I was done with that
 CFData, and tested with MallocScribble and MallocPreScribble environment
 variables set to 1.  Result: No more leak, no crashes.

 Lesson: When documentation says that Ownership follows the 'Create Rule'
 for a parameter, what they really mean to say is that When applying the
 'Create Rule' to this function, proceed as though this function had
 'Create' in its name.  Or, more succinctly, You own this object.


 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: NSValue valueWithBytes:objCType:

2013-08-25 Thread Stephen J. Butler
My guess, and this is only a guess, is that NSValue only uses the type
property to make sure two NSValues have the same layout before calling
memcmp (or such) on them. We have a lot of evidence that it doesn't do a
deep inspection of the type in order to give a more accurate comparison.

Can you not bzero() the structs before writing to them and placing them in
NSValues? That would solve your problem.


On Sun, Aug 25, 2013 at 12:34 PM, Andreas Grosam agro...@onlinehome.dewrote:


 On 24.08.2013, at 23:01, Jean-Daniel Dupas devli...@shadowlab.org wrote:

 
  Le 24 août 2013 à 22:09, Andreas Grosam agro...@onlinehome.de a écrit
 :
 
 
  That's not a problem specifics to NSValue.


 I disagree. Please read the documentation of NSValue:

 valueWithBytes:objCType:
 Creates and returns an NSValue object that contains a given value, which
 is interpreted as being of a given Objective-C type.


 isEqualToValue:
 Returns a Boolean value that indicates whether the receiver and another
 value are equal.


 The fact is, the result of isEqualToValue: is more often undefined,
 implementation defined or completely random when applied to structs.


  You should know what you do when manipulating structs.

 I think, I do - otherwise, I wouldn't come up with this problem. The
 problem is, that in some library which we cannot mention here, two encoded
 structs wrapped into NSValues together with method isEqualToValue: will be
 used as a means to compare structs. IMO, this's not a reliable approach.


 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: Variable Number of Parameters in Method

2013-08-21 Thread Stephen J. Butler
On Wed, Aug 21, 2013 at 2:35 AM, Dave d...@looktowindward.com wrote:

 -(void) methodX:(NSString*) theName,…
 {
 va_list
 myArgumentList;
 NSInteger
 myArgumentCount;

 myArgumentCount = 0;
 va_start(myArgumentList,theMethodName);

 while(va_arg(myArgumentList,NSString*) != nil)
  //
 myArgumentCount++;


Whatever else you're trying to do, you cannot write a loop like that.
va_arg() will NOT return nil/NULL/0 when it reaches the end. In fact,
va_arg() has no possible way of knowing when it has reached the end. That's
why you pass in theName; it's 100% up to you to parse theName and figure
out how many arguments were passed in and call va_arg() properly.

Or, alternately, force all of your arguments to be of a common base type
(say, id) and nil terminate the list. A la +[NSArray arrayWithObjects:],
etc.

But you can't have it both ways.

Once you have that your while() loop is easy:

while (more_arguments) {
  argument_type = get_next_arg_type();
  if (argument_type == myNSStringType) {
objVal = va_arg(myArgList,NSString*);
  } else if (argument_type == myNSIntegerType) {
intVal = va_arg(myArgList,NSInteger);
  } ... etc ..

  more_arguments = has_more_arguments();
}
___

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: Variable Number of Parameters in Method

2013-08-21 Thread Stephen J. Butler
On Wed, Aug 21, 2013 at 4:22 AM, Dave d...@looktowindward.com wrote:

 if ([myType isEqualToString:@NSInteger] )
 {
 myNSInteger = va_arg(myArgumentList,NSInteger*);
 //  do something with myNSInteger
 [myFormattedString appendFormat:@myNSInteger = %d ,
 myNSInteger];
 }

 else if ([myType isEqualToString:@CGFloat] )
 {
 myCGFloat = va_arg(myArgumentList, CGFloat*);
 //  do something with myCGFloat
 [myFormattedString appendFormat:@myCGFloat = %f ,
 myCGFloat];
 }


This is better, however... if you pass an actual NSInteger or CGFloat to
the method, va_arg() should have a type of NSInteger or CGFloat, not
pointers to those types. Your code examples with it's printf style formats
is using the former, not the latter. Just to be clear, you can have all
these cases:

if ([myType isEqualToString:@NSInteger] ) {
   myNSInteger = va_arg(myArgumentList,NSInteger);
} else if ([myType isEqualToString:@NSInteger*] ) {
  pMyNSInteger = va_arg(myArgumentList,NSInteger*);
} else if ([myType isEqualToString:@CGFloat]) {
  myCGFloat = va_arg(myArgumentList, CGFloat);
} else if ([myType isEqualToString:@CGFloat*]) {
  pMyCGFloat = va_arg(myArgumentList, CGFloat*);
} ... etc
___

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: -[NSBundle URLForResource:withExtension:subdirectory] is case-sensitive

2013-08-17 Thread Stephen J. Butler
On Sat, Aug 17, 2013 at 6:03 PM, Rick Aurbach r...@aurbach.com wrote:

 I expect indexURL to be non-null (and to contain the appropriate URL).
 However, in actual devices, this function returns nil; on the IOS Simulator
 it returns a valid URL. If I change the resource name to exactly match the
 actual file name (i.e., change either the filename or the argument to
 exactly match) I get a correct result on both the actual and simulated
 devices


This is a known limitation of the Simulator. On OS X the filesystem is case
preserving, but not case sensitive. Since the Simulator runs on top of OS X
it inherits this behavior.

However, on iOS the filesystem is case sensitive. It's been this way since
the beginning; you just have to watch out for it.
___

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: pathForResource:ofType: iOS bug?

2013-07-07 Thread Stephen J. Butler
How are you examining the return value? Show us that code too, please.


On Sun, Jul 7, 2013 at 7:34 PM, Jeff Smith jeff...@aol.com wrote:



 Hi,



 pathForResource:ofType: is returning a path string with 4 garbage
 characters added to the end of the string.

 To make sure it wasn't my program causing the problem I created a new iOS
 project to try it out and it does it too.


 Empty Application
 Devices - Universal
 No - Use Core Data
 No - Use ARC
 No - Include Unit Tests


 I added this to the end of application:didFinishLaunchingWithOptions:


 NSString *path = [[NSBundle mainBundle] pathForResource:@Default
 ofType:@png];


 Anyone else have this problem?


 thanks
 Jeff


 OS X 10.7.5
 Xcode 4.6.3







 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: how to run NSApplicationMain() in child process?

2013-05-10 Thread Stephen J. Butler
I didn't look at your code, but... one thing to note is that it is
absolutely not secure to run your daemon as root and display a GUI. I hope
that isn't part of your plan.

The OS X way to do this sort of thing is to write your daemon as a Launch
Agent (since it needs to interact with a logged in user). Using a launchd
plist file, you can tell launchd to monitor a TCP port/unix socket/mach
port/watched directory/etc and run your agent when there is activity. This
is nice since your agent can exit when it doesn't have anything to do, and
the system will regain resources.

Good place to start would be here:

http://developer.apple.com/library/mac/#technotes/tn2083/_index.html

And then here:

http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/Introduction.html#//apple_ref/doc/uid/1172i-SW1-SW1


On Wed, May 8, 2013 at 5:41 AM, Ondrej Holecek ondrej.hole...@gmail.comwrote:

 Hi,

 I'm creating a picture viewer controlled from command-line (I call it
 xqiv which sould be an equivalent to http://www.klografx.net/qiv/ on
 linux). However, xqiv is slightly different.

 You have to run xqiv-daemon, which is the window-based application
 which handles global notifications sent by xqiv-command-line and
 displays the image(s). My idea is to have just one application xqiv
 which acts as both daemon and/or command-line tool together. If you
 run xqiv and the deamon is not running yet it forks and run the
 daemon. Parent would act as a commandline tool and child would be the
 daemon which stay on background. Parent would sent a notification to
 the forked child what image to display and exit. If the daemon is
 already running, then fork is not needed and it would just sent the
 notification.

 The question is, how to force  NSApplicationMain() to run in child.

 The basic idea is to do something like this:

 if (already running) {
   return cmd_main(argc, argv);
 } else {
 if (fork() == 0) {
 return NSApplicationMain(argc, (const char **)argv);
 } else {
 return cmd_main(argc, argv);
 }
 }

 The real code is there: http://pastebin.com/7LD2dPK8

 When I run NSApplicationMain() in child process, it simply does
 nothing. What's wrong?

 I have already functional application there:
 https://github.com/smrt28/xqiv

 It is functional but daemon and command-line tool are two applications.

 let me note I'm the beginner in objc/cocoa development and this is my
 very first cocoa application.

 thanks,

 Ondrej
 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: how to run NSApplicationMain() in child process?

2013-05-10 Thread Stephen J. Butler
On Fri, May 10, 2013 at 1:56 AM, Ondrej Holecek ondrej.hole...@gmail.comwrote:

 thanks for the hint, I have to check this first. However at first
 glance it seems I have to create 2 applications. Daemon and cmd-line
 app. My idea is to have just one app which behaves as a daemon in
 case the deamon doesn't run yet and/or as a cmd-line tool if the
 daemon runs. But maybe it is not the way.


Make launchd run the same executable, but with a --daemon option. That's
got to be as easy, or easier, than detecting an already running one and
forking + daemonizing.
___

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: how to run NSApplicationMain() in child process?

2013-05-10 Thread Stephen J. Butler
On Fri, May 10, 2013 at 2:03 PM, Jens Alfke j...@mooseyard.com wrote:

 #!/bin/sh
 open -b com.example.XQIVApp $@


You probably want this instead to prevent word splitting for elements that
have spaces:

open -b com.example.XQIVApp $@

Nothing is ever trivial in sh/bash ;)
___

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: Too many threads?

2013-05-08 Thread Stephen J. Butler
If that's a POSIX error code it's reporting, then 35 maps to either EAGAIN
or EWOULDBLOCK.

I thought it might be you're hitting the max file limit (256 by default)
but that would cause open() to return EMFILE. However, pthread_create() can
return EAGAIN, and with 2000+ threads you might be hitting this limit:

The system lacked the necessary resources to create another thread, or the
system-imposed limit on the total number of threads in a process
[PTHREAD_THREADS_MAX] would be exceeded.


On Wed, May 8, 2013 at 5:03 PM, Rainer Standke li...@standke.com wrote:

 Hello all,

 I have an app that's rendering QuickTime movies based on AVFoundation.
 It's multi-threaded via GCD, and has up 6 renders going at the same time.

 I am getting un-explained crashes, or at least I can't explain them. The
 crashing thread is usually something deep in AVFoundation. I get things
 like this one: AVAssetWriterStatusFailed - An unknown error occurred (35)
 - The operation could not be completed

 When the crashes happen the has something like 2000 threads going,
 according to Activity Monitor, and all the Free RAM is used up.

 As a crutch I have implemented a throttling mechanism that basically waits
 a number of seconds before starting the next render - but it feels kludgy,
 and the app can still crash.

 My question is, besides properly releasing objects etc, is there any thing
 I can do to keep the number of threads down, or cause the system to spin
 down threads that aren't needed any more?

 Thanks for any pointers,

 Rainer
 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: Dynamic library linking

2013-02-24 Thread Stephen J. Butler
This is an advanced topic which touches on a lot of OS X details. The short
of it is, even if you solve your linking problems your Python 3.3 library
won't work.

What you need to is include the entire Python 3.3 framework in your
Application bundle. Once you've figured out how to do that, linking against
it is as simple as telling Xcode to link the framework. Here are two links
some Googling brought up:

Here's the official docs:

https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html

Look under Embedding a Private Framework in Your Application Bundle and
start following links. This StackOverflow question touches on the subject:

http://stackoverflow.com/questions/1621451/bundle-framework-with-application-in-xcode



On Sun, Feb 24, 2013 at 2:09 PM, ecir hana ecir.h...@gmail.com wrote:

 Hello,

 I have a simple program which I can compile but when I tried to link it
 with a dynamic library the linker is not able to find the library, despite
 that it is in the same folder as the program.

 The longer version: I want to embed Python 3.3 interpreter into simple C
 program. I'm on MacOS 10.8, which ships with Python 2.7. I downloaded the
 binary distribution of 3.3 version from python.org, copied the dynamic
 library from the bundle to a folder, along with all the headers. The
 library I copied was a file named Python which had a symlink pointing to
 it named libpython3.3m.dylib. Now that the library is in the folder,  I
 renamed it to python33 so it wouldn't collide with installed Python of
 version 2.7.

 So the folder has these files: embed.c, python33 and include folder.
 The embed.c containts:

 #include Python.h

 int
 main(int argc, char *argv[])
 {
   Py_Initialize();
   PyRun_SimpleString(print 'test'\n);
   Py_Finalize();
   return 0;
 }

 and running file python33 says:

 python33 (for architecture i386): Mach-O dynamically linked shared
 library i386
 python33 (for architecture x86_64): Mach-O 64-bit dynamically linked
 shared library x86_64

 The problem I have is that when try to run:

 gcc embed.c -I./include -L. -lpython33

 if breaks with:

 ld: library not found for -lpython33

 Please, does anyone know why?

 I guess this is not exactly Cocoa-related question but I tried to ask about
 this at various places and I have not found a solution, yet.

 I have various theories about why this happens, I would be thankful if
 someone could confirm/reject these:

 - I cannot just copy out a dynamic library out of a bundle, I have to
 install the whole Python 3.3 and after it is properly installed at
 particular locations, then I can link with it.

 - I'm missing some linker flags. I tried DYLD_LIBRARY_PATH=. but it
 didn't help.

 - The Python 3.3 library was compiled with different compiler that what I
 use to compile my program with.

 PS: it compiles with:

 gcc embed.c -I./include python33

 but when I tun ./a.out it breaks with:

 dyld: Library not loaded:
 /Library/Frameworks/Python.framework/Versions/3.3/Python
 Referenced from: /Users/ecir/Desktop/embed/./a.out
 Reason: image not found
 Trace/BPT trap: 5

 I would really appreciate any hint on how to solve this, thank you in
 advace!
 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: Cocoa | Reading Plist/file version of Native binary

2012-11-26 Thread Stephen J. Butler
Do you mean the app/bundle version? CFBundleGetValueForInfoDictionaryKey()
with kCFBundleVersionKey.


On Tue, Nov 27, 2012 at 12:41 AM, Sachin Porwal sachinpor...@gmail.comwrote:

 Hi,

 I am looking for a way to read file version information of a native
 Binary(32/64 bit) in Cocoa. This is required to upgrade a existing
 tool on target system from my custom installer.
 Could you please point me in right direction? Much appreciated

 Thanks,
 Sachin
 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: App rejection due to app-sandboxing invalid entitlement

2012-10-29 Thread Stephen J. Butler
On Mon, Oct 29, 2012 at 12:49 PM, Martin Hewitson
martin.hewit...@aei.mpg.de wrote:
 But com.apple.security.scripting-targets is not a temporary entitlement, is 
 it? I thought this was the recommended way of communicating between apps in 
 the new era.

But this part clearly is:

  keycom.apple.security.temporary-exception.apple-events/key
  array
stringcom.apple.mail/string
  /array
___

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: Hints for supporting dragging a file onto the dock icon, then onto a row in menu presented at that point?

2012-09-13 Thread Stephen J. Butler
On Thu, Sep 13, 2012 at 2:40 PM, Chris Markle cmar...@asperasoft.com wrote:
 I'm pretty new to OS X development and just looking for hints about
 how to do something like this... I saw an app called Dragster that
 allows you to drag a file over the dock icon for the app, at which
 point a menu of rows opens up form the app icon, and you can continue
 to drag the file over a particular row. I'd like to emulate that
 notion of dragging a file over the dock icon, then over a row in a
 menu presented from the icon.

I've never done this, but I think a good place to start would be with
the Dock Time Programming Guide:

https://developer.apple.com/library/mac/#documentation/Carbon/Conceptual/customizing_docktile/intro/dockintro.html#//apple_ref/doc/uid/TP3986-CH1-TP1

Maybe create a custom view for your dock tile then track the mouse
and/or drag events over it?
___

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: How to Identify a Phantom Write Operation

2012-09-05 Thread Stephen J. Butler
On Wed, Sep 5, 2012 at 1:51 PM, douglas welton
douglas_wel...@earthlink.net wrote:
 I reconfigured my code to load the cached copy of the user-selected movie 
 with the QTMovieResolveDataRefsAttribute set to NO.

 I don't get any new/additional messages sent to the console.  In your 
 experience, is this an indication that i am *not* writing to the source QT 
 file (via some mysterious effort to resolve the data reference)?

Does the file you're testing with contain external references? Maybe
your test file doesn't but Apple's does.
___

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: App memory

2012-08-16 Thread Stephen J. Butler
getrusage?

On Thu, Aug 16, 2012 at 9:39 AM, Charlie Dickman 3tothe...@comcast.net wrote:
 Is there a system command or any other way to get application memory stats 
 like vm_stat does for the whole system?

 Charlie Dickman
 3tothe...@comcast.net




 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: Where do these come from...

2012-08-15 Thread Stephen J. Butler
On Wed, Aug 15, 2012 at 10:20 AM, Charlie Dickman 3tothe...@comcast.net wrote:
 [[NSColor whiteColor] set];
 [die1 drawInRect: iDieDrawRect
   fromRect: imageRect1
  operation: NSCompositeSourceOver
   fraction: 1.0];
 [die2 drawInRect: jDieDrawRect
   fromRect: imageRect2
  operation: NSCompositeSourceOver
   fraction: 1.0];

Where are these being called from in your program? What's the context
of the surrounding code in the method?
___

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: Where do these come from...

2012-08-15 Thread Stephen J. Butler
On Wed, Aug 15, 2012 at 10:02 PM, Charlie Dickman 3tothe...@comcast.net wrote:
 Here's the whole method... it is being called from within a view's drawRect 
 method...

Are you calling drawRect directly from your code? If so, don't do
that. You should be sending one of the setNeedsDisplay messages, and
letting AppKit call drawRect for you.

With AppKit calling drawRect your lockFocus messages should not be needed.
___

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: Adding login items - who's right? The headers or the guide?

2012-07-29 Thread Stephen J. Butler
On Sun, Jul 29, 2012 at 6:09 PM, João Varela joaocvar...@gmail.com wrote:
 I would like to support the new way of adding login items by adopting the
 Services Management framework. As I I would like to support Snow Leopard I
 was quite pleased when I read that SMLoginItemSetEnabled function was
 available on OS X 10.6.6 and later. You can check it here:

 http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSy
 stemStartup/Chapters/CreatingLoginItems.html

 However, when I check the header documentation, it states that the very same
 function is available on OS X 10.7 and later. You can check it here:

 http://developer.apple.com/library/mac/#documentation/ServiceManagement/Refe
 rence/SMLoginItem_header_reference/Reference/reference.html#//apple_ref/doc/
 uid/TP40012446

 So, who's right? The guide or the headers? Does anyone know? I will file a
 bug, anyway, but it would help to know.

It's in the headers for the framework on my 10.6.8 system.

___

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: Getting NSApplicationDelegate protocol

2012-07-06 Thread Stephen J. Butler
On Fri, Jul 6, 2012 at 3:30 AM, ecir hana ecir.h...@gmail.com wrote:
 I'm trying to get the methods a protocol specifies and just stumbled upon
 one problem: the following code returns NULL:

 Protocol *protocol = objc_getProtocol(NSApplicationDelegate);

Are you trying this on 10.5? Or are you building this application with
the 10.5 SDK?

Before 10.6 the NSApplicationDelegate was an informal protocol (that
is, a category of methods on NSObject). This is because @optional
didn't appear till the 10.6 SDK/compiler and previous to that for
protocols:

1) all methods were mandatory
2) you couldn't extend the protocol later; once you publish it's set
of methods in a Framework you were fixed at that set

Point (2) follows from point (1) if you think about it enough.

So some of the protocols, like NSApplicationDelegate, weren't really
protocols at all. But in 10.6 they introduced @optional, and
NSApplicationDelegate became a formal protocol.
___

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: Getting NSApplicationDelegate protocol

2012-07-06 Thread Stephen J. Butler
On Fri, Jul 6, 2012 at 4:35 AM, ecir hana ecir.h...@gmail.com wrote:
 Sorry I should've said that before: no, I'm on 10.6.

 But thanks for the reply!

You're positive you're linking against the 10.6 SDK? Even if you're on
10.6 you might be linking against the 10.5 SDK and that would explain
your problem perfectly.

 On Fri, Jul 6, 2012 at 11:14 AM, Stephen J. Butler stephen.but...@gmail.com
 wrote:

 On Fri, Jul 6, 2012 at 3:30 AM, ecir hana ecir.h...@gmail.com wrote:
  I'm trying to get the methods a protocol specifies and just stumbled upon
  one problem: the following code returns NULL:
 
  Protocol *protocol = objc_getProtocol(NSApplicationDelegate);

 Are you trying this on 10.5? Or are you building this application with
 the 10.5 SDK?

 Before 10.6 the NSApplicationDelegate was an informal protocol (that
 is, a category of methods on NSObject). This is because @optional
 didn't appear till the 10.6 SDK/compiler and previous to that for
 protocols:

 1) all methods were mandatory
 2) you couldn't extend the protocol later; once you publish it's set
 of methods in a Framework you were fixed at that set

 Point (2) follows from point (1) if you think about it enough.

 So some of the protocols, like NSApplicationDelegate, weren't really
 protocols at all. But in 10.6 they introduced @optional, and
 NSApplicationDelegate became a formal protocol.

 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: How to know if a file has been opened before?

2012-06-05 Thread Stephen J. Butler
On Tue, Jun 5, 2012 at 3:14 AM, Antonio Nunes devli...@sintraworks.com wrote:
 On 5 Jun 2012, at 00:09, Stephen J. Butler wrote:

 You can use extended attributes to attach information to a file. Maybe
 serialize your session state as a plist and use setxattr/getxattr to
 manipulate it. Follows the file as it's moved around.

 Thanks Stephen,

 I think the extended attributes are pretty persistent though, they'll follow 
 the file around across to other computers, right? I wouldn't want that. I 
 only need the data on the particular user's system. Starting to look like l'm 
 probably better off devising my own scheme.

In general, yes. It won't follow if you upload to a website, say
Dropbox, and then someone else downloads it. But if you copy it to a
thumb drive and send it then it will.

One thing you could try is to mix the two ideas. Generate a GUID for
each file and store that in the extended attribute. Then use the GUID
to lookup your session information in an application CoreData store or
simple SQLite database.

Then only the GUID follows the file around, and on another machine it
won't have the session information and you can create it fresh. Also,
you'll have to handle the case when a file doesn't have a GUID in its
extended attributes and attach a new one.

___

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: How to know if a file has been opened before?

2012-06-04 Thread Stephen J. Butler
You can use extended attributes to attach information to a file. Maybe
serialize your session state as a plist and use setxattr/getxattr to
manipulate it. Follows the file as it's moved around.

PS: it's recommended that names for your attribute following the java
style reverse DNS. For example, Apple uses com.apple.FinderInfo

On Mon, Jun 4, 2012 at 5:50 PM, Antonio Nunes devli...@sintraworks.com wrote:
 I have implemented window state restauration in an app. This works fine for 
 re-opening documents that were open when the app was last quit. What I now 
 want to do is extend that functionality to files that were not necessarily 
 open when the app was last quit, but simply that have been opened at any time 
 before. I can't put state information into the files themselves, since they 
 are files that need to remain clean and that are not owned by my app.

 From what I've researched so far the window state restoration feature won't 
 extend the way I need it.

 I think NSURL's bookmarks feature could help out. I could create bookmark 
 data, and save it, and then later, when a file is opened, check the cached 
 bookmarkdata to see if one resolves to a URL that is equal to the url of the 
 just opened file. That should even work if the file is moved between 
 sessions. Is this the best way to do it though?

 The next question is, what is a handy way to keep track of the restoration 
 data that goes with the URL, since that will have to be saved separately from 
 the bookmark data. Using only the file name won't do, I need some kind of 
 unique ID, or a unique URL that can be derived from the bookmark data.  I 
 know I can think up a scheme, but I wonder if there is a proper way to do 
 this, like obtaining a unique file ID.

 -António

 
 A merry heart does good like medicine
 



 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: Sending a list of path strings to the Finder via Scripting Bridge

2012-05-26 Thread Stephen J. Butler
On Fri, May 25, 2012 at 1:56 AM, Peter magn...@web.de wrote:
 I'd like to reveal/select multiple items in the Finder.
 NSWorkspace only handles single files as in

            [[NSWorkspace sharedWorkspace] selectFile:currentFilePath
                             inFileViewerRootedAtPath:currentFilePath];

 I searched Google and tried to pick up every scrap of information on the 
 Scripting Bridge but I could not find anything about sending a LIST of paths.

If you want an example of some very dark magic, here's some code that
constructs an Apple Event and sends it to the Finder:

https://uofi.box.com/s/91ef71641b6eeffdfc29

I started out with MoreAppleEvents sample code, ripped out everything
that didn't make it to 64bit (bunch of FSSpec stuff and IconSuites),
then wrote a MoreFESetSelection() function because MoreAppleEvents
didn't think to include one.

It sends a kAESetData event to Finder for the pSelection property. It
passes the files in as a list of FSRefs.

___

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: In a modal pickle

2012-05-19 Thread Stephen J. Butler
On Sat, May 19, 2012 at 12:04 PM, NUExchange j.ay...@neu.edu wrote:
 I have a core data app that opens two windows when it starts up. One of the 
 two has a NSSearchField. The cursor is in search field and I can enter and 
 delete text, but any other operation on either of the windows causes the 
 screen to flash and the system beeps. This even happens when I hit Command-Q 
 to try to exit the app. Nothing appears in the GDB debugger and if I pause 
 the app in the debugger it's always in main. Any idea what could make it go 
 in such a mode?

Maybe there's an NSBeep() hiding somewhere in your code or a 3rd party
framework? It shouldn't be in the system frameworks, but it has
happened before.

Try setting a breakpoint on NSBeep.

___

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: Dissappearing string

2012-05-16 Thread Stephen J. Butler
On Wed, May 16, 2012 at 12:39 PM, Charlie Dickman 3tothe...@comcast.net wrote:
        possible[strlen(possible)] = '\0';

This can't possibly work. strlen() depends on the string already being
\0 terminated. You can't use strlen() to find the position to add a
\0.

___

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: Dissappearing string

2012-05-16 Thread Stephen J. Butler
On Wed, May 16, 2012 at 12:39 PM, Charlie Dickman 3tothe...@comcast.net wrote:
        NSString *possibleString = [NSString stringWithFormat: @%s, 
 possible];

... and this line is something you shouldn't do. There are a ton of
correct methods to create an NSString from a C string:

+stringWithCString:encoding:
+stringWithUTF8String:
-initWithBytes:length:encoding:
-initWithBytesNoCopy:length:encoding:freeWhenDone:
-initWithCString:encoding:
-initWithData:encoding:
-initWithUTF8String:

___

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: First Responder

2012-05-10 Thread Stephen J. Butler
On Thu, May 10, 2012 at 6:24 PM, koko k...@highrolls.net wrote:
 I have a menu item connected to an action in First Responder;

 The action exists in an NSView subclass.

 The subclass implements acceptsFirstResonder and return YES.

 The subclass implements validateMenuItem and return YES;

 When the menu displays the menu item is disabled (set to enabled in IB).

 Is this not the proper implementation?

Does your subclass implement the action that the menu item is looking
for? Your view subclass won't be chosen as the first responder if it
doesn't implement the action.
___

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: Problem parsing file in 64 bit build.

2012-05-07 Thread Stephen J. Butler
On Mon, May 7, 2012 at 8:06 AM, Charles Srstka cocoa...@charlessoft.com wrote:
 Myself, I like to just spin off a method or function that takes a chunk of 
 data and populates the fields of the struct one by one, instead of writing 
 the data straight onto the struct. A little more code, but you know it’s 
 going to work right without any surprises.

Not only that, but writing structs to file handles has caused security
problems before. Consider what happens if you have a short or byte
field and the compiler pads the struct. Now there's memory in your
struct that never gets initialized. If you write that to a file or
socket you're sending whatever might have been lurking there.
Passwords, login details...

___

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: inconsistent behavior of NSString's localizedCaseInsensitiveCompare

2012-05-05 Thread Stephen J. Butler
On Sat, May 5, 2012 at 4:46 PM, Markus Spoettl ms_li...@shiftoption.com wrote:
 On 05.05.12 23:07, Martin Wierschin wrote:

 So, when using a binary search, I get different answers depending on the
 other strings in the list!


 Seems to work for me:

I was using F-Script to investigate this, but I'm seeing the same
thing (locale: en_US):

# a := {'aaa', 'laso', 'lasso', 'zzz'}

# 'laßt' localizedCaseInsensitiveCompare:@a
{1, -1, 1, -1}

Interestingly enough...

# 'laßt' localizedCompare:@a
{1, 1, 1, -1}

So if there's a bug, it appears to be in localizedCaseInsensitiveCompare:

___

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: How do I get the hot spot from a .cur file in objective c on MAC Cocoa?

2012-03-31 Thread Stephen J. Butler
Wikipedia says that cur/ico files have a very simple format:

http://en.wikipedia.org/wiki/ICO_(file_format)

Part of the ICONDIRENTRY structure is the hotspot information. Should
be pretty easy to write a basic parser.

On Sun, Mar 25, 2012 at 4:25 AM, Oshrat Fahima oshr...@waves.com wrote:
 Hi
 In our plug-ins we are using cursors kept in a *.CUR file.
 In windows there's no problem to identify the hot spot from the *.CUR file 
 (because it's a WIN file, LoadCursor already knows where is the hot spot 
 automatically).
 But in MAC Cocoa, we've encountered a problem when we create a new NSCursor 
 object in which we must transfer the hot spot to it by calculating it and 
 maintaining it hard coded
 (we prefer not to do that).
 Are you familiar with a method that can help retrieve the hot spot from a 
 given *.CUR file?
 That way we can create the NSCursor directly using this point rather than 
 calculating it ourselves.

 Here's a sample of our code.
 Thanks a lot for your time and knowledge
 Oshrat


 NewCursor(const resContainerRef, const short cursorID, const WTPoint2s 
 hotSpotPoint)
 {
 WTCursorHandle retVal = 0;

      NSCursor* crsr = 0;
      wvFM::WCStPath imgPath;
      WTResType resType = Crsr;
      wvRM::GetPathToActualFile (resContainerRef, resType, cursorID, imgPath);

      NSString* imgPathAsNSString = 0;
      imgPathAsNSString = [NSString stringWithFormat:@%s, 
 imgPath.GetNativePathString().c_str()];

      NSImage * img = [[NSImage alloc]  :imgPathAsNSString];
      crsr = [[NSCursor alloc]initWithImage:img 
 hotSpot:NSMakePoint(hotSpotPoint.m_x,hotSpotPoint.m_y)];

 ___

 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/stephen.butler%40gmail.com

 This email sent to stephen.but...@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: drawRect using a Category

2012-03-30 Thread Stephen J. Butler
On Fri, Mar 30, 2012 at 10:31 PM, Peter Teeson ptee...@me.com wrote:
 Rather than using a sub-class, which seems overkill to me,
 I decided to try a Category instead. So here's what I did (and it seems to 
 work.)

The problem with this approach is that you've replaced the drawRect:
for every NSMatrix instance, everywhere, in your app. If some Cocoa
control is using NSMatrix, suddenly it's using your drawRect:. If you
decide to use NSMatrix somewhere else, it too is using this drawRect:.

I wouldn't trust this to be very stable. And I don't see how
subclassing is much more work than this.
___

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: [Q] Why is the threading and UI updating designed to be done only on a main thread?

2012-03-13 Thread Stephen J. Butler
On Tue, Mar 13, 2012 at 4:09 PM, JongAm Park jongamp...@sbcglobal.net wrote:
 In other words, the thread function may want to update UI like inserting a
 log message to a text field on a window and thus asking main thread to do
 so, and main thread is waiting to acquire a lock or waiting using Join,
 then either the main thread and the other thread can't progress.

You should really be rethinking your design if your main thread is
waiting on long held locks or waiting for threads to join. There are
ways around this, and the main thread shouldn't block long at all.
___

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: Finding object array index when iterating through array

2012-03-08 Thread Stephen J. Butler
On Tue, Mar 6, 2012 at 8:19 PM, Marco Tabini mtab...@me.com wrote:
 I have an array and I am iterating through it using this technique:

 for (id object in array) {
    // do something with object
 }

 Is there  way to obtain the object's current array index position or do I 
 have to add a counter?

 [array indexOfObject:object] should do the trick, though, if you need to do 
 it at every iteration, keeping a counter may be better.

Here's a stupid question that occurred to me: do the documents
anywhere guarantee that NSFastEnumeration over an NSArray will always
return the items in order? That is, the first item returned will have
index 0, second will have index 1, etc.

I feel like the safe thing in this situation is to just revert back to
an plain old for (;;;) loop. You know then that the index you have
is the one for the object.

___

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: Accessing array in thread safe way

2012-03-06 Thread Stephen J. Butler
On Tue, Mar 6, 2012 at 1:51 PM, Jan E. Schotsman jesc...@xs4all.nl wrote:
 I have an array of progress values (number objects) for subprojects, from
 which I calculate the overall progress .
 The array is an atomic property of the project class.

 Is it safe to access this array from multiple threads, using methods like
 objectAtIndex and replaceObjectAtIndex?

This is an NSMutableArray? No.

The atomic only means it's safe to access the *property* from multiple
threads. But it doesn't say anything about the thread safety of what
you do with the object stored in the property.

If you limit your array accesses to only the methods contained in
NSArray then things are okay. But as soon as you start mixing any
NSMutableArray methods the whole thing becomes unsafe (including those
previously safe NSArray methods).
___

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: initFileURLWithPath run on emulator, not run on device

2012-01-30 Thread Stephen J. Butler
On Mon, Jan 30, 2012 at 9:57 AM, Riccardo Barbetti
riccardo.barbe...@gmail.com wrote:
 I have a problem, after that I had write and test code on simulator, today I 
 have work on device.

I'm skeptical because...

 In my program I save my NSArray:


    NSArray *paths = 
 NSSearchPathForDirectoriesInDomains(NSSharedPublicDirectory, 
 NSUserDomainMask, YES);

    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSURL *URLDirectory = [[NSURL alloc] 
 initFileURLWithPath:documentsDirectory];

    BOOL result = [anArray writeToURL:URLDirectory atomically:YES];

... nowhere in this code do you add a filename to write to.

___

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: KVO willChange and didChange

2012-01-15 Thread Stephen J. Butler
On Mon, Jan 16, 2012 at 12:30 AM, Gideon King gid...@novamind.com wrote:
 Are there any recommendations on the best approach for being able to have the 
 setter able to do what it needs with the KVO and then calling other methods, 
 without breaking bindings?

 I can't believe I have misunderstood this for so long, and never noticed what 
 was happening until now!

From the KVO programming guide, Manual Change Notification:

http://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/KeyValueObserving/Articles/KVOCompliance.html#//apple_ref/doc/uid/20002178-SW3
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Carousel - like control for Mac OS

2011-12-21 Thread Stephen J. Butler
On Tue, Dec 20, 2011 at 3:00 PM, Nick eveningn...@gmail.com wrote:
 Hello
 I am wondering, if a component exists similar to this
 http://www.ajaxdaddy.com/demo-jquery-carousel.html
 for Mac OS.

 Basically, what I need is just next and previous buttons (and
 these images smoothly scrolled one image per next or prev button
 click).

This is an awful lot like the coverflow animation/display. Are you
sure that coverflow wouldn't be more appropriate for OS X?
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Locks

2011-12-06 Thread Stephen J. Butler
On Tue, Dec 6, 2011 at 9:07 PM, koko k...@highrolls.net wrote:
 I did come across OSAtomicIncrementXX … thanks.

 I cannot use NSLock as this is in a BSD Static lib and I am required to 
 implement as close to windows as possible.

 So my code looks like below and is isomorphic to the Windows implementation.

This code doesn't work.

 =
 LONG volatile Mylock = 0;

 void SetLock()
 {
        while(Mylock){Sleep(0);};               // Give up timeslice
 #ifndef MAC
        InterlockedIncrement(Mylock);
 #else
        OSAtomicIncrement32(Mylock);
 #endif
 }

There is a race condition between your test and set/increment
operations. If two threads are spinning on the same variable then they
could both see 0 at the same time, and your Mylock ends up with 2.

You probably didn't see this race condition on Windows because you
entered a critical section. Which begs the question, if you remain
inside the critical section the entire time you're locked, what's the
point of doing the spinning? Only one person can be inside a critical
section at one time anyway.

I'm guessing someone added the critical sections because they ran into
this race condition and didn't understand enough about multithreaded
programing to fix it.

On OS X you want to spin on the return value
OSAtomicCompareAndSwap32(0, 1, Mylock).

Actually, what you really want is to rewrite this code using proper
mutexes. Spin locking is only acceptable in highly, highly critical
paths and when you don't expect the lock to be held for more than a
couple instructions. Otherwise it's damn unfriendly.

 void FreeLock()
 {
 #ifndef MAC
        OSInterlockedDecrement(Mylock);
 #else
        OSAtomicDecrement32(Mylock);
 #endif
 }
 ===





 Thanks.

 -koko



 On Dec 6, 2011, at 5:39 PM, Conrad Shultz wrote:

 On 12/6/11 3:28 PM, koko wrote:
 In windows we have:

 LONG volatile Mylock = 0;
 InterlockedIncrement(Mylock);
 InterlockedDecrement(Mylock);


 What should these be replaced with for OSX  as in :

 Have you read the Threading Programming Guide?

 I'm not a Windows developer, so I had to look up the MSDN docs, and
 based on those it seems like you want the OSAtomicIncrementxxx (and
 matching OSAtomicDecrementxxx) as direct analogues.

 However, since it sounds like you are trying to use these functions to
 implement locking in a multithreaded application, perhaps you should
 also examine whether higher level constructs would prove sufficient.  A
 couple such mechanisms you can read about are NSLock and the
 @synchronized directive.  GCD has some features (dispatch semaphores and
 barrier blocks come to mind) that may also be helpful in certain
 circumstances.

 --
 Conrad Shultz

 Synthetiq Solutions
 www.synthetiqsolutions.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:
 http://lists.apple.com/mailman/options/cocoa-dev/stephen.butler%40gmail.com

 This email sent to stephen.but...@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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Validating dictionary strings file

2011-11-20 Thread Stephen J. Butler
On Sun, Nov 20, 2011 at 11:33 PM, Gideon King gid...@novamind.com wrote:
 Clearly there is some formatting error in the file but it is a rather large 
 file and would take a very long time to manually go through and find the 
 issue - is there some tool available that will tell me where to look in the 
 file for the error?

I don't know that grep understands UTF-16, but this seems like a
problem that a well written regexp could solve.

grep -Pv '^((\s*)|(/\*.*\*/)|(.*;))\s*$' MyFile.strings

Adjust as needed. Maybe quickly convert the file to UTF-8 if grep
chokes on UTF-16.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: -dateWithTimeIntervalSinceNow: 64-bits may overflow

2011-10-09 Thread Stephen J. Butler
On Sun, Oct 9, 2011 at 1:51 PM, Jerry Krinock je...@ieee.org wrote:

 On 2011 Oct 08, at 21:12, Stephen J. Butler wrote:

 What's wrong with +[NSDate distantFuture]?

 Nothing.  It's only [NSDate -dateWithTimeIntervalSinceNow:FLT_MAX] which 
 sometimes gives unexpected results.

It's not, at least not on 10.6 with Xcode 3.2.5. This program...


#import Foundation/Foundation.h

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSLog( @distantFuture: %@, [NSDate distantFuture] );
NSLog( @FLT_MAX: %@, [NSDate dateWithTimeIntervalSinceNow:FLT_MAX] );

[pool drain];
return 0;
}


Gives the output (in 32 and 64 bit):


2011-10-09 14:46:41.639 Untitled[60937:a0f] distantFuture: 4000-12-31
18:00:00 -0600
2011-10-09 14:46:41.640 Untitled[60937:a0f] FLT_MAX: 5828963-12-19
18:00:00 -0600

I think you'll find distantFuture much less buggy than your solution,
seeing as how it isn't going to overflow or run into boundary
situations.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Mystery of the missing symbol

2011-10-02 Thread Stephen J. Butler
On Sun, Oct 2, 2011 at 7:50 PM, Graham Cox graham@bigpond.com wrote:
 A user is reporting this error logged to the console when trying to load a 
 plug-in bundle (an iTunes visualizer):

 dlopen(path to plug-in): Symbol not found: __NSConcreteStackBlock
  Referenced from:path to plug-in executable
  Expected in: /usr/lib/libSystem.B.dylib


 The plug-in is built against the 10.7 SDK with a minimum deployment target of 
 10.5 (however, I've only tested it on 10.6 and 10.7). The user has version 
 10.5.8, so I'm guessing that this private class isn't available there.

 Apparently this is a private member of a class cluster (which class, I do not 
 know), so I'm not invoking it directly. With a deployment target of 10.5, 
 shouldn't the linker or compiler complain at some point? What should I be 
 looking for?

Is this user running the app as 64bit? I seem to remember that 64bit
Cocoa wasn't really finalized till 10.6 and some classes moved between
libraries.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Task dispatching

2011-09-13 Thread Stephen J. Butler
On Tue, Sep 13, 2011 at 1:36 PM, Scott Ribe scott_r...@elevated-dev.com wrote:
 On Sep 13, 2011, at 12:23 PM, Jens Alfke wrote:
  The forked process is an exact clone of the original, with its address 
 space copy-on-write, so it’s already up and running without any startup time.

 Yeah, but about the only thing you can do in that forked process is exec a 
 new image over it. This is not a technique for memory sharing.

Assuming you stay away from Frameworks that forbid forking (Cocoa,
mach ports, etc) the only remaining issue I'm aware of is threading.
That is because IIRC threads other than the forking one don't survive:
they are immediately killed in the child. If they happened to be
holding any locks, say in malloc, then you'll deadlock easily.

But if you also aren't using threading then you'll be OK. Really,
threading and forking are two different paradigms and you shouldn't be
mixing them anyway.

Programs like postgres run just fine in OS X and they rely heavily on forking.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Custom universal types, but outside an application

2011-09-08 Thread Stephen J. Butler
On Thu, Sep 8, 2011 at 3:21 PM,  dvlc...@gmail.com wrote:
 My problem: this type is not actually defined and used by an
 application, but by a preference pane. It seems that putting the proper
 entries in the preference pane's Info.plist doesn't work (or am I
 missing something ?).

What you're missing, I think, is that LaunchServices doesn't scan
preference panes for types.

Shot in the dark, but looking at LSInfo.h it seems LSRegisterURL (with
your bundle URL) might work:


/*
 *  LSRegisterURL()
 *
 *  Discussion:
 *If the specified URL refers to an application or other bundle
 *claiming to handle documents or URLs, add the bundle's document
 *and URL claims to the Launch Services database.
 *

However, the ADC documentation says something slightly different:

A Core Foundation URL reference designating the application to be
registered; see the CFURL Reference in the Core Foundation Reference
Documentation for a description of the CFURLRef data type. The URL
must have scheme file and contain a valid path to an application file
or application bundle.

So you take your chances!

BTW, is a preference pane actually able to handle stuff like the
'oapp' or 'rapp' events? Seems to me that System Preferences.app would
receive those and just ignore it.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: NSTask vmrun

2011-08-05 Thread Stephen J. Butler
On Fri, Aug 5, 2011 at 10:15 PM, Rainer Standke li...@standke.com wrote:
 args: (
    -T fusion,
    -gu Administrator,
    -gp Admin,
    runScriptInGuest,
    \/Users/rainer/Documents/Virtual Machines.localized/Windows XP 
 Professional v1.vmwarevm/Windows XP Professional v1.vmx\,
    ,
    start http://apple.com;
 )

 None of the many variations I have tried have worked.

Ever worked with argv? Know how argv[1] would be -T and argv[2]
would be fusion, etc? That's the type of thing you have to build on
this side. So, args are:

-T,
fusion,
-gu,
Administration,
-gp,
Admin,
runScriptInGuest,
/Users/rainer/Documents/Virtual Machines.localized/Windows XP
Professional v1.vmwarevm/Windows XP Professional v1.vmx,
-noWait,
,
start http://apple.com;

No shell escapes. Just what you would have to escape for a normal
C/Obj-C string (\, \\, etc). There's no reason to do shell escapes
since you aren't involving the shell here. Don't escape spaces, put
things in quotes, or escape $, etc.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Symbol not found when compiling MM (ObjC++) file

2011-08-05 Thread Stephen J. Butler
On Fri, Aug 5, 2011 at 9:57 AM, Alexander Hartner a...@j2anywhere.com wrote:
 Now when I import Logger.h and use it from a Objective C (.m) file everything 
 seems to work great. However as soon I as import it and use it from a 
 Objective C++ (.mm) file I get the following link error:

 Ld [REMOVED] normal i386
 setenv MACOSX_DEPLOYMENT_TARGET 10.4
 /Developer/usr/bin/g++-4.0 -arch i386 -dynamiclib -isysroot 
 /Developer/SDKs/MacOSX10.4u.sdk -L[REMOVED]/Release -F[REMOVED]/Release 
 -filelist [REMOVED].LinkFileList -install_name [REMOVED] 
 -mmacosx-version-min=10.4 -framework Foundation -framework Cocoa -framework 
 SyncServices -framework Foundation -framework IOKit -lcrypto.0.9.7 
 -lssl.0.9.7 -single_module -compatibility_version 1 -current_version 9 -o 
 [REMOVED]

 Undefined symbols:
  ABSLog(NSString*, ...), referenced from:
      -[SoapAdaptor initWithPreferences:] in SoapAdaptor.o
 ld: symbol(s) not found
 collect2: ld returned 1 exit status

http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html#faq-32.3

Basically, the C++ compiler thinks ABSLog is a C++ function, and it's
undergoing name mangling. So what you have to do is tell the C++
compiler that ABSLog is a C function with extern C { stuff }
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Running Cocoa from a dynamic library

2011-07-28 Thread Stephen J. Butler
On Thu, Jul 28, 2011 at 1:14 PM, Jens Alfke j...@mooseyard.com wrote:
 On Jul 27, 2011, at 8:02 AM, Guido Sales Calvano wrote:

 Ogre3D however, uses a cocoa window to render on, and obviously I want user
 input. But if I start ogre in a dynamic library ui events register 
 incorrectly.

 It’s not the fact that it’s in a dynamic library that causes trouble (for 
 example, all system frameworks are in dynamic libraries!) It’s the fact that 
 you’re starting a generic Unix process (node.js server) and then trying to 
 turn it into a GUI app by calling AppKit in it, without going through the 
 usual AppKit initialization (NSApplicationMain). However, I don’t think 
 calling NSApplicationMain is the right thing for you to do, because (a) it 
 expects to be the first thing called when the process starts, and (b) it will 
 take over the main thread.

 I know that this can be done, though I don’t know the details of how. But 
 hopefully this will get you looking closer to the right place, or nudge 
 people who do know more to provide some answers.


NSApplicationLoad()?  Although that's meant to be called from Carbon
applications. I don't know that command line applications will work at
all.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: drawRect not getting called when needed under OS X

2011-07-24 Thread Stephen J. Butler
On Sat, Jul 23, 2011 at 11:33 PM, Tom Jeffries tjeffries@gmail.com wrote:
 When I run the code that displays the graphics in question on initialization
 it works fine, but when I call it later in the program it the new graphics
 are not displayed.  The code in the graphics module that displays the window
 is working perfectly, but somehow drawRect never gets called after it is
 called during initialization.

Just to be clear, you're doing one of these two things:

1) all of your drawing *inside the drawRect:* of your subclass.

2) all of your drawing to some sort of temporary context, then copying
it *inside the drawRect:* of your subclass.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: NSTask oddity with getting stdout

2011-07-24 Thread Stephen J. Butler
On Sun, Jul 24, 2011 at 10:17 PM, Scott Ribe
scott_r...@elevated-dev.com wrote:
 I'm using NSTask to run a background process, monitor its output, and 
 ultimately present a message to the user. All has been fine with this 10.2 
 through 10.6, as far as I know. Now under 10.7 I saw a case where my code did 
 not receive quite all the stdout output from the background process. I saw 
 this once; I haven't tried running it a huge number of times, but it is 
 definitely not the common case. (And I've never seen it in dev mode running 
 under the debugger, only on a machine without dev tools. Also BTW, the output 
 of the bg process is plain ASCII, no worries about multi-byte sequences.) 
 Does anybody see anything wrong with this code (severely stripped for 
 legibility):

Interesting. THIS IS JUST ME SPECULATING OUT LOUD. I wonder if they've
changed how the readInBackgroundAndNotify works. In particular, my
guess here would be that:

1) Two threads are created to handle the stdout and stderr (may be
dispatch queues, but let's say threads for this thought experiment).

2) Your task generates output in stdout, and most of it gets consumed.

3) Your task generates its last data and closes its stderr then stdout.

4) The stdout thread reads the last data and readies a notification,
but doesn't get a chance to post it before being swapped.

5) The stderr thread sees a closed socket and posts a notification
before being swapped.

6) The stdout thread wakes up, and posts its notification.

Now you are in a situation where there are two notifications being
delivered, and their order is wrong for your code. Namely, when the
stderr notification arrives first you will do this:

a) see that stderr is closed.
b) try to read all the remaining data from stdout. There is none,
because it has been queued already.
c) remove yourself as a listener for stdout.
d) try to read all the remaining data from stderr.
e) remove yourself as a listener for stderr.

The problem is step (c)! There might be data in the notification queue
that you will never receive.

Here's how I'd write your methods:

 - (void) doSomeTask: (NSTask *) task

Same.

 - (void) processStdOut: (NSNotification *) ntc
 {
        NSFileHandle *f = [ntc object];
        NSData *d = [[ntc userInfo] objectForKey: 
 NSFileHandleNotificationDataItem];

        if( [d length] == 0 )
{
        [[NSNotificationCenter defaultCenter]
                removeObserver: self
                name: NSFileHandleReadCompletionNotification
                object: curStdOut];

        curStdOut = nil;
}
        else
        {
                [f readInBackgroundAndNotify];
                [curStdOutStr appendString:
                        [[[NSString alloc] initWithData: d encoding: 
 NSASCIIStringEncoding] autorelease]];
        }
 }


 - (void) processStdErr: (NSNotification *) ntc
 {
        NSFileHandle *f = [ntc object];
        NSData *d = [[ntc userInfo] objectForKey: 
 NSFileHandleNotificationDataItem];

        if( [d length] == 0 )
{
        [[NSNotificationCenter defaultCenter]
                removeObserver: self
                name: NSFileHandleReadCompletionNotification
                object: curStdErr];

        curStdErr = nil;
}
        else
        {
                [f readInBackgroundAndNotify];
                [curStdErrStr appendString:
                        [[[NSString alloc] initWithData: d encoding: 
 NSASCIIStringEncoding] autorelease]];
        }
 }

That is, abandon processPipeClose and let each pipe handle its own
close in the notification when you're sure all of its read
notifications have actually been delivered. As you've presented it,
processPipeClose isn't needed.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Writing global preferences file into /Library/Preferences (OS X Lion)

2011-07-20 Thread Stephen J. Butler
On Wed, Jul 20, 2011 at 8:31 PM, Peter C peterchan...@gmail.com wrote:
 Some of the programs I wrote save a preference file into /Library/Preferences 
 via NSDictionary. This serves as a general settings for all users. Many other 
 3rd party software (Skype, Microsoft and etc) saves preferences file into 
 this directory too. This works from 10.0 to 10.6.

It was a bad design decision to assume you could ever write to this
directory. What if your user isn't running as admin?

The way to solve this issue is to use the BetterAuthorizationSample library:

http://developer.apple.com/library/mac/#samplecode/BetterAuthorizationSample/Introduction/Intro.html#//apple_ref/doc/uid/DTS10004207-Intro-DontLinkElementID_2

Basically, you write a helper tool that runs as root, and comunicate
with it what settings get what values. Then the helper tool, as root,
saves the plist.

Read and understand all the included txt files before you just dive
into the code!
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: getting last accessed date

2011-07-07 Thread Stephen J. Butler
On Fri, Jul 8, 2011 at 12:31 AM, Scott Ribe scott_r...@elevated-dev.com wrote:
 On Jul 7, 2011, at 11:19 PM, Rick C. wrote:

 One more note, seems in terminal stat aFile works so I suppose I could use 
 nstask to do this as well?

 It does seem odd that the two would produce different results...

They don't, at least not in my test. For all six loops of a given file
this code gives the same output:


#include sys/stat.h
#include stdio.h
#include unistd.h

#import Foundation/Foundation.h

int main( int argc, char **argv )
{
struct stat st;
int i;

for (i = 0; i  3; ++i)
{
if (stat( argv[1], st ) != 0)
return 1;
printf( %s #%d atime = %d\n, argv[1], i, 
st.st_atimespec.tv_sec );
sleep( 10 );
}

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *file = [NSString stringWithUTF8String:argv[1]];

for (i = 0; i  3; ++i)
{
if (stat( [file fileSystemRepresentation], st ) != 0)
return 1;
printf( %s #%d atime = %d\n, argv[1], i, 
st.st_atimespec.tv_sec );
sleep( 10 );
}

[pool drain];

return 0;
}

I was testing the Obj-C version just in case fileSystemRepresentation
was in some odd way changing the atime.

I think something else in your code is going wrong. Are you asking
Launch Services for an icon or anything like that?
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Why Wasn't Memory Collected?

2011-06-11 Thread Stephen J. Butler
On Sat, Jun 11, 2011 at 1:03 PM, Bing Li lbl...@gmail.com wrote:
        NSData *data = [xmlDoc XMLData];
        NSString *xmlStr = [[[NSString alloc] initWithData:data
 encoding:NSUTF8StringEncoding] autorelease];
        xmlStr = [xmlStr stringByAppendingString:@\n];
        const char *xmlChar = [xmlStr UTF8String];

        [xmlDoc release];
        return xmlChar;
 }

If you're using your own autorelease pools now, be careful about the
lifetime of your return value (xmlChar)! It will only live as long as
xmlStr lives. For example, this would be incorrect:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
const char *str = [self createSendMessage:...];
[pool release];
// do something with str

You'll want to strdup() the return value to make sure it lives after
the pool is released, but then you also need to remember to free()
your strdup() value.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: How can logging a pointer value cause EXC_BAD_ACCESS?

2011-05-29 Thread Stephen J. Butler
On Sun, May 29, 2011 at 1:30 PM, Jerry Krinock je...@ieee.org wrote:
 I'm really losing it; or maybe I never understood to begin with.  How can 
 this code crash?

      - (void)dealloc
      {
          NSLog(@0988 %p %s, self, __PRETTY_FUNCTION__) ;
          NSLog(@1250 ) ;
 CRASH-   int myPointer = (int)m_managedObjectContext ;
          NSLog(@1335 myPointer = %d, myPointer) ;
          ...
      }

 stderr output:

 0988 0x0 -[SSYMojo dealloc]
 1250
 Program received signal:  “EXC_BAD_ACCESS”

This is HIGHLY suspicious. Look at your first line, dealloc is somehow
getting sent to a nil self. I have no idea how you'd end up in such a
situation. For one, you never call dealloc yourself in code unless
it's [super dealloc]. Number two, Obj-C short circuits messages to
nil objects: they aren't even called.

The crash happens because m_managedObjectContext is an instance
variable (I assume), and there's an implied dereference of self (that
is, it's really self-m_managedObjectContext). Since self is nil,
you're dereferencing NULL and you get a segfault.

So the crash is the logical conclusion of dealloc being called on a
nil object. But I have zero ideas how you even got to that situation
in the first place.

 The line marked CRASH- is highlighted in blue by Xcode/gdb.  How can this 
 crash?  I wanted to log the pointer value (and it *is* an 'int' since this is 
 32-bit).  To emphasize this, I assigned it to an int, and it still crashes.  
 I thought that EXC_BAD_ACCESS can only occur if you *access* memory.

 Of course, m_managedObjectContext is declared as a pointer to an object in 
 the @interface,

 NSManagedObjectContext* m_managedObjectContext ;

 I've never seen this happen before.  I know the format specifier %@ can evoke 
 a crash because it sends a -description message.  But not %p or %x or %d.

 Just to prove that gravity still pulls downward, I tried this:

 NSManagedObjectContext* x = (void*)3 ;
 // Certainly 0x3 is not in my memory space!
 NSLog(@Hello) ;
 NSLog(@x=%d, (int)x) ;
 int y = (int)x ;
 NSLog(@World) ;
 NSLog(@y=%d, y) ;

 stderr output:

 Hello
 x=3
 World
 y=3

 No crash, as expected!

 What might be the difference between this and my -dealloc method?

 Jerry

 ___

 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:
 http://lists.apple.com/mailman/options/cocoa-dev/stephen.butler%40gmail.com

 This email sent to stephen.but...@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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: A Simple NSXML XPath Problem

2011-05-28 Thread Stephen J. Butler
On Sat, May 28, 2011 at 9:40 PM, Bing Li lbl...@gmail.com wrote:
 The XML is pretty simple.

    ?xml version=1.0 encoding=UTF-8?
    addresses
        roadOrange ST/road
        aptRM235/apt
    /addresses

 The following code is use to extract the value of the road, Orange ST. In
 Java, the XPath is the same, i.e., /addresses/road.

You're selecting the road node which happens to contain a text node
with the value you want. That Java and Cocoa return different strings
when asked isn't a bug because what a toString()/description returns
isn't in a spec.

If you want the text node, you should be selecting:

/addresses/road/text()
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: What's wrong with this?

2011-05-28 Thread Stephen J. Butler
On Sat, May 28, 2011 at 11:29 PM, Graham Cox graham@bigpond.com wrote:
 #import UIKit/UIKit.h

 @class SGBoard;         //-- error: Expected '{' before 'class'

 @interface GameViewController : UIViewController
 {
        IBOutlet UIView*                mGameView;
        IBOutlet SGBoard*       mBoard;
 }


 - (SGBoard*)            board;

 @end



 This is occurring on one header file out of many which have exactly the same 
 import and forward class declaration, but this one just won't compile. I've 
 tried deleting the text and starting over in case it was a rogue hidden 
 character, but to no avail. What's going on here?

Header files don't get compiled. They get included into source files
which then get compiled. What's the name of the source file that
includes this when you get the error? Does it have an .m or .mm
extension? What file is included just before this one? Because of how
files get included sometimes an error in a previous header file can
manifest in a subsequent header (such as a missing '}' or ';')
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: How to implement while there are objects in the array - run runloop idea?

2011-05-26 Thread Stephen J. Butler
On Thu, May 26, 2011 at 12:56 PM, Nick eveningn...@gmail.com wrote:
 I have a custom (not main) thread, that adds objects to an NSArray at random
 times.
 I have an another thread (main thread) that has to retrieve these objects
 and do something with them (extract some properties from the retrieved
 object and make an NSURLConnection's asynchronous connection).

How are you synchronizing access to the shared array? Lock objects?

You might want to abandon that approach and not add objects from the
background thread directly to the shared array. Instead, you could
signal the main thread that a new object is ready to be processed.
Some common methods:

- Distributed Objects/NSConnection. The main thread would be your
server and your background thread the client. The client would call
something like [proxy processObject:blah] and the main thread would
perform the action.

- Use mach pipes to pass objects to the main thread. mach pipes can be
added as a source to the runloop. Either serialize and pass the object
over the pipe itself, or (since you are in the same address space)
just pass a token single byte message over the pipe to notify the main
thread that a new object has been added to the array to be processed.

- Use NSObject's performSelectorOnMainThread:withObject:waitUntilDone
to message the main thread directly from the background thread and
hand off the new object to be processed. Or you could still add the
object to the shared array and use
performSelectorOnMainThread:withObject:waitUntilDone to notify the
main thread.

- Use NSNotifications to notify that a new object is waiting to be
processed. If you go this route, you could actually have multiple
processing threads all listening for the notification.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: How to implement while there are objects in the array - run runloop idea?

2011-05-26 Thread Stephen J. Butler
On Thu, May 26, 2011 at 1:35 PM, Stephen J. Butler
stephen.but...@gmail.com wrote:
 You might want to abandon that approach and not add objects from the
 background thread directly to the shared array. Instead, you could
 signal the main thread that a new object is ready to be processed.
 Some common methods:

- Just thought of this: blocks and dispatch queues. There's a special
one just for the main thread. I suppose this is the most modern way to
do it!
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Use them from only one thread at a time

2011-05-19 Thread Stephen J. Butler
On Thu, May 19, 2011 at 3:56 PM, Sean McBride s...@rogue-research.com wrote:
 On Thu, 19 May 2011 13:22:32 -0700, Jerry Krinock said:

Thread-Unsafe Classes.  The following classes and functions are
generally not thread-safe. In most cases, you can use these classes from
any thread as long as you use them from only one thread at a time.

I'm confused by the second sentence.

 Indeed.  Surely they don't mean that.

Surely they do mean that, and people do it all the time. The key is to
use locks to synchronize your access. For example, an
NSMutableDictionary is thread unsafe. But if you do this:

@synchronize (myDict) {
  // read and write operations
}

Then it is OK to access myDict from multiple threads. But because of
the @synchronize, only one thread can be using it at a time.

Note: read operations on many container classes are thread safe. BUT
only if the class cannot be written to. If you are doing to both read
and mutate a class, then all operations (read and mutate) need to be
safe. You could do something like this:

NSMutableDictionary *myDict = [NSMutableDictionary dictionary];

// write to myDict

// spawn a bunch of worker threads that only read from myDict

// wait for all threads to complete

// write some more to myDict
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Read-Write Lock is Available?

2011-05-12 Thread Stephen J. Butler
On Thu, May 12, 2011 at 12:44 PM, Bing Li lbl...@gmail.com wrote:
 I am writing concurrent code. I get used to the read-write lock on other
 development environment. However, according to the Threading Programming
 Guide from apple.com, Cocoa does not support the read-write lock? We can use
 it with POSIX threads? Is that true?

It is safe to use POSIX threads RW locks with Cocoa threads.

man pthread_rwlock_init
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: @selector signature with two colons instead of actual message name

2011-05-03 Thread Stephen J. Butler
On Tue, May 3, 2011 at 8:49 PM,  davel...@mac.com wrote:
 - (void)noEmailAlertDidEnd:(NSAlert*) returnCode:(NSInteger)retCode 
 contextInfo:(void*)ctxInfo {

See it now?

- (void)noEmailAlertDidEnd:(NSAlert*) returnCode
  :(NSInteger)retCode
  contextInfo:(void*)ctxInfo

It's using 'returnCode' as the first variable to the message
(NSAlert*). And then it sees 'retCode' as a variable without a
parameter name.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Xcode 4 auto-importing Objective C categories from static library

2011-04-23 Thread Stephen J. Butler
On Sat, Apr 23, 2011 at 3:36 PM, Bradley S. O'Hearne
br...@bighillsoftware.com wrote:
 Since transitioning to Xcode 4, I have discovered a very curious shift in the 
 way Objective C categories are handled in static libraries. In general, if 
 you create an Objective C category, you have to import that category into an 
 implementation (.m) class in order for that category's additions to be 
 visible and used. That worked great in Xcode 3, as you can control what 
 categories methods appear wherever by merits of using the import (or not). 
 However, in Xcode 4, all categories defined in a static library used in a 
 dependent project are by definition visible, even if not imported.

It's always been this way at runtime. When a category is loaded it
changes the behavior of all instances of a class that it modifies, no
ifs/ands/buts. It's loaded by the DYLD, and that has no concept of
your imports/includes. From the Obj-C docs:

Category methods can do anything that methods defined in the class
proper can do. At runtime, there’s no difference. The methods the
category adds to the class are inherited by all the class’s
subclasses, just like other methods.

Now the tools, on the other hand, were less smart in Xcode3 and below.
Autocomplete, IB message browser, etc only knew about the
messages/properties visible to the immediate code block (via import,
include, etc). That Apple has fixed this in Xcode 4 to better match
reality is a GOOD THING.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: NSString midstring()

2011-04-17 Thread Stephen J. Butler
On Sun, Apr 17, 2011 at 4:08 PM, JAMES ROGERS jimrogers_w4...@me.com wrote:
 I have stepped this through with the debugger and no flags were raised. The 
 code compiles without an error or a warning of any kind. I am afraid your 
 response has overwhelmed me.

You didn't see it in the debugger because you aren't using the right
kind of test data. Look at this example:

#import Foundation/Foundation.h

#define BUFFER_SIZE 65
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSString *str1 = @временный;
NSString *str2 = nil;
char buffer[BUFFER_SIZE + 1];
int i, count;

count = MIN( [str1 length], BUFFER_SIZE );
for (i = 0; i  count; i++)
buffer[i] = [str1 characterAtIndex:i];
buffer[i] = 0x00;

str2 = [NSString stringWithUTF8String:buffer];
NSLog( @str1 = %@, str1 );
NSLog( @str2 = %@, str2 );

[pool drain];
return 0;
}

This does not at all correctly copy the string. Also, while writing up
the example, I noticed you have a buffer overflow error. At the end of
the loop, j == 65 and the last index in your buffer is 64.

Now, compare with this example:

#import Foundation/Foundation.h

#define BUFFER_SIZE 5
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSString *str1 = @временный;
NSString *str2 = nil;
char buffer[BUFFER_SIZE];
NSUInteger i = 0, bufferLength;
NSRange askRange, leftRange;

NSLog( @str1 = %@, str1 );
while (i  [str1 length])
{
askRange = NSMakeRange( i, [str1 length] - i );
if (![str1 getBytes:buffer
  maxLength:BUFFER_SIZE
 usedLength:bufferLength
   encoding:NSUTF8StringEncoding
options:0
  range:askRange
 remainingRange:leftRange])
{
NSLog( @error: no characters to convert );
break;
}

str2 = [[[NSString alloc] initWithBytes:buffer
length:bufferLength encoding:NSUTF8StringEncoding] autorelease];
NSLog( @str2 = %@ (%d:%d), str2, bufferLength, [str2 length] );

i = leftRange.location;
}

[pool drain];
return 0;
}

Notice how that even though the buffer is large enough to hold one
more 'character',
getBytes:maxLength:usedLength:encoding:options:range:remainingRange:
doesn't fill it because that would make the buffer contain an invalid
UTF8 character sequence.

 The substring = [NSString stringWithUTF8String:sndBuffer] was not my own 
 and came from a website as a result of my query on C string to NSString and 
 it works.

You should be very careful about copying code from another website
that you don't understand.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Strange property/synthesized accessor behaviour

2011-04-10 Thread Stephen J. Butler
On Sat, Apr 9, 2011 at 9:52 AM, Philipp Leusmann m...@byteshift.eu wrote:
 Who can explain this behavior to me? Why is oWidth != object.mWidth ? How can 
 that happen?

It's an artifact of how Objective-C searches for selector
implementations. You're calling @selector(width) on an id, and of
course id doesn't implement @selector(width).

So what Objective-C does is search for the first implementation of
@selector(width) that it finds. My guess is it finds the one in AppKit
first (greping the frameworks):

NSTableColumn.h:- (CGFloat)width;

Then when the compiler sets up the call site it does it expecting a
CGFloat return and that is handled differently than an integer. So the
call site and the implementation of how your width is done disagree
and you get some strange heisenvalue back.

When you cast the variable to Result*, Objective-C now knows to use
YOUR implementation of @selector(width) and it sets up the call site
properly.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: NSString, stringByAppendingPathComponent, and Canonicalization

2011-04-04 Thread Stephen J. Butler
On Mon, Apr 4, 2011 at 10:08 PM, Jeffrey Walton noloa...@gmail.com wrote:
 I need to accept a filename from the user. Given the user supplied
 filename, I form a fully qualified name:

 NSString* pathName = [NSHomeDirectory(),
 stringByAppendingPathComponent:@Documents];
 NSString* fullPathName = [pathName  stringByAppendingPathComponent:filename];

First, you should be getting the path to the documents folder via
NSSearchPathForDirectoriesInDomains():

http://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/LowLevelFileMgmt/Articles/StandardDirectories.html#//apple_ref/doc/uid/20001279-SW5

 How do I canonicalize the the resulting fullPathName to verify there
 was no directory traversal goodness in the filename? In case its
 relevant, the platform is iOS.

I can't remember if there's a Cocoa version, but the standard Unix way
to do this is realpath (man realpath). Make sure to use -[NSString
fileSystemRepresentation] to get the char* version.

But I'm not sure directory traversals are a huge concern in iOS.
Everything is so sandboxed anyway...
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Programming Context Menu

2011-04-04 Thread Stephen J. Butler
On Tue, Apr 5, 2011 at 12:10 AM, Chris Hanson c...@me.com wrote:
 On Apr 4, 2011, at 12:38 PM, Bing Li lbl...@gmail.com wrote:

        if (nil == defaultMenu)
        {
                @synchronized(self)
                {
                        if (nil == defaultMenu)

 Don't do this. I don't mean just in Cocoa either, I mean don't do it ever. 
 It's an anti-pattern called double-checked locking and it's fatally broken 
 under most languages' memory models.

 If you want to initialize a value once-and-only-once, use dispatch_once or 
 (if you need to support an OS version without GCD) use pthread_once.

It's also worth pointing out that NSMenu is not thread safe, and
should never be accessed off the main thread. So the locking is
pointless anyway!
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: OCTET_STRING_t - NSString?

2011-03-29 Thread Stephen J. Butler
On Tue, Mar 29, 2011 at 12:24 PM, Todd Heberlein todd_heberl...@mac.com wrote:
 In particular, the beginning of the OCTET_STRING_t's buffer begins with two 
 bytes (decimal values 12 and 21). Am I supposed to skip these? For example, 
 the following code where I skip these first two bytes seems to work, but it 
 seems like a big hack:

I'm not familiar with validating app store bundles, as I'm not
(currently) a paid developer. But what is this, ANS.1 BER encoding?
Then the first byte is the tag (the type of data to follow), the
second byte the length (21), and then the next 21 bytes the data.

Indeed, Wikipedia (http://en.wikipedia.org/wiki/Basic_Encoding_Rules)
says that tag 12 is UTF8String. I'd recommend using liblber (man
lber-decode) if you have to do anything other than basic work with
this format.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: OCTET_STRING_t - NSString?

2011-03-29 Thread Stephen J. Butler
On Tue, Mar 29, 2011 at 12:48 PM, Todd Heberlein todd_heberl...@mac.com wrote:
 In particular, the beginning of the OCTET_STRING_t's buffer begins with two 
 bytes (decimal values 12 and 21). Am I supposed to skip these? For example, 
 the following code where I skip these first two bytes seems to work, but it 
 seems like a big hack:

 OK, it seems that the second byte (21 in this case) is the number of 
 characters encoded (I haven't tried non-ASCII characters). The OCTET_STRING_t 
 for bundle_version begins 12, 5 (where the string resolves to 1.0.2, five 
 characters). I still don't know what the 12 means. And does this mean that an 
 OCTET_STRING can encode at most 256 bytes?

You've probably already figured this out, but no, OCTET_STRING can
have as many bytes as it wants. You can store up to 127 bytes using
the simple, single byte length field. But if the highest order bit is
1 then the length field is either a length-of-length field or
indeterminate length field (depending on the particular length
value) where the data is terminated by a end-of-content sequence.

Again, I think using lber is the best way to handle this data :) I
can't remember why, but once upon a time I wrote an encoder/decoder
and had to learn all the subtitles.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: why I got wrong arguments from command-line

2011-03-29 Thread Stephen J. Butler
On Tue, Mar 29, 2011 at 9:55 AM, Haibin Liu lhb...@gmail.com wrote:
 NSArray * argvs = [[NSProcessInfo processInfo] arguments];
    argvs = (
    /Users/sara/studio/client/bin/Debug/Test.app/Contents/MacOS/Test,
    -psn_0_2392648
 )

The -psn_* argument is added by launch services. You'll have to code
your app to ignore it.
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Symbol not found

2011-03-16 Thread Stephen J. Butler
On Wed, Mar 16, 2011 at 6:08 PM, koko k...@highrolls.net wrote:
 A customer running 10.5.8 gets this message when launching my app.

 Dyld Error Message:
 Symbol not found: _OBJC_CLASS_$_NSURL
 Referenced from: /Applications/Convert It Mac.app/Contents/MacOS/Convert It
 Mac
 Expected in:
 /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation

 The app is built 32/64 universal with a deployment target of 10.5 and an SDK 
 of of 10.6.

 NSURL is available form 10.0

 Can someone shed light on this ?

Looks like in 10.5 NSURL was in Foundation.framework and in 10.6 they
moved it to CoreFoundation.framework. However, I don't know how to fix
this other than to build against the 10.5 SDK.

(not saying it's not fixable... just I don't know how)
___

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


  1   2   3   >