我正在开发一个跟踪不同歌曲的控制台应用程序。我正在努力让歌曲类首先起步,并遇到了一个障碍,试图将已为歌曲持续时间分配的 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 类型之间。任何关于如何处理这些的澄清将不胜感激。
谢谢,
缺口