Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to NSLog an NSNumber ivar in an instance method
    text
    copied!<p>I'm working on a console app that is tracks different songs. I'm working on getting the song class up off the ground first and have run into a snag trying to log an nsnumber which has been allocated for the song duration into an nslog statement:</p> <pre><code>// // Song.h // MusicCollection.15.9 // // Created by Nicholas Iannone on 1/11/10. // Copyright 2010 __MyCompanyName__. All rights reserved. // #import &lt;Foundation/Foundation.h&gt; @interface Song : NSObject { NSString *songTitle; NSString *songArtist; NSString *songAlbum; NSNumber *SongDuration; } @property (nonatomic, retain) NSString *songTitle, *songArtist, *songAlbum; @property (nonatomic, retain) NSNumber *SongDuration; -(id) init; -(void) printSong; @end // // Song.m // MusicCollection.15.9 // // Created by Nicholas Iannone on 1/11/10. // Copyright 2010 __MyCompanyName__. All rights reserved. // #import "Song.h" @implementation Song @synthesize songTitle, songArtist, songAlbum; @synthesize SongDuration; -(id) init { if (self = [super init]) { [SongDuration numberWithInteger]; } -(void) printSong { NSLog(@"===============Song Info=================="); NSLog (@"| |"); NSLog (@"| %-31s |", [songTitle UTF8String]); NSLog (@"| %-31s |", [songArtist UTF8String]); NSLog (@"| %-31s |", [songAlbum UTF8String]); NSLog (@"| %31@ |" [self songDuration]); NSLog (@"| |"); NSLog (@"| |"); NSLog (@"========================================="); } @end </code></pre> <p>Basically I'm not sure how to incorporate the nsnumber into the nslog statement when the print method gets called, plus im not really sure how to deal with these nsobjects ingeneral they seem kind of in-between an object I would create and a c type. Any clarification on how to handle these would be appreciated.</p> <p>Thanks,</p> <p>Nick</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload