Re: How to get music list?

2008-08-04 Thread Bob Warwick


I have a problem getting the iTunes list, and then making the  
tableview display the iTunes list.


The problem, is actually getting started. Which class should I use?



I wrote some sample code a couple months ago to read in the playlist  
names from the iTunes XML file.  It might help get you started if you  
decide to go that route.


You can find it here: http://codehackers.net/blog/?p=65

- Bob Warwick

___

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 [EMAIL PROTECTED]


Re: Array help!

2008-07-17 Thread Bob Warwick
From a quick glance, I'd say you've connected your tableview outlet  
to the scrollview in Interface Builder, not the tableview.  Tableviews  
are contained within scrollviews.  You can confirm by checking what  
the outlet's connected to under the 'outlets' tab of the info panel in  
IB.


-Bob Warwick

On 17-Jul-08, at 5:50 PM, Eric Lee wrote:

I'm doing Challenge from Chapter 6 in the 3rd edition of the Cocoa  
Programming for mac OS X book, and I've ran into some trouble.


While I'm trying to reload data, there's always this warning the says:

Warning: 'NSScrollView' may not respond to '-reloadData' (Messages  
without a matching method signature will be assumed to return 'id'  
and accept '...' as arguments)


I have no idea what it means, and no idea how to correct it.

here's the code:

App Controller.m

-

#import AppController.h


@implementation AppController

- (id) init
{
[super init];
array = [[NSMutableArray alloc] init];

return self;
}

- (NSInteger)numberOfRowsInTableView:aTableView
{
return [array count];
}

- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(NSInteger)rowIndex
{
return [array objectAtIndex:rowIndex];
}

- (void)tableView:(NSTableView *)anotherTableView
setObjectValue:(id)anObject
forTableColumn:(NSTableColumn *)anotherTableColumn
  row:(NSInteger)rowIndex
{
[array replaceObjectAtIndex:rowIndex withObject:anObject];
}

- (IBAction)addThing:(id) sender
{
NSString *string = [textField stringValue];
NSLog(@Got string %@ from textfield, string);

[array addObject:string];
[tableView reloadData];
}

@end

AppController.h
--

#import Cocoa/Cocoa.h


@interface AppController : NSObject {
NSMutableArray *array;
IBOutlet NSTextField *textField;
IBOutlet NSScrollView *tableView;
}

- (IBAction)addThing:(id)sender;

@end
---

I've connected everything. Also, I think there are other problems,  
since when I press a button that's supposed to add an object into  
the TableView, nothing happens, even though a log appears on the  
console.


Thanks!
___

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

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

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/warwick%40codehackers.net

This email sent to [EMAIL PROTECTED]


___

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 [EMAIL PROTECTED]


Re: how to save keyboard shortcuts?

2008-06-25 Thread Bob Warwick


On 25-Jun-08, at 12:04 PM, HAMSoft Admin wrote:


I'm really new at this so please be kind!

I recently learned how to make menu item keyboard shortcuts for my  
program. The problem is that on the next launch of the program the  
shortcuts are gone, so they are not being automatically saved. Is  
there a setting in IB for my menu to enable auto-saving of them or  
do I have to do it manually? I'm setting them with something like  
this:


[menuitem setKeyEquivalentModifierMask:NSControlKeyMask |  
NSCommandKeyMask];

[menuitem setKeyEquivalent:@U];

If I have to do it manually I'm not sure how. First to get the  
modifier keys for a particular menu item I'm using this...


int thekmm = [menuitem keyEquivalentModifierMask];

But I don't understand the returned integer. Plus do I have to  
create an array of modifiers and keys for every menu item in my  
program and save/restore that on every launch? Thant doesn't make  
sense, so there must be an easier way.


Thanks,
Hank


Hello -

	Have you considered setting your keyboard shortcuts in IB?  Just  
select your menu item in IB and change the Key Equiv. from the  
attributes panel.


-Bob Warwick
___

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 [EMAIL PROTECTED]


Re: Table View/Array Troubles

2008-06-13 Thread Bob Warwick


On 13-Jun-08, at 2:21 AM, Kyle Sluder wrote:

On Thu, Jun 12, 2008 at 2:00 AM, Bob Warwick  
[EMAIL PROTECTED] wrote:

Calling the NSMutableArray convenience method array will return an
autoreleased object.  You should do this instead:

 - (id) init
 {
 [super init];
 myNotes = [[NSMutableArray alloc] init];
 return self;
 }


Actually, it should really be like this (I've been pedantically  
explicit):


- (id)init
{
  self = [super init];
  if(self != nil)
  {
  myNotes = [[NSMutableArray alloc] init];
  }

  return self;
}

Note that -init is NOT required to return the same object that self
refers to.  Therefore it is always required that you re-assign self in
your overridden initializer if you need to access it, and you must
return that modified self*.

--Kyle Sluder


Of course you're correct here, and right to be absolutely pedantic in  
regards to how to write an init method properly.  In the case of the  
original question, NoteController and Note were both subclasses of  
NSObject which I believe should behave as expected in the my example.


To indulge my own curiosity, in a case like this where you know the  
behaviour of the superclass like NSObject, is there any advantage to  
doing it Kyle's way as opposed to my example?


-Bob Warwick
___

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 [EMAIL PROTECTED]


Re: Table View/Array Troubles

2008-06-12 Thread Bob Warwick

On 12-Jun-08, at 2:16 AM, Gabriel Shahbazian wrote:


Hi,

I've posted the source to an app I'm working on. If someone can take  
a look and tell my why my tableview is not working with my array, it  
would be of great help.


Source:
http://novisdesign.net/Labs/Alien%20Notes.zip

-Gabe


I found a couple problems in a quick look through your source:

Your NoteController init method looks like this:

- (id) init
{
[super init];
myNotes = [NSMutableArray array];
return self;
}

Calling the NSMutableArray convenience method array will return an  
autoreleased object.  You should do this instead:


- (id) init
{
[super init];
myNotes = [[NSMutableArray alloc] init];
return self;
}

Also, you populate your tableview by calling the title method of a  
given note.  Your title method looks like this:


- (NSString *) title
{
return [self title];
}

You're looking to access the title variable of the note instance, but  
instead you just call the title method again.  This creates a big ol'  
neverending recursive call.  You're wanting to do this:


- (NSString *) title
{
return title;
}

I'm also not too confident about how you're handling setting the title  
and content of a note.  Personally I'd use an NSMutableString for both  
of those and set the content of the string when setTitle: or  
setContent: is called.


-Bob Warwick

___

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 [EMAIL PROTECTED]


Re: Regular Expressions?

2008-06-06 Thread Bob Warwick

On 6-Jun-08, at 4:31 AM, Cemil Browne wrote:


Hi all,

This might be a really silly question - but am I missing something  
obvious?
Is there any support at all for regular expressions in the Cocoa  
libraries?


I can't find anything and I've found some third-party frameworks - but
surely something so necessary must be buried in the string classes
somewhere? How would I do a simple substring search or replace in  
10.4?


Thanks,
Cemil



Hello -

	There is no regular expression support in Cocoa.  You might find http://www.cocoadev.com/index.pl?RegularExpressions 
 useful in helping to find a library to do it for you.


Search and replace in Cocoa looks like this:

NSString *someString = @The quick brown fox;
	NSString *newString = [someString  
stringByReplacingOccurrencesOfString:@quick withString:@slow];


	You can find this in the NSString documentation.  It creates a new  
string with the substring replaced.


-Bob Warwick
[EMAIL PROTECTED]
___

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 [EMAIL PROTECTED]


Re: Regular Expressions?

2008-06-06 Thread Bob Warwick

Hello -

Whoops!  I can read.

	You use the replaceOccurrencesOfString:withString:options:range:  
method in NSMutableString.  It works on the same instance of the  
string instead of creating a new string.


For example:

	NSMutableString *someString = [NSMutableString stringWithString:@The  
quick brown fox];
	[someString replaceOccurrencesOfString:@quick withString:@slow  
options:NSCaseInsensitiveSearch range:NSMakeRange(0, [someString  
length])];


-Bob Warwick
[EMAIL PROTECTED]

On 6-Jun-08, at 4:54 AM, Cemil Browne wrote:


Bob,

Thanks for the reply...

However, stringByReplacingOccurrencesOfString only works in Tiger,  
though, right?  What did everyone do last year for it?


-Cemil
On 06/06/2008, at 5:51 PM, Bob Warwick wrote:


Hello -

	There is no regular expression support in Cocoa.  You might find http://www.cocoadev.com/index.pl?RegularExpressions 
 useful in helping to find a library to do it for you.


Search and replace in Cocoa looks like this:

NSString *someString = @The quick brown fox;
	NSString *newString = [someString  
stringByReplacingOccurrencesOfString:@quick withString:@slow];


	You can find this in the NSString documentation.  It creates a new  
string with the substring replaced.


-Bob Warwick
[EMAIL PROTECTED]

On 6-Jun-08, at 4:31 AM, Cemil Browne wrote:


Hi all,

This might be a really silly question - but am I missing something  
obvious?
Is there any support at all for regular expressions in the Cocoa  
libraries?


I can't find anything and I've found some third-party frameworks -  
but

surely something so necessary must be buried in the string classes
somewhere? How would I do a simple substring search or replace in  
10.4?


Thanks,
Cemil
___

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/warwick%40codehackers.net

This email sent to [EMAIL PROTECTED]






___

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 [EMAIL PROTECTED]


Re: Best Practice for Returning Immutable Objects?

2008-06-03 Thread Bob Warwick - Codehackers


On 3-Jun-08, at 12:56 PM, Karl Moskowski wrote:

I have a few methods that return NSData objects, but the objects are  
created and manipulated as NSMutableData, and then copied to an  
immutable version along these lines:

NSMutableData *myData = [NSMutableData data];
:
:
return [NSData dataWithData:myData];

Would it be sufficient to cast, like this?
:
return (NSData *)myData;

Does this generalize to other non-collection classes, e.g., NSString?



Hello -

It depends if you actually want to return an immutable object or not.

	When you call a method, the return type isn't a guarantee that the  
returned value will be a member of the specific class shown, but  
rather a member of or a subclass of the class shown.   You can return  
that NSMutableData without casting it from a method which says it  
returns NSData and it's still technically valid.


	For example, in these three classes only the first returns an NSData  
object, the other two return NSMutableData objects


- (NSData *) returnImmutableData {
NSMutableData *someData = [NSMutableData data];
return [NSData dataWithData:someData];
}

- (NSData *) returnSomeData {
NSMutableData *someData = [NSMutableData data];
return (NSData *)someData;
}

- (NSData *) returnSomeOtherData {
NSMutableData *someOtherData = [NSMutableData data];
return someOtherData;
}

	In general, I'd say it's best to return what you're actually claiming  
to return.


-Bob Warwick
[EMAIL PROTECTED]
___

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 [EMAIL PROTECTED]