• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Comparing apples & oranges (well, Strings & mount points)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comparing apples & oranges (well, Strings & mount points)


  • Subject: Re: Comparing apples & oranges (well, Strings & mount points)
  • From: Mark Rowe <email@hidden>
  • Date: Sun, 16 Feb 2003 15:48:57 +1300

On Sunday, Feb 16, 2003, at 14:31 Pacific/Auckland, Brian Ganninger wrote:

Thanks to those who have responded or emailed me. A few more clarifications
are in order about the problem.

1. According to Cocoa documentation itself the mountedLocalVolumes method
inside NSWorkspace returns an array of mount points, not strings. Thus, if
you try to create a string using initWithString:[array objectAtIndex:x] the
following error occurs:
*** -[NSCFString objectAtIndex:]: selector not recognized

The documentation for -[NSWorkspace mountedLocalVolumePaths] is:

"""mountedLocalVolumePaths

- (NSArray *)mountedLocalVolumePaths

Returns an array containing the mount points of all local volumes, not just the removable ones returned by mountedRemovableMedia."""

The documentation for -[NSWorkspace mountedRemovableMedia] starts off as:

"""mountedRemovableMedia

- (NSArray *)mountedRemovableMedia

Returns an NSArray of NSStrings containing the full pathnames of all currently mounted removable disks."""

This should make it clear that the mount points are just strings. The error message that you receive trying to create a string from one of the returned mount points indicates that you are doing something else incorrectly, and that the 'array' object isn't actually an NSArray like you thought.

The following code snippet shows an example of how to retrieve a mount point using NSWorkspace:


#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSArray *mountPoints = [[NSWorkspace sharedWorkspace] mountedLocalVolumePaths];

NSLog(@"mountPoints: %@", mountPoints);
NSLog(@"First mount point: %@", [mountPoints objectAtIndex:0]);
NSLog(@"Class of first mount point variable: %@", [[mountPoints objectAtIndex:0] class]);
NSLog(@"First mount point == '/'? %d", [[mountPoints objectAtIndex:0] isEqual:@"/"]);

[[[NSString alloc] initWithString:[mountPoints objectAtIndex:0]] release];

[pool release];
return 0;
}


When I run it I get the following output:
2003-02-16 15:44:31.766 Test[4926] mountPoints: <CFArray 0x84f30 [0xa01303fc]>{type = mutable-small, count = 1, values = (
0 : <CFString 0x840d0 [0xa01303fc]>{contents = "/"}
)}
2003-02-16 15:44:31.786 Test[4926] First mount point: /
2003-02-16 15:44:31.800 Test[4926] Class of first mount point variable: NSCFString
2003-02-16 15:44:31.814 Test[4926] First mount point == '/'? 1


This shows that:
a) mountPoints is a NSArray of NSString's
b) The first mount point is /
c) Passing an object retreived from the mountPoint array to -[NSString initWithString] does not produce the error that you mentioned above.


-- Mark Rowe
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Comparing apples & oranges (well, Strings & mount points) (From: Brian Ganninger <email@hidden>)

  • Prev by Date: Re: Hello
  • Next by Date: capturing button-clicks on an Image
  • Previous by thread: Re: Comparing apples & oranges (well, Strings & mount points)
  • Next by thread: Accents in About Box
  • Index(es):
    • Date
    • Thread