草庐IT

initializing

全部标签

ios - 初始化变量 : 'self' captured by a closure before all members were initialized

我在初始化自定义类时遇到问题。当初始化更新属性的类时,我需要在一些数据上设置一个观察者。最初,属性可以为空,这就是我在启动时设置它们的方式。但是,Xcode仍然会抛出“在所有成员初始化之前由闭包捕获的‘self’”错误。这是代码的简化版本。classFoo{init(){self.usersRef=ref.child("users")self.usersRef.observe(DataEventType.value,with:{(snapshot)in//snapshoterrorchecking//usersis[String]self.users=users})}privateva

ios - `UnsafeMutablePointer.initialize()`到底是做什么的?

以下是我的猜测。请大家指出我理解错误的部分。如果我有一个类,其中一个实例占用128位,叫做Class128Bits.我的程序在64位计算机上运行。首先,我调用letpointer=UnsafeMutablePointer.allocate(capacity:2)内存布局应该是这样的:000-063064bitschaos064-127064bitschaos128-255128bitschaos256-383128bitschaos如果我调用pointer.pointee=aClass128Bits,它崩溃了,因为前两个网格中的指针还没有被初始化。访问它们指向的内容会导致不可预测的结果

ios - Swift 3.0 中的 UICollectionViewController 错误 : must be initialized with a non-nil layout parameter

我是iOS开发新手。我一直在学习Swift,今天,我尝试使用UICollectionViewController。我的代码如下:classViewController:UICollectionViewController,UICollectionViewDelegateFlowLayout{varcolView:UICollectionView!overridefuncviewDidLoad(){super.viewDidLoad()//Doanyadditionalsetupafterloadingtheview,typicallyfromanib.letlayout:UIColle

ios - swift 错误 : Struct 'XX' must be completely initialized before a member is stored to

我正在尝试在Swift中定义AudioStreamBasicDescription。在Objective-C中,我使用了如下代码。AudioStreamBasicDescriptionASBD;ASBD.mSampleRate=8000;ASBD.mFormatID=kAudioFormatLinearPCM;ASBD.mFormatFlags=kAudioFormatFlagsCanonical|kAudioFormatFlagIsSignedInteger|kAudioFormatFlagIsPacked;ASBD.mFramesPerPacket=1;ASBD.mChannels

opensslErrorStack: [ ‘error:03000086:digital envelope routines::initialization error‘ ]

如果遇到了OpenSSL错误opensslErrorStack:[‘error:03000086:digitalenveloperoutines::initializationerror’],并且使用的是Node.js,可以尝试以下解决方案:“dev”:“setNODE_OPTIONS=–openssl-legacy-provider&&vue-cli-serviceserve”找到项目的package.json文件。在"scripts"部分“dev”:“vue-cli-serviceserve”添加“setNODE_OPTIONS=–openssl-legacy-provider”设置为“d

ios - 它显示 "required initializer init must be provided in subclass of UIControl"当我覆盖 init(frame : CGRect)

此代码有效:importUIKitclasswheel:UIControl{}但是这段代码没有:classwheel:UIControl{overrideinit(frame:CGRect){super.init(frame:frame)}当我覆盖init(frame:CGRect)而不是init(coderaDecoder:NSCoder).为什么我必须执行init(coderaDecoder:NSCoder)?如果我没有实现init(frame:CGRect)为什么我不需要实现它?我找到了一个类似的StackOverflow帖子,但没有解释:Swift:Error:'require

ios - Swift 类中的自定义初始化给出 'property not initialized at implicitly generated super.init call' 错误?

我正在尝试创建一个简单的类用作我的MKMapView的注释。我正在获取要解析到这些注释对象中的数据,并认为用字典初始化注释是个好主意,并在这个模型类中而不是在UIViewController。不过,我似乎无法摆脱编译器错误,每当我尝试修复一个错误时,就会出现另一个错误。当前正在获取未在隐式生成的super.init调用中初始化的“属性self.coordinate”。调用super.init()只会产生不同的错误“Propertyself.coordinatenotinitializedatsuper.initcall”,无论我在哪里在方法中调用super.init()。任何帮助将非常

ios - Swift - NSIndex forRow inSection Initializer

我有以下代码:varpath=NSIndexPath(forRow:index,inSection:0);我收到一条编译器警告:调用中的额外参数“inSection”为什么?我在这里的文档中看到了初始化程序:https://developer.apple.com/library/ios/documentation/UIKit/Reference/NSIndexPath_UIKitAdditions/index.html#//apple_ref/occ/clm/NSIndexPath/indexPathForRow:inSection:我导入了UIKit,甚至尝试做类似的事情:varpa

ios - swift 核心数据 : error: Failed to call designated initializer on NSManagedObject class 'NSManagedObject'

我正在使用核心数据在vc1中保存一个类别,并想将列表属性添加到vc2中的列表中。我的数据模型是许多列表属性的一个类别。我在vc1中添加这样的类别:funccreateNewCategory(){varcategory:NSManagedObject!=NSEntityDescription.insertNewObjectForEntityForName("Category",inManagedObjectContext:self.context)asNSManagedObjectcategory.setValue(self.categoryTextField.text,forKey:"

ios - Swift 类 : Property not initialized at super. init 调用中的错误 - 如何初始化需要在其初始化参数中使用 self 的属性

我正在快速覆盖UITableViewController,其中我有两个必需的变量,它们是通过使用self的weak引用初始化的,因为这些用于实现UITableViewDataSource协议(protocol),需要self引用才能使用其tableView属性classVideosListViewController:UITableViewController{requiredinit(coderaDecoder:NSCoder){super.init(coder:aDecoder)self.datasourceOfflineVideos=ASDataSource(tableViewC