FROM : Daniel DeCovnick
DATE : Tue Apr 19 05:34:30 2005
Additionally, you can simply reopen the interface in your .m file:
in Bar.h:
@interface Bar : NSObject
{
id ivar;
id ivar2;
}
-(int)doStuff;
@end
in Bar.m
@interface Bar
-(int)foo1;
-(int)foo2;
@end
@implementation Bar
-(int)doStuff
{
//code that does stuff
}
-(int)foo1
{
return 10;
}
-(int)foo2
{
return 20;
}
@end
Daniel DeCovnick
danhd123 at mac dot com
Softyards Software
http://www.softyards.com
On Apr 18, 2005, at 4:36 PM, Ivan S. Kourtev wrote:
> The default return type is (id). If you don't declare the functions
> you should do:
>
> i = i + (int)[self foo1];
>
> --
> ivan
>
> On Apr 18, 2005, at 4:08 PM, Pradeep Kumar wrote:
>
>> Hi All
>>
>> I am not sure if I am missing something really fundamental or it is
>> really a bug. But I have
>> this strange problem that's occurring when functions are not
>> declared in the interface.
>> Thought of broadcasting this incase some one has any insight on why
>> this is happening.
>>
>> Please review the following code snippet. Assume that the functions
>> foo1 and foo2 are
>> declared in the interface declaration of MyObject.
>>
>> @implementation MyObject
>>
>> -(void)awakeFromNib
>> {
>> NSLog(@"[self foo1] returned %d", [self foo1]);
>> NSLog(@"[self foo2] returned %d", [self foo2]);
>> int foo1 = [self foo1];
>> int foo2 = [self foo2];
>> NSLog(@"Variables foo1 = %d\tfoo2 = %d", foo1, foo2);
>>
>> int i = 100;
>> NSLog(@"i = %d", i);
>>
>> i = i+[self foo1];
>> NSLog(@"Executing i = i+[self foo1] = %d", i);
>> i = i+[self foo2];
>> NSLog(@"Executing i = i+[self foo2]; = %d", i);
>> }
>>
>> -(int)foo1
>> {
>> return 10;
>> }
>>
>> -(int)foo2
>> {
>> return 20;
>> }
>>
>> @end
>>
>> The result you get in the log is
>>
>> [self foo1] returned 10
>> [self foo2] returned 20
>> Variables foo1 = 10 foo2 = 20
>> i = 100
>> Executing i = i+[self foo1] = 110
>> Executing i = i+[self foo2]; = 130
>>
>> The results are perfect.
>>
>> Now remove the declarations of foo1 and foo2 from the interface file
>> of MyObject. After
>> doing this here's what I get.
>>
>> [self foo1] returned 10
>> [self foo2] returned 20
>> Variables foo1 = 10 foo2 = 20
>> i = 100
>> Executing i = i+[self foo1] = 410
>> Executing i = i+[self foo2]; = 1660
>>
>> See the results of the last two statements. 410 and 1660. Why is
>> this happening?
>>
>> I am using XCode 1.5 with Component versions Xcode IDE: 389.0,
>> Xcode Core: 387.0,
>> ToolSupport: 372.0 on 10.3.9 (7W98). I know it is recommended that
>> functions be declared
>> in the interface. But can not declaring the functions cause such a
>> huge difference in ways
>> you can use non-declared functions?
>>
>> Thanks
>> prady
>>
>>
>>
>>
DATE : Tue Apr 19 05:34:30 2005
Additionally, you can simply reopen the interface in your .m file:
in Bar.h:
@interface Bar : NSObject
{
id ivar;
id ivar2;
}
-(int)doStuff;
@end
in Bar.m
@interface Bar
-(int)foo1;
-(int)foo2;
@end
@implementation Bar
-(int)doStuff
{
//code that does stuff
}
-(int)foo1
{
return 10;
}
-(int)foo2
{
return 20;
}
@end
Daniel DeCovnick
danhd123 at mac dot com
Softyards Software
http://www.softyards.com
On Apr 18, 2005, at 4:36 PM, Ivan S. Kourtev wrote:
> The default return type is (id). If you don't declare the functions
> you should do:
>
> i = i + (int)[self foo1];
>
> --
> ivan
>
> On Apr 18, 2005, at 4:08 PM, Pradeep Kumar wrote:
>
>> Hi All
>>
>> I am not sure if I am missing something really fundamental or it is
>> really a bug. But I have
>> this strange problem that's occurring when functions are not
>> declared in the interface.
>> Thought of broadcasting this incase some one has any insight on why
>> this is happening.
>>
>> Please review the following code snippet. Assume that the functions
>> foo1 and foo2 are
>> declared in the interface declaration of MyObject.
>>
>> @implementation MyObject
>>
>> -(void)awakeFromNib
>> {
>> NSLog(@"[self foo1] returned %d", [self foo1]);
>> NSLog(@"[self foo2] returned %d", [self foo2]);
>> int foo1 = [self foo1];
>> int foo2 = [self foo2];
>> NSLog(@"Variables foo1 = %d\tfoo2 = %d", foo1, foo2);
>>
>> int i = 100;
>> NSLog(@"i = %d", i);
>>
>> i = i+[self foo1];
>> NSLog(@"Executing i = i+[self foo1] = %d", i);
>> i = i+[self foo2];
>> NSLog(@"Executing i = i+[self foo2]; = %d", i);
>> }
>>
>> -(int)foo1
>> {
>> return 10;
>> }
>>
>> -(int)foo2
>> {
>> return 20;
>> }
>>
>> @end
>>
>> The result you get in the log is
>>
>> [self foo1] returned 10
>> [self foo2] returned 20
>> Variables foo1 = 10 foo2 = 20
>> i = 100
>> Executing i = i+[self foo1] = 110
>> Executing i = i+[self foo2]; = 130
>>
>> The results are perfect.
>>
>> Now remove the declarations of foo1 and foo2 from the interface file
>> of MyObject. After
>> doing this here's what I get.
>>
>> [self foo1] returned 10
>> [self foo2] returned 20
>> Variables foo1 = 10 foo2 = 20
>> i = 100
>> Executing i = i+[self foo1] = 410
>> Executing i = i+[self foo2]; = 1660
>>
>> See the results of the last two statements. 410 and 1660. Why is
>> this happening?
>>
>> I am using XCode 1.5 with Component versions Xcode IDE: 389.0,
>> Xcode Core: 387.0,
>> ToolSupport: 372.0 on 10.3.9 (7W98). I know it is recommended that
>> functions be declared
>> in the interface. But can not declaring the functions cause such a
>> huge difference in ways
>> you can use non-declared functions?
>>
>> Thanks
>> prady
>>
>>
>>
>>
| Related mails | Author | Date |
|---|---|---|
| Pradeep Kumar | Apr 18, 22:08 | |
| Shawn Erickson | Apr 18, 22:34 | |
| Ivan S. Kourtev | Apr 18, 22:36 | |
| Daniel DeCovnick | Apr 19, 05:34 |






Cocoa mail archive

