来自Finch音频库:
- (void) play
{
[[sounds objectAtIndex:current] play];
current = (current + 1) % [sounds count]; // this line here...
}
Run Code Online (Sandbox Code Playgroud)
我试着理解它:有许多声音n,并且current每次迭代都会增加1.一旦current大于声音数n,则模数返回零.这样,它从头开始.
它是否正确?
有没有办法让编译器在调用未定义的选择器时发出警告?例如,我在某个地方有这个电话:
methodcall time1:[[self.H1time copy] stringValue]
Run Code Online (Sandbox Code Playgroud)
在H1time类中不再存在stringValue方法,并且编译器没有引发任何内容.
copyWithZone声明为
- (NSHour*)copyWithZone:(NSZone *)zone;
Run Code Online (Sandbox Code Playgroud)
如果我打电话,编译器会在NSHour内部发出警告[self stringValue].但不是methodcall time1:[[self.H1time copy] stringValue]
我看到这个错过只是因为在碰撞后进行了密集测试.
我希望编译器阻止我这样的错误调用.我怎么能这样做?
一些测试表明编译器可能会在上述情况下发出警告:
NSHour *titi = [NSHour hourWithString:@"00:00:00"];
id toto = [titi copy];
NSString *str2 = [toto doThis]; --- Warning : "No doThis Method found"
Run Code Online (Sandbox Code Playgroud)
另一个测试:
NSHour *titi = [NSHour hourWithString:@"00:00:00"];
NSString *str3 = [[titi copy] doThis]; --- Warning : "No doThis Method found"
Run Code Online (Sandbox Code Playgroud) 让我说我正在做mk"目标"来构建一些东西.有可能传递一个参数吗?即mk"目标""x",它会做相应的事情吗?我知道我将提供mk"target"一个参数,我知道它的语义,只是提前不知道这个名字.
可能?
我总是怀疑有时当我运行我的应用程序时,会创建一个应用程序池并且我的应用程序被加载到应用程序池中,当我点击主页按钮时,我的应用程序终止,即我的应用程序所在的池将被终止,所以在此如果我不释放这些对象将会发生什么事情,我认为它们也将被终止,但苹果神不推荐这种方法,因为什么原因.任何绅士都可以为这个问题提供一个可靠的答案,因为这些天它真的给我带来了很多麻烦.
感谢和问候
如果出现问题我正试图设置错误信息,但是我知道了
This class is not key value coding-compliant for the key NSLocalizedDescription
Run Code Online (Sandbox Code Playgroud)
这是我使用的代码
-(id)getMoneyFromAccount:(int) sum error:(NSError **)error
{
if(self.balance - sum < 0)
{
NSDictionary *details = [NSDictionary dictionary];
[details setValue:@"You don't have enough money" forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:@"money" code:200 userInfo:details];
return nil;
}
self.balance = self.balance - sum;
return [NSNumber numberWithInt:self.balance];
}
Run Code Online (Sandbox Code Playgroud) 我使用了一些照片写入照片库UIImageWriteToSavedPhotosAlbum(),同时我和朋友一起显示了这个资产组(ALAssetsGroupSavedPhotos)的内容enumerateAssetsUsingBlock:.有时,通过枚举组返回的资产会变得"无效",这意味着defaultRepresentation调用会返回nil,尽管资产仍在内存中.
我注意到这似乎发生在照片库被UIImageWriteToSavedPhotosAlbum()调用修改后.这是记录在案的行为吗?我该怎样预防呢?重新加载资产不是一个可行的选择,因为用户可能已经在使用资产的UI中更深处.
我试图通过Web服务解析一些JSON.逻辑是:
id jsonObject = ....; //This can be string or array
if([jsonObject class] == [NSString class] || [jsonObject class] == [NSMutableString class]{
// DO some thing
}
else if([jsonObject class] = [NSArray class] || [jsonObject class] == [NSMutableArray class]{
// Do some thing else
}
Run Code Online (Sandbox Code Playgroud)
然而,对于其中一个元素,我遇到了一个奇怪的问题.这个元素的类应该是NSArray,但是当我运行代码时,我将该类视为__NSArrayM.这与第二个if块不匹配.
有人可以告诉我我做错了什么
我现在有可能愚蠢,但检查一下.我有一个浮动:
float wordTime=46.81; // I get it after some calculations
Run Code Online (Sandbox Code Playgroud)
然后我记录了这个:
NSLog(@"1:%f", wordTime);
NSLog(@"2:%f", (3/2)*wordTime);
NSLog(@"3:%f", (5/2)*wordTime);
NSLog(@"4:%f", (7/2)*wordTime);
Run Code Online (Sandbox Code Playgroud)
我明白了:(日志编号2有问题)
46.81
46.81 // weird
93.8
140.7
Run Code Online (Sandbox Code Playgroud)
然后,我已经改变了3/2对1.5和我46,70,93,和140缺少什么我在这里?
我得到了一些代码:
setA :: Integer -> Integer
setA 3 = 5
setA 5 = 6
setA 7 = error "some error one"
setA _ = error "some error two"
Run Code Online (Sandbox Code Playgroud)
现在我尝试写另一个函数
checkError :: Integer -> Bool
checkError x = if HERE_TO_CHECK_IF setA x RETURNS some error two
then False
else True
Run Code Online (Sandbox Code Playgroud)
但我怎么能这样做?
谢谢
目录结构
Attachments/TADDE12345
Attachments/TADDE12346
Attachments/TADDE12347
Attachments/TADDE12348
Attachments/TADDE12349
Attachments/TADDE12350
Run Code Online (Sandbox Code Playgroud)
我必须在附件目录中获取所有文件夹名称而不使用任何cpan模块?