草庐IT

variable-declaration

全部标签

ios - 桥接头问题 - 'MyClass' 不可用 : cannot find Swift declaration for this class

我已经访问过这个链接-MyClassisunavailable:cannotfindSwiftdeclarationforthisclass-ReleaseBuildOnlyAddingLinkedorEmbeddedSwiftFramework:'MyClass'isunavailable:cannotfindSwiftdeclarationforthisclassSwift:usingprivateframework但是以上链接都没有帮助我解决问题。我正在使用objective-c开发一个应用程序,在我正在集成的应用程序中ios-charts其框架是在swift中开发的。我已经合并

ios - Swift- 错误 : Variable 'self.___' used before being initialized

我正在尝试在Playground中使用手势识别器,但遇到了一些问题。这是我的类(class):classfoo{varfooVarSwipe:AnyvarfooVarTap:Anyinit(){letgr=UISwipeGestureRecognizer(target:self,action:#selector(foo.bar))lettr=UITapGestureRecognizer(target:self,action:#selector(foo.tar))helloApple.addGestureRecognizer(gr)helloApple.addGestureRecogni

ios - 在 Swift 中使用 block 给出错误 "Variable used within its own initial value"

这是我在obj-c中的代码:__blockNSString*requestReference=[selfoperation:methodurl:urlparameters:parametersheaders:headerssuccess:^(NSURLSessionDataTask*task,idresponseObject){NSError*error=[NSErrorerrorWithSessionTask:taskresponseObject:responseObject];if(error){NSLog(@"error-%@",error);[delegaterequestWi

ios - 我在 Swift 中不断收到此错误。 "Consecutive Declarations On A Line Must Be Separated By ' ;'"

这是我的代码,非常感谢任何帮助,谢谢!这是在Swift中用Xcode编写的。我不断收到这样的错误:“一行中的连续声明必须用‘;’分隔”importUIKitclassViewController:UIViewController{@IBOutletvaroutputLabel:UILabel!=UILabel()varcurrentCount:Int=0overridefuncviewDidLoad(){super.viewDidLoad()//Doanyadditionalsetupafterloadingtheview,typicallyfromanib.}overridefunc

variables - 在 swift 中使用哪个声明

这个问题在这里已经有了答案:Whycreate"ImplicitlyUnwrappedOptionals",sincethatimpliesyouknowthere'savalue?(10个答案)关闭7年前。我真的不知道如何在Swift中声明我的变量,我有四个选择:varvalue=0.0//IknowthisonedeclaresvalueasaDoublewiththenumber0.0varvalue:Float=0.0//ThisonedeclaresvalueasaFloatwiththenumber0.0varvalue:Float?//Ireallydon'tgetthe

ios - self.variable 和 _variable 的区别,关于 KVO

这个问题在这里已经有了答案:What'sthedifferencebetween_variable&self.variableinObjective-C?[duplicate](1个回答)关闭7年前。第一张图是用self.name改的,第二张图是用_name改的,应该是一样的结果,但是第二张什么都不输出,为什么?这是代码#import"ViewController.h"@interfacekvo:NSObject@property(nonatomic,strong)NSString*name;@end@implementationkvo-(void)change{_name=@"b";

variables - 通过尽可能多地定义常量而不是变量在 Swift 中有什么好处吗?

通过定义尽可能多的常量xvars,在Swift中是否有任何速度、内存使用等方面的yield?我的意思是,尽可能多地使用let而不是var来定义? 最佳答案 理论上,速度或内存使用应该没有差异-在内部,变量工作相同。在实践中,让编译器知道某些东西是常量可能会导致更好的优化。然而,最重要的原因是使用常量(或不可变对象(immutable对象))有助于防止程序员出错。默认情况下,方法参数和迭代器是常量并非偶然。使用不可变对象(immutable对象)在多线程应用程序中也非常有用,因为它们可以防止一种类型的同步问题。

swift 警告 : 'weak' should not be applied to a property declaration in a protocol

看起来像weakreferenceswillbedisallowedinprotocols.那么如果我想添加一个弱引用,我应该怎么做呢?有更好的主意吗?protocolPipelineElementDelegate:class{funcsomeFunc()}protocolPipelineElement{weakvardelegate:PipelineElementDelegate?{getset}} 最佳答案 只需从协议(protocol)中删除weak关键字,并在符合类型中将属性声明为weak即可:classSomeClass:

swift - 在 SwiftUI 中将 View 声明为 View 主体内的变量时出现 "Function declares an opaque return type [...]"错误

假设我有一个View,其中的Image具有shadow属性:structContentView:View{varbody:someView{Image("turtlerock").shadow(radius:10)}}现在假设我想访问阴影半径的值。我以为我可以做到这一点:structContentView:View{varbody:someView{letmyImage=Image("turtlerock").shadow(radius:10)print(myImage.modifier.radius)}}但是,这会返回一个错误:Functiondeclaresanopaqueretu

Swift 语言 : How to define a computed variable with observer?

我是Swift的新手,正在研究这门语言。我学习了计算变量和变量观察器的概念。我想知道是否可以在定义变量时同时定义它们。我试过但失败了。下面是我的代码(不工作!)。vara:Int=88{get{println("get...")return77}set{a=newValue+1}}{willSet{println("InwillSet")println("Willsetato\(newValue)")println("OutwillSet")}didSet{println("IndidSet")println("Oldvalueofais\(oldValue)")println(a)i