11
我正在開發一款控制檯應用程序,用於跟蹤不同的歌曲。我工作的第一步,取得歌曲類擡離地面,並已遇到障礙試圖登錄已分配給的歌曲時長成的NSLog聲明一個NSNumber:試圖NSLog NSNumber伊娃實例方法
//
// 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 (@"| %[email protected] |" [self songDuration]);
NSLog (@"| |");
NSLog (@"| |");
NSLog (@"=========================================");
}
@end
基本上我不是確定如何在打印方法被調用時將nsnumber納入nslog語句,再加上我不確定如何處理這些nsobjects,通常他們似乎在我創建的對象和ac類型之間。任何澄清如何處理這些將不勝感激。
感謝,
尼克