草庐IT

non-void

全部标签

ios - 类型为 Void 的 appendAttributedString 返回值

我正在尝试附加两个NSAttributedString。letstring_1:NSAttributedString=self.answerTextView.attributedTextletstring_2:NSAttributedString=handleHtml(i)//afunctionthatreturnsaNSAttributedStringletfinalStr:NSAttributedString=string_1.mutableCopy().appendAttributedString(string_2)但是我在第三行报错了:Cannotconvertvalueoft

Swift - 可选的 Void

我正忙于使用NSURLProtocolClient的URLProtocol函数:welf?.client?.URLProtocol(welf!,didReceiveResponse:operation.response,cacheStoragePolicy:NSURLCacheStoragePolicy.NotAllowed)我原以为它会返回Void。但令我惊讶的是它返回Void?为什么要区分Void和Void?我读到Void是空元组类型的类型别名。那么,这是否与空元组类型与nil之间的区别有关? 最佳答案 这仅仅是因为您正在使用O

pointers - 在 swift 中将 CFContextRef 转换为可变的 void 指针?

我正在尝试将此objc代码转换为swift:CGContextRefcontextRef=CGBitmapContextCreate(NULL,proposedRect.size.width,proposedRect.size.height,CGImageGetBitsPerComponent(imageRef),0,colorSpaceRef,(CGBitmapInfo)kCGImageAlphaPremultipliedFirst);NSGraphicsContext*context=[NSGraphicsContextgraphicsContextWithGraphicsPort

objective-c - 是否可以将 Swift 类转换为 C void* 指针?

是否可以将Swift类转换为Cvoid*指针?//swiftclassclassMyClass{}varmyClass=MyClass()varp:UnsafeMutablePointer=myClass//谢谢 最佳答案 我遇到了类似的问题,你可以按照下面的方式转换它。varmyClass=MyClass()varclassPtr=unsafeBitCast(myClass,UnsafePointer.self)和你的功能,funcsomeSwiftClass(voidPointer:UnsafeMutablePointer){}

objective-c - 无法调用从 Obj-C 抛出并返回非 void 的 Swift 类中的方法

我想在Swift中有一个返回Bool的函数,但如果发生异常,它也可以throw。例如:funcdoSomething(value:Int)throws->Bool{if(value>0){returntrue}elseif(value==0){throwNSError(domain:"SwiftClass",code:0,userInfo:nil)}returnfalse}这在Swift中运行良好,但如果我尝试在Objective-C中使用此函数,编译器将无法找到该方法。我知道throws需要将Objective-C函数签名更改为doSomething:xerror:&error并且如

swift - "cannot call value of non-function type"尝试调用 max(_ :_:) function

我正在尝试调用max函数:max(x:T,y:T)。但是,当我键入max(2,3)时,我不断收到以下错误:error:cannotcallvalueofnon-functiontypeIntvara=max(2,3)我是初学者,从来没有遇到过使用类型“T”的函数签名。所以与使用max函数相关的线程以我的方式调用它(比如max(2,3))所以我不确定我哪里出错了。我正在寻找关于“T”的解释以及如何调用支持泛型类型的函数以及如何使max函数在比较整数时返回32和3. 最佳答案 问题(如you'veconfirmedinthecommen

pointers - Swift 使用 UnsafePointer<String> 从 UnsafeMutablePointer<Void> 获取值

我正在尝试通过contextInfo类型UnsafeMutablePointer至UISaveVideoAtPathToSavedPhotosAlbum并在回调函数中使用它。由于某种原因,我无法访问contextInfo作为字符串使用UnsafePointer(x).memory当我在回调函数中时。我很确定这是我所缺少的简单东西,但我花了很多时间试图弄清楚。下面是我试过的一些代码。以下代码有效。vartestStr:String="hello"takesAMutableVoidPointer(&testStr)functakesAMutableVoidPointer(x:UnsafeM

java "void"和 "non void"构造函数

我用java编写了这个简单的类,只是为了测试它的一些功能。publicclassclass1{publicstaticIntegervalue=0;publicclass1(){da();}publicintda(){class1.value=class1.value+1;return5;}publicstaticvoidmain(String[]args){class1h=newclass1();class1h2=newclass1();System.out.println(class1.value);}}输出是:2但是在这段代码中:publicclassclass1{publics

java - 创建已完成的 CompletableFuture<Void> 的正确方法是什么

我在Java8中使用Completablefutures,我想编写一个方法,根据接收到的参数,并行运行多个具有副作用的任务,然后返回它们的“组合”future(使用CompletableFuture.allOf()),或者什么都不做并返回一个已经完成的future。然而,allOf返回CompletableFuture:publicstaticCompletableFutureallOf(CompletableFuture...cfs)创造一个已经完成的future的唯一方法是使用completedFuture(),它需要一个值:publicstaticCompletableFutur

java - Callable<Void> 作为功能接口(interface)与 lambdas

我只是在学习新的java8特性。这是我的问题:为什么不允许使用Callable作为lambda表达式的功能接口(interface)?(编译器提示返回值)而且使用Callable仍然是完全合法的那里。这是示例代码:publicclassTest{publicstaticvoidmain(String[]args)throwsException{//worksfinetestInt(()->{System.out.println("FromtestIntmethod");return1;});testVoid(()->{System.out.println("FromtestVoidme