我已经开始使用块了,我遇到的第一件事就是无法设置闭包捕获的值.这很好,我一直在使用C/C++很长一段时间.我只会使用指针!
MyObject* bestObj = nil;
float bestDist= 10000.f;
MyObject **pBestObj = &bestObj;
float* pBestDist = &bestDist;
[self testObjects:class block:^(MyObject* obj){
CGRect r = [obj boundingBox];
// position is captured from outside this code sample
if( CGRectContainsPoint( r, position ) )
{
float dist = GetDistance( obj, position );
if(dist < bestDist)
{
*pBestDist = dist;
*pBestObj = obj;
}
}
}];
return bestObj;
Run Code Online (Sandbox Code Playgroud)
我的问题是,这样安全吗?我假设只要我的指针指向一些没有超出范围但仍然存在的东西,它应该可以工作.但是我也假设那些采用块的东西并不是说并行运行它们.我知道我的代码没有,但我不知道,比如使用带有NSArray enumerateObjectsUsingBlock调用的块.
我有一个.editorconfig文件,其中包含我的命名首选项。当我运行代码清理时,它会自动格式化除命名之外的所有其他首选项。当我将鼠标悬停在违反命名首选项的变量上时,它会告诉我它违反了哪一个,我可以右键单击将其更改为正确的格式,但是当像我的其他首选项一样运行代码清理时,这不会自动发生。
我是否缺少 VS 设置以.editorconfig在运行代码清理时自动应用命名首选项?
偏好通知示例:
编辑器配置命名首选项:
# Naming rules
dotnet_naming_rule.private_or_internal_field_should_be_underscore_prefixed_camel_case.severity = warning
dotnet_naming_rule.private_or_internal_field_should_be_underscore_prefixed_camel_case.symbols = private_or_internal_field
dotnet_naming_rule.private_or_internal_field_should_be_underscore_prefixed_camel_case.style = underscore_prefixed_camel_case
# Symbol specifications
dotnet_naming_symbols.class.applicable_kinds = class
dotnet_naming_symbols.class.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.class.required_modifiers =
dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_symbols.method.applicable_kinds = method
dotnet_naming_symbols.method.applicable_accessibilities = *
dotnet_naming_symbols.method.required_modifiers =
dotnet_naming_symbols.property.applicable_kinds = property
dotnet_naming_symbols.property.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.property.required_modifiers =
dotnet_naming_symbols.public_or_protected_field.applicable_kinds = field
dotnet_naming_symbols.public_or_protected_field.applicable_accessibilities = public, protected
dotnet_naming_symbols.public_or_protected_field.required_modifiers …Run Code Online (Sandbox Code Playgroud) 我正在使用NSMutableDictionary来存储有效的某些类的描述符,因为我宁愿不浪费将描述符添加到每个类实例的内存,因为只有1000个对象的非常小的子集将具有描述符.
不幸的是,鉴于:
MyClass* p = [MyClass thingy];
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
NSString* description = @"blah"; //does this work? If not I'm just simplifying for this example.
[dict setObject:description forKey:p]; // BZZZZT a copy of p is made using NSCopying
MyClass* found = [dict objectForKey:p]; //returns nil, as p becomes a different copy.
Run Code Online (Sandbox Code Playgroud)
所以这不起作用.
我可以通过传递NSNumber来破解它:
[dict setObject:description forKey:[NSNumber numberWithInt:(int)p]]; // this is cool
Run Code Online (Sandbox Code Playgroud)
但这不仅是丑陋的,而且因为它是非标准的而容易出错.
考虑到这一点,有一个干净的方法来做到这一点?
我不小心将一个我没有权利的文件推送到一个可公开访问的仓库.
我可以做些什么来完全从repo中选择性地修改单个文件,以便它的数据完全消失?
假设我使用:运算符声明一个lua函数,如下所示:
function ClassName:myFunc( stuff )
--do stuff
end
Run Code Online (Sandbox Code Playgroud)
然后说我将该函数存储在一个表中,如下所示:
someTable = {
ClassName.myFunc,
someGlobalFunc,
}
Run Code Online (Sandbox Code Playgroud)
然后,假设我有另一个函数遍历表并尝试调用给定的函数.
function ClassName:callStuffInThisTable(table)
-- I go through the table, which might be someTable above, and call all the functions
end
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何知道表中的函数是否归ClassName所有,以便我可以使用self调用它?
objective-c ×2
c# ×1
code-cleanup ×1
delete-file ×1
editorconfig ×1
git ×1
ios ×1
lua ×1
permanent ×1