草庐IT

local-class

全部标签

swift - NSTimer scheduledTimerWithTimeInterval 和目标是 "class level function"

如何在Swift中设置target(调用类级函数),就像在obj-c中完成的那样:callaclasslevelmethodinscheduledTimerWithTimeInterval 最佳答案 classMyClass:NSObject{classfuncstartTimer(){NSTimer.scheduledTimerWithTimeInterval(2.0,target:MyClass.self,selector:"callByTimer:",userInfo:nil,repeats:true)}classfuncca

ios - 使用自定义框架时出现"Unknown class BarChartView in Interface Builder file"错误

我正在尝试在我的应用程序中使用图表框架。我已经使用迦太基为此构建了二进制文件并将其添加到我的应用程序中,其中包含两个文件:-Charts-Swift.h-Charts.h然后我将View的自定义类设置为BarChartView,但XCode似乎无法识别该类(无自动完成)。并且自定义模块也没有设置。当我运行该应用程序时,我总是收到此警告:UnknownclassBarChartViewinInterfaceBuilderfile我已经尝试了一些来自互联网的解决方案,但似乎对我来说没有任何效果。任何人都有针对Xcode8.1和Swift3的解决方案? 最佳答案

Swift 2.0 获取镜像父类(super class)属性

我需要将类的属性作为字典获取。为简单起见,我创建了一个默认实现如下的协议(protocol):protocolListsProperties{functoDictionary()->[String:AnyObject]}extensionListsProperties{functoDictionary()->[String:AnyObject]{letmirrored_object=Mirror(reflecting:self)vardict=[String:AnyObject]()for(_,attr)inmirrored_object.children.enumerate(){if

ios - 为什么在注册子类时出现错误 "the class ... must be registered with registerSubclass before using Parse"?

从iOSparse-library-1.6.3升级到parse-library1.7.5后,我在我的一个PFQueryTableViewController的queryForTable中收到以下错误:Terminatingappduetouncaughtexception'NSInternalInconsistencyException',reason:'TheclassAppname.AttendingModelmustberegisteredwithregisterSubclassbeforeusingParse.'但是,我在application:didFinishLaunchi

Swift 协议(protocol)错误 : 'weak' cannot be applied to non-class type

Protocols和class-boundProtocols有什么区别,我们应该在Swift中使用哪一个?protocolA:class{...}protocolA{...}当协议(protocol)未定义为:class时尝试添加weak委托(delegate)时出现错误:protocolA{...}weakvardelegate:A给出错误:'weak'cannotbeappliedtonon-classtype或'weak'mustnotbeappliedtonon-class-bound'A';consideraddingaprotocolconformancethathasac

ios - 快速替换 'Class'

我正在从objective-C转向Swift。头文件是:@interfaceRegisterType:NSObject{Classtype;NSString*typeName;NSString*namespace;inttypeId;}@property(nonatomic,retain)Classtype;@property(nonatomic,retain)NSString*typeName;@property(nonatomic,retain)NSString*namespace;@property(nonatomic)inttypeId;@end实现是:@implementat

ios - 带有 Swift UIApplication 子类的 Objective-C 项目。错误 : class not loaded

我有一个用Objective-C编写的项目,我刚刚使用Swift添加了一个UIApplication子类:RMFApplication.swift(在文章末尾实现)。但是,我收到此错误:Terminatingappduetouncaughtexception'NSInternalInconsistencyException',reason:'UnabletoinstantiatetheUIApplicationsubclassinstance.NoclassnamedRMFApplicationisloaded.'在我的info.plist中我正确指定了名称NSPrincipalCla

class - Swift 类省略带闭包的括号 : syntactic sugar or something else?

我试图理解为什么在将block作为参数时可以在类初始化中省略圆括号。没有括号的例子:varblock=CCActionCallBlock{()->VoidinNSLog("sedfjsdkl")}这是带括号的形式上正确的版本:varblock=CCActionCallBlock({()->VoidinNSLog("sedfjsdkl")})两种变体都按预期工作,没有任何运行时错误或编译器警告。在什么情况下我可以省略类的初始化括号?这是相同的代码还是有任何副作用?关于闭包/block,还有其他我应该注意的语法糖吗?注意:我知道一个闭包作为最后一个参数可以写在括号之后,但找不到与省略括号相

Playground 上的 Swift 代码与实际类(class)

这里发生了奇怪的事情。以下代码:String(Int(date.timeIntervalSince1970*1000))在Playground上工作但不在类里面。它因EXC_BAD_INSTRUCTION而崩溃。有什么想法吗?或者,如何获取上述NSTimeInterval的字符串?提前致谢!编辑:我需要Int形式的结果,例如1402324472549而不是1402324472549.64。 最佳答案 在类定义中:vardate=NSDate()letmyDateString=String(Int64(date.timeInterva

ios - Swift - 带有 Objective-C 选择器 '*()' 的方法 '*' 与具有相同 Objective-C 选择器的父类(super class) '*' 的 'NSObject' 的 getter 冲突

自从将我的xcode更新到6.3.1后,我收到了这条错误消息。/Users/MNurdin/Documents/iOS/xxxxx/Models/Message.swift:46:10:Method'hash()'withObjective-Cselector'hash'conflictswithgetterfor'hash'fromsuperclass'NSObject'withthesameObjective-Cselector我的代码varhash_:UIntfunchash()->UInt{returnUInt(hash_);} 最佳答案