草庐IT

uniform-initialization

全部标签

swift - 在 Swift 3.1 中,UnsafeMutablePointer.initialize(from :) is deprecated

在Swift3.1中,不推荐使用UnsafeMutablePointer.initialize(from:)。Xcode建议我改用UnsafeMutableBufferPointer.initialize(from:)。我有一个看起来像这样的代码块:letpointer=UnsafeMutablePointer.allocate(capacity:64)pointer.initialize(from:repeatElement(0,count:64))由于弃用,代码给了我一个编译时警告。所以我要把它改成:letpointer=UnsafeMutablePointer.allocate(

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

Swift - 播种 arc4random_uniform?还是另类?

让我首先说明我要完成的任务:我需要在一定范围内随机生成一组数字我希望这些数字稍微均匀分布我需要能够为随机数生成播种,这样,给定一个种子,生成的随机数将始终相同。在对drand48()、rand()和arc4random()进行了大量试验后,我目前决定使用rand()获取随机数,并使用srand()进行播种。这是一个从我正在做的事情中简化而来的小例子:letseed:UInt32=10srand(seed)letstart=0letend=100letrandomNumber=Double(rand())%(end+1-start)+start这行得通。给定相同的种子,会产生相同的随机数