• 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: NSArray problem for a newbie
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSArray problem for a newbie


  • Subject: Re: NSArray problem for a newbie
  • From: Dylan Adams <email@hidden>
  • Date: Wed, 30 Jul 2003 12:15:35 -0500

Ufficio Tecnico Metagraphics wrote:

Hi to all,
I'm a complete newbie to Cocoa and Obj-C.
I'm trying to write in a NSTextView an array like follow:

#import "byip.h"

@implementation byip

- (IBAction)connect_ip:(id)sender
{

NSString * file = @"/Library/Apache2/logs/access_log";
NSString * path = [file stringByStandardizingPath];
NSString * source = [NSString stringWithContentsOfFile:path];
NSString * name = [path lastPathComponent];
//NSMutableArray * [[IpArray alloc]init];


NSMutableArray * ip = [[source componentsSeparatedByString:@"\n"]retain];
int count = [ip count];
int i;

for (i = 0; i < count; i++)

{
[by_ip insertText:[NSString stringWithFormat:@"%i: \n",[ip objectAtIndex:i]]];

Are you sure that by_ip isn't nil? How is by_ip getting its value? Is it an outlet? Are you sure it's connected properly in IB?

Also, your ip is going to be full of NSStrings, not ints. You probably want to do:

[by_ip insertText: [NSString stringWithFormat:@"%@: \n",
[ip objectAtIndex:i]]];



}

[logs_ip setObjectValue :[NSString stringWithFormat:name]];

It doesn't really make a big difference, but wouldn't this make more sense as [NSString stringWithString: name]?

//[ip release];

With this line commented out, you're going to leak the NSMutableArray pointed to by `ip.' That's probably not what you want.

}

@end


dylan
_______________________________________________
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: 
 >NSArray problem for a newbie (From: Ufficio Tecnico Metagraphics <email@hidden>)

  • Prev by Date: Re: exception in class derived from NSMutableDictionary
  • Next by Date: Beta Testers Wanted
  • Previous by thread: Re: NSArray problem for a newbie
  • Next by thread: Re: What's this error mean
  • Index(es):
    • Date
    • Thread