草庐IT

compound-assignment

全部标签

ios - 为什么 Obj-C 属性默认所有权为 "assign"而不是 "strong"

我正在向旧项目添加Swift类。一切顺利,直到我尝试向Swift类添加一个属性。生成的header无法编译。我认为问题在于,在生成的代码中,Swift省略了strong所有权,仅将其声明为nonatomic。这通常应该足够了,因为@property应该默认为strong所有权,对吧?所以基本上这些是等价的:@property(nonatomic)NSDate*aDate;@property(nonatomic,strong)NSDate*aDate;但是,在我的例子中,根据编译器消息,它似乎默认为assign而不是strong。我正在使用Xcode6GM,并且该项目已打开ARC。知道为

swift - "Initialisation of immutable value' 上下文 ' was never used, consider replacing assignment to ' _' 或删除它

我在swift中声明了一个变量letcontext:LAContext=LAContext()发出警告"Initialisationofimmutablevalue'context'wasneverused,considerreplacingassignmentto'_'orremovingit. 最佳答案 都在错误信息里value...wasneverused您的变量未在任何地方使用,因此Xcode告诉您可以删除它(因为拥有未使用的变量会浪费内存)。只需在某处使用您的变量,错误就会消失(例如,从中获取一个值,打印它等)。当然是指在

ios - 错误 : Assigning non-escaping parameter 'publicationQuery' to an @escaping closure

我有一个像这样的ViewController:classPublicationListViewController:UIViewController{varpublicationQuery:(()->[Publication])!funcinitWith(title:String,publicationQuery:()->[Publication]){self.title=titleself.publicationQuery=publicationQuery}}为什么我会收到“将非转义参数‘publicationQuery’分配给@escaping闭包”错误?

swift 4 : Cannot assign value of type '(_) -> Void' to type '(() -> ())?'

XCode9,Beta3。Swift4。letbutton=JumpingButton(x:0,y:50,w:150,h:300)//JumpingButton:UIButton//InsideJumpingButton://varclickAction:(()->())?button.clickAction={(sender)->Voidin//Errorlineaction()Sound.playSound(Sounds.Button)}出现错误:无法将类型“(_)->Void”的值分配给类型“(()->())?” 最佳答案 因

swift - SpriteKit : why node in collision has category bit mask of 4294967295 when this category was never assigned to a node

在下面的didBegin函数中,其中一个节点的类别位掩码为4294967295。但是,此类别从未分配给任何节点。这里是所有使用的位掩码:structPhysicsCategory{staticletNone:UInt32=0staticletAll:UInt32=UInt32.maxstaticletPlayer:UInt32=0b1//1staticletWorldBorder:UInt32=0b10//2staticletTopWorldBorder:UInt32=0b100//4staticletRightWorldBorder:UInt32=0b1000//8staticlet

swift - 协议(protocol) : Cannot assign to 'X' in 'Y' in Swift

我刚刚定义了一个非常简单的协议(protocol)和一个使用泛型的类来处理这个协议(protocol)。在标有错误的行中,您将收到错误:“无法分配给‘aObj’中的‘标志’。protocolFlag{varflag:Bool{getset}}classTestFlag{functoggle(aObj:T){ifaObj.flag{aObj.flag=false;//您知道为什么以及我必须更改什么来修复它吗? 最佳答案 来自docs:Functionparametersareconstantsbydefault.Tryingtocha

python - 深度学习 Udacity 类(class) : Prob 2 assignment 1 (notMNIST)

看完this并参加类(class),我正在努力解决作业1(notMnist)中的第二个问题:Let'sverifythatthedatastilllooksgood.Displayingasampleofthelabelsandimagesfromthendarray.Hint:youcanusematplotlib.pyplot.这是我尝试过的:importrandomrand_smpl=[train_datasets[i]foriinsorted(random.sample(xrange(len(train_datasets)),1))]print(rand_smpl)filena

python - UnboundLocalError : local variable 'x' referenced before assignment. 在数据帧的 seaborn 包中正确使用 tsplot?

我无法让它对我的数据起作用,所以首先我尝试了一个非常相似的具体示例。这是数据框:In[56]:idx=pd.DatetimeIndex(start='1990-01-01',freq='d',periods=5)data=pd.DataFrame({('A','a'):[1,2,3,4,5],('A','b'):[6,7,8,9,1],('B','a'):[2,3,4,5,6],('B','b'):[7,8,9,1,2]},idx)Out[56]:ABabab1990-01-0116271990-01-0227381990-01-0338491990-01-0449511990-01-

python - functools.wraps的 `assigned`和 `updated`参数如何使用?

我知道包装有如下属性:functools.wraps(wrapped[,assigned][,updated])但我想知道如何使用assigned和updated参数,有人有例子吗? 最佳答案 “已分配”参数告诉包装函数上的哪些属性将分配给包装(装饰)函数上的同名属性。默认情况下,它们是'__module__'、'__name__'、'__doc__',它们在变量functools.WRAPPER_ASSIGNMENTS中被定义为默认值。正如@abarnet在评论中所说,另一个可能想要复制的属性示例是Python3.x中的函数注释-

python - 为什么使用 pandas.assign 而不是简单地初始化新列?

我刚刚发现了pandas数据帧的assign方法,它看起来不错并且与R中dplyr的mutate非常相似。但是,我总是通过“即时”初始化一个新列。assign更好的原因是什么?例如(基于pandas文档中的示例),要在数据框中创建一个新列,我可以这样做:df=DataFrame({'A':range(1,11),'B':np.random.randn(10)})df['ln_A']=np.log(df['A'])但是pandas.DataFrame.assign文档建议这样做:df.assign(ln_A=lambdax:np.log(x.A))#ornewcol=np.log(df[