English 中文(简体)
国家安全局宣布工作,但并未开始或分配工作。
原标题:NSSound working, but not initialized or allocated..

我有一个表演歌曲的简单节目。 它沿用了传承的觉醒基金从尼伯的方法。 因此。

-(void)awakeFromNib {
NSSound *song = [NSSound soundNamed:@"MyTune.mp3"];
[song play];
}

我的问题是,为什么这样做。 我无需怎么做。

NSSound *song = [[NSSound alloc]init];
song = [NSSound soundNamed:@"MyTune.mp3"];
[song play];
}

It also seems to work with strings too.. I have a NSTextView variable set up and I can do the following

-(void)awakeFromNib {
NSString *str = [NSString stringWithFormat:@"Hello there!"];
[myTextVariable insertText:str];
}

Why didn t I have to alloc and init the objects.. I am so lost.. Please help.

最佳回答

许多果树类具有助手功能,在助手职能范围内,为你们宣布为主食和 in。 他们回去准备使用物体。 您可以说明,“九”是否看到了这种方法的用法,它说的是“与特定名称有关的国家安全局的复审”。

因此,你的第一个实例是:

-(void)awakeFromNib {
NSSound *song = [NSSound soundNamed:@"MyTune.mp3"];
[song play];
}

Your second example leaks memory because you alloc and then overwrite your pointer with a new object returned by [NSSound soundNamed:@"MyTune.mp3"]:

  -(void)awakeFromNib {

    // Create an NSSound object in memory and store the address in song.
    NSSound *song = [[NSSound alloc]init]; 

    // If you don t want a memory leak this is your last chance to [song release]

    // Create a NSSound object using a helper function and place its address 
    // in song, over writing the previous address.
    song = [NSSound soundNamed:@"MyTune.mp3"];

    // We now lost track of the first NSSound object and can t release it because 
    // we overwrote the address.

    [song play];
    }

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSSound_Class/Reference/Reference.html 您可以看到,这一方法正在采用<代码>alloc和in。 在座各位:

http://www.ohchr.org。

遣返与某个名字相关的国家情报和安全局。

+(id) 声纳med:NSString *

<>12>

soundName Name that identifies sound data.

<>Return Value

国家抽样调查首先采用了由声音Name确定的良好数据。

问题回答

暂无回答




相关问题
Python: Binding method

In following example I am trying to bind a method object via types.MethodType(...). It does not seem to work. Any suggestions? Thanks in advance. import types class Base: def payload(self, *args)...

Invoking an instance method without invoking constructor

Let s say I have the following class which I am not allowed to change: public class C { public C() { CreateSideEffects(); } public void M() { DoSomethingUseful(); } } and I have to call M ...

Behaviour of final static method

I have been playing around with modifiers with static method and came across a weird behaviour. As we know, static methods cannot be overridden, as they are associated with class rather than instance....

Setting the Page-Title in .Net using C# from a Class

Question, How do i set the title of a page from a class. Is it even possible? I can and have set the page title from a page itself and a usercontrol. Can I, How Do I do this via a class using C# ....

how to drag in the animation in iphone application?

Iphone application is using the static co-ordinates to reach at some points in the application,which is based on the button event. But what i want is when i drag the item than it should reach at some ...