铸造问题(或者更确切地说,不铸造问题)
我想这是非常基本的。
我从 xCode 收到两个相关警告。两者都说我正在尝试从整数创建一个指针而不进行强制转换。我怎样才能满足xCode?
这是我的代码:
int tempCurrentPage = currentPageCounter;
[self tabAdd:@"New tab!" inColour:@"Red" withReference:tempCurrentPage];
注意:currentPageCounter 是一个 NSUInteger currentPageCounter;
。
我的方法如下所示:
-(void)tabAdd:(NSString *)newTabTitle inColour:(NSString *)newTabColour withReference:(int *)newTabReference
{
NSLog(@"#string about to be added:%@", newTabTitle);
[[[self.myLibrary objectAtIndex:currentBookNumber] tabTitles] addObject:newTabTitle];
NSLog(@"#string about to be added:%@", newTabColour);
[[[self.myLibrary objectAtIndex:currentBookNumber] tabColours] addObject:newTabColour];
NSLog(@"#string about to be added:%@", newTabReference);
[[[self.myLibrary objectAtIndex:currentBookNumber] tabReference] addObject:[NSNumber numberWithInteger:newTabReference]];
}
我应该如何进行转换?
I guess this is very basic.
I get two related warnings from xCode. Both say that I'm trying to make a pointer from integer without a cast. How can I satisfy xCode?
This is my code:
int tempCurrentPage = currentPageCounter;
[self tabAdd:@"New tab!" inColour:@"Red" withReference:tempCurrentPage];
Note: currentPageCounter is an NSUInteger currentPageCounter;
.
My method looks like this:
-(void)tabAdd:(NSString *)newTabTitle inColour:(NSString *)newTabColour withReference:(int *)newTabReference
{
NSLog(@"#string about to be added:%@", newTabTitle);
[[[self.myLibrary objectAtIndex:currentBookNumber] tabTitles] addObject:newTabTitle];
NSLog(@"#string about to be added:%@", newTabColour);
[[[self.myLibrary objectAtIndex:currentBookNumber] tabColours] addObject:newTabColour];
NSLog(@"#string about to be added:%@", newTabReference);
[[[self.myLibrary objectAtIndex:currentBookNumber] tabReference] addObject:[NSNumber numberWithInteger:newTabReference]];
}
How should I do a cast?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
withReference
需要一个int *
,但您正在传递一个int
。这是一个潜在的错误,可能会导致您的程序崩溃。看来你不需要在方法中指向整数的指针,只需传递一个整数就可以了。withReference
is expecting aint *
, but you are passing anint
. This is a potential bug and may crash your program. It seems that you don't need a pointer to integer in the method, just passing a integer is fine.您正在传递一个指向整数的指针:
将其更改为:
在选择器调用中,直接传递 currentPageCounter:
You're passing in a pointer to integer at:
Change this for:
and in the selector call, pass the currentPageCounter directly:
传入的强制转换应该是
(int)
而不是(int*)
。当您记录newTabReference
时,使用%d
而不是%@
进行记录。The incoming cast should be
(int)
and not(int*)
. And when you lognewTabReference
log it using%d
and not%@
.