• 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: Passing an integer as contextInfo from a sheet
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Passing an integer as contextInfo from a sheet


  • Subject: Re: Passing an integer as contextInfo from a sheet
  • From: Clark Cox <email@hidden>
  • Date: Thu, 12 Feb 2004 10:14:26 -0500

On 2004/02/12, at 9:44, Jeremy Dronfield wrote:

> I was using the following method to pass an integer from an alert
> sheet:
>
> - (IBAction)deleteSelection:(id)sender
> {
> NSString *warningText = [NSString stringWithFormat:@"Delete %@?",
> [sender title]];
> int theTag = [sender tag];
>
> NSBeginAlertSheet(warningText, @"Cancel", @"Delete", nil, [skJournal
> mainWindow], self,
> @selector(didEndDeleteSheet:returnCode:contextInfo:), NULL, theTag,
> @"This action cannot be undone.", nil);
> }
>
> - (void)didEndDeleteSheet:(NSWindow *)sheet returnCode:(int)returnCode
> contextInfo:(void *)contextInfo
> {
> int theTag = (int)contextInfo;
>
> < ...etc >
> }
>
> It worked okay, and the integer was passed, even though the compiler
> gave me a "pointer from integer without a cast" warning on
> NSBeginAlertSheet. So, going by pure guesswork, I changed the argument
> to (void *)theTag, and the warning stopped. I know it seems like an
> arsey question, but is this correct?

It's generally a bad idea to assume that an int can be represented by
a pointer or vice-versa. Your code will work on OSX as it currently
stands, but your code is brittle with respect to changes in the sizes
of types. Why not do something like:

- (IBAction)deleteSelection:(id)sender
{
NSString *warningText = [NSString stringWithFormat:@"Delete %@?",
[sender title]];

NSBeginAlertSheet(warningText, @"Cancel", @"Delete", nil, [skJournal
mainWindow], self,
@selector(didEndDeleteSheet:returnCode:contextInfo:), NULL, sender,
@"This action cannot be undone.", nil);
}

- (void)didEndDeleteSheet:(NSWindow *)sheet returnCode:(int)returnCode
contextInfo:(void *)contextInfo
{
int theTag = [(id)contextInfo tag];

< ...etc >
}


--
Clark S. Cox III
email@hidden
http://homepage.mac.com/clarkcox3/
http://homepage.mac.com/clarkcox3/blog/B1196589870/index.html

[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.

  • Follow-Ups:
    • Re: Passing an integer as contextInfo from a sheet
      • From: Jeremy Dronfield <email@hidden>
References: 
 >Passing an integer as contextInfo from a sheet (From: Jeremy Dronfield <email@hidden>)

  • Prev by Date: Re: is this enough for a singleton? (for a class cluster "placeholder")
  • Next by Date: Key associate with NSTableView Row
  • Previous by thread: Passing an integer as contextInfo from a sheet
  • Next by thread: Re: Passing an integer as contextInfo from a sheet
  • Index(es):
    • Date
    • Thread