草庐IT

Duck-typing

全部标签

ios - Xcode 4.6.3 中的解析问题 - "Expected a type"- 找不到错误

Xcode有问题:目前我正在为iOSSDK6.1开发一个应用程序。前几天我正在实现一些方法并尝试编译项目。然后奇怪的事情发生了:编译失败,我在两个文件中遇到了一些错误(见下图),这与我使用的方法无关。我搜索了我的代码中的错误,但找不到任何错误。然后我关闭项目再打开:他们还在这里。然后我关闭项目和Xcode,然后重新打开它们:它们还在这里。然后我新建了一个项目,把所有的代码都复制过来:问题又出现了。现在我被困住了,不知道该怎么办。我是否遗漏了我的代码中的某些内容?请帮帮我!---编辑1:这里有一些代码片段,在我遵循MartinR的建议后应该显示我的代码://PlayingCardDeck

iphone - 我在 iOS 的 Xcode 中收到 "Implicit conversion from enumeration type"警告,我不知道为什么

使用这段代码:NSDataDetector*detector=[NSDataDetectordataDetectorWithTypes:NSTextCheckingTypeLinkerror:&error];我收到这个警告:Implicitconversionfromenumerationtype'enumNSTextCheckingType'todifferentenumerationtype'NSTextCheckingTypes'(aka'enumNSTextCheckingTypes')有人可以向我解释为什么会收到此警告以及如何解决吗? 最佳答案

ios - Xcode : Expected method to write array element not found on object of type 'NSArray *' 错误

我有另一个数组问题...我声明了一个数组如下:NSArray*sliderValAtTimes;这是有错误的代码:代码:sliderValAtTimes[x]=sliderValue;错误:在“NSArray*”类型的对象上找不到写入数组元素的预期方法声明:intx=0;sliderValue=[[NSStringalloc]initWithFormat:@"%0.0f",self.slider.value];任何帮助都会很棒! 最佳答案 NSArray是不可变的。您不能替换NSArray的元素。你需要一个NSMutableArra

objective-c - "property with ' weak' attribute must be of object type"是什么意思?

我的界面中有这个:@property(nonatomic,weak)NSTimeInterval*timeStamp;我的逻辑告诉我,我需要一个时间戳对象,这个对象只会在实例化的上下文中被这个类使用,所以“弱”对我来说似乎是合乎逻辑的——但XCode告诉我“具有“弱”属性的属性必须是对象类型“......如果我这样做:@property(nonatomic)NSTimeInterval*timeStamp;然后错误消失了,但我不确定我明白为什么...... 最佳答案 问题是NSTimeInterval是一个值类型——它是double

ios - "collection element of type BOOL"不是 objective-c 对象

有人知道我为什么会收到这个吗?-(void)postPrimaryEMWithEM:(EM*)emexclusive:(BOOL)isExclusivesuccess:(void(^)())onSuccessfailure:(void(^)())onFailure{if(self.accessToken){GenericObject*genObject=[[GenericObjectalloc]init];[[RKObjectManagersharedManager]postObject:genObjectpath:@"users/update.json"parameters:@{..

ios - 从我的模型文件生成新的 NSManagedObject 子类时,我应该检查 “Use scalar properties for primitive data types” 吗?

我使用CoreData创建了一个项目,并在.model文件中创建了一个名为Targets的实体。我添加了这两个实体属性:content(String)targetID(Integer32)当我生成NSManagedObject子类时,Xcode会询问我:Usescalarpropertiesforprimitivedatatypes?从我的模型文件生成新的NSManagedObject子类时,我应该选中此框吗? 最佳答案 如果选中该框,Xcode将为这些属性生成标量类型(例如,int、float、double)。如果未选中,属性将为

c - 警告 : passing argument 2 of ‘getsockname’ from incompatible pointer type

我想不通。谁能告诉我为什么会出现此错误:警告:从不兼容的指针类型传递“getsockname”的参数2在下面的代码中:#include#include#include#include#include#includeintmain(){intsd;structsockaddr_inmy_addr;bzero(&my_addr,sizeof(my_addr));my_addr.sin_family=AF_INET;my_addr.sin_addr.s_addr=inet_addr("127.0.0.1");my_addr.sin_port=htons(0);my_addr.sin_addr

class - 带有 NSBundle 的段错误 11(对于类 :) and multiple type constraint (protocol + class)

以下代码在模拟器中运行良好,但在创建存档时抛出“Commandfaileddutosignal:Segmentationfault:11”。funcpopAction(){MyViewController.pop(self)}classfuncpop(controller:T){letbundle=NSBundle(forClass:controller.dynamicType)//…}下面的编译就好了:letbundle=NSBundle(forClass:object_getClass(self))//orletbundle=NSBundle(forClass:self)dynam

swift - 找不到名为 Type 的枚举

我有一个包含枚举的结构:publicstructTemperatureUnit:Unit{publicenumType{caseCelsiuscaseFahrenheit}publicvartype:Typepublicinit(type:Type){self.type=type}publicfuncgetFormattedStringForValue(value:Int)->String{if(self.type==.Celsius){return"\(value)°C"}else{return"\(value)°"}}}当我尝试在代码的其他地方使用枚举时,编译器给我一个错误。该问题

arrays - 无法调用类型 : with an argument list of type: 的初始值设定项

对我做错了什么有什么建议吗?初始化对象时,我似乎无法将另一个类的数组作为参数。这是我的具体情况:我正在尝试创建一个锻炼应用程序。该应用程序包含几种不同的锻炼。每项锻炼都有其独特的一系列训练。我有我的WorkoutObj代码(这个结构创建了一个锻炼并且需要一个NSArrayworkoutDrillSet)importUIKitstructWorkoutObj{varworkoutType:NSStringvarworkoutNumber:IntvarworkoutDesc:NSStringvarworkoutDuration:IntvarworkoutDrillSet:NSArrayin