14

さまざまな曲を追跡するコンソール アプリに取り組んでいます。私は最初に歌のクラスを軌道に乗せようと取り組んでおり、曲の長さに割り当てられた nsnumber を nslog ステートメントに記録しようとして問題が発生しました。

//
//  Song.h
//  MusicCollection.15.9   
//
//  Created by Nicholas Iannone on 1/11/10.
   //  Copyright 2010 __MyCompanyName__. All rights reserved.
   //

   #import <Foundation/Foundation.h>


@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

基本的に、print メソッドが呼び出されたときに nsnumber を nslog ステートメントに組み込む方法がわかりません。さらに、これらの nsobjects の一般的な処理方法がよくわかりません。これらは、作成するオブジェクトと ac タイプの中間のように見えます。これらの処理方法に関する説明をいただければ幸いです。

ありがとう、

ニック

4

1 に答える 1