草庐IT

optional_argument

全部标签

objective-c - 将 “no options” 传递给 NSJSONWritingOptions 类型参数的语法

在Objective-C中我写了如下代码:NSError*error;NSData*jsonData=[NSJSONSerializationdataWithJSONObject:someDictionaryoptions:0error:&error];我正尝试在Swift中做同样的事情。根据Xcode语法检查的一些提示,我这样写:varjsonError:NSErrorletjsonData=NSJSONSerialization.dataWithJSONObject(someDictionary,options:NSJSONWritingOptions(),error:&jsonE

ios - swift 错误 : '&' used with non-inout argument of type 'UnsafeMutablePointer'

我正在尝试从中转换以下Objective-C代码(source)-(CGRect)dimensionsForAttributedString:(NSAttributedString*)asp{CGFloatascent=0,descent=0,width=0;CTLineRefline=CTLineCreateWithAttributedString((CFAttributedStringRef)asp);width=CTLineGetTypographicBounds(line,&ascent,&descent,NULL);//...}进入swift:funcdimensionsFo

python执行函数时报错TypeError: create_pointer_down() takes 1 positional argument but 2 were given

 在调用函数时出现了这个报错new_input.create_pointer_down(MouseButton.LEFT)TypeError:create_pointer_down()takes1positionalargumentbut2weregiven,意思是说这个函数只接收一个变量,但实际上却给了两个变量,我搜索到说如果这个函数是自己在类里定义的,那么应该在类的函数参数在最前方加上self,defcreate_pointer_down(self,**kwargs):data=dict(type="pointerDown",duration=0)data.update(**kwargs)

gitee/github上传远程仓库错误usage: git remote add [<options>] <name> <url>

gitee/github上传远程仓库错误gitee/github上传远程仓库错误错误截图版本错误出现时间错误检查及解决1.网址中含有空格2.关闭翻译软件3.gitbash自身问题gitee/github上传远程仓库错误不知道大家最近有没有碰到这个错误usage:gitremoteadd[],我最近就碰到了,在上传到gitee的时候出现的,当我用gitremoteadd的时候就报了这个错误,我原以为是创建仓库的问题就仓库删了从弄,结果不行,我还尝试传到GitHub上结果也不行依然是这个错误错误截图版本软件/硬件版本git2.33.1windows10错误出现时间2022-12-06错误检查及解决

swift - Xcode 8.1 Swift 3 错误 : cannot convert value of type 'String' to expected argument type 'UnsafeMutableRawPointer'

包含varsceneData代码的行给出了一个错误,显然是因为“路径”字符串。有谁知道如何解决这个问题?谢谢!extensionSKNode{classfuncunarchiveFromFile(_file:String)->SKNode?{ifletpath=Bundle.main.path(forResource:file,ofType:"sks"){varsceneData=Data(bytesNoCopy:path,count:.DataReadingMappedIfSafe,deallocator:nil)!vararchiver=NSKeyedUnarchiver(forR

ios - 切换 map : error: cannot invoke 'map' with an argument list of type '((_) -> _)'

我不明白为什么这个有效:vararr=[4,5,6,7]arr.map(){xinreturnx+2}虽然这个不是arr.map(){xinvary=x+2returny}有错误Playgroundexecutionfailed:MyPlayground.playground:13:5:error:cannotinvoke'map'withanargumentlistoftype'((_)->_)'arr.map(){ 最佳答案 这里的问题是有错误信息。通常,当您看到类似cannotinvoke..with...的内容时,这意味着编

ios - 无法将类型 'Option' 的值转换为预期的参数类型 '@noescape (Option) throws -> Bool'

我有一个名为Option的类。这是一个Realm对象,因此它是Realm自己的基类Object的子类。在ViewController中,我有一个数组属性,其中包含一堆Option对象。privatevaroptions=[Option]()在ViewController下方的方法中,我需要检查上述选项数组中是否包含某个Option对象。以前(Swift1.2),我有这样的检查逻辑。funcitemSelected(selection:Object){letoption=selectionas!Optionif!contains(options,option){//actaccordin

swift - UICollectionView 问题 "fatal error: unexpectedly found nil while unwrapping an Optional value"

编辑:添加异常断点后(感谢大牛T),发现原来是我的cell.askingUsernameLabel.text=NSString(string:arr[indexPath.row])返回nil。这个问题的解决方案是在swift中,注册子类会覆盖你在Storyboard中所做的事情(如果使用Storyboard)。直接删除self.collectionView.registerClass(CollectionViewCell.self,forCellWithReuseIdentifier:"CollectionViewCell")一切顺利原创我真的迷失了这个:我试图在我的ViewContr

ios - 如何修复 "Argument passed to call that takes no arguments"错误?

我正在尝试制作一个TicTacToe游戏。我正在尝试使用此checkForWinner函数,但不断出现错误。非常感谢任何帮助。这是我的代码classViewController:UIViewController{@IBOutletweakvarCurrentLetterLabel:UILabel!@IBOutletweakvarlabel1:UILabel!@IBOutletweakvarlabel2:UILabel!@IBOutletweakvarlabel3:UILabel!@IBOutletweakvarlabel4:UILabel!@IBOutletweakvarlabel5:

swift - Swift 可选类型中 "an Optional of an Optional"的用途是什么?

我在SwiftTestssourcecode中发现了一个有趣的函数:functest(_v:A????,_cast:(A????)->B?)自Type?只是Optional的语法糖,这意味着参数的类型v可以重写为Optional>>>.我知道这个函数是用来测试可选类型的,所以它的参数肯定是过火了v和cast,但是具有“可选的可选等”的实际用途是什么?输入Swift(如果有)? 最佳答案 当您访问数据时,这些有时会在Swift中发生。一个示例是,如果您有一个字典,其中的值具有可选类型,然后您在该字典中查找一个值:letrockStar