草庐IT

nsobject

全部标签

objective-c - 如何将 NSDictionary 转换为 Swift Dictionary<String, NSObject>?

我正在用Swift重写一个Objective-C类,以感受一下这门语言。在Objective-C中,我的类包含以下方法:-(id)initWithCoder:(NSCoder*)aDecoder{return[selfinitWithActionName:[aDecoderdecodeObjectOfClass:[NSStringclass]forKey:@"actionName"]payload:[aDecoderdecodeObjectOfClass:[NSDictionaryclass]forKey:@"payload"]timestamp:[aDecoderdecodeObje

swift - 我可以在 Swift 中将默认类型分配给泛型类型 T 吗?

我有一个泛型类,我希望它能够与默认类型一起使用。现在我可以用任何类型初始化它,但我必须明确。//InitializewithatypeMyManager()//InitializewithNSObject(whatIwanttobemydefaulttype)MyManager()//Thisdoesn'twork,butIwantthiskindoffunctionalityclassMyManager{}//SoIcancreatemymanagerlikesoanditinsertsthedefaulttypeasNSObjectMyManager()//OrMyManager(

swift - 我可以在 Swift 中将默认类型分配给泛型类型 T 吗?

我有一个泛型类,我希望它能够与默认类型一起使用。现在我可以用任何类型初始化它,但我必须明确。//InitializewithatypeMyManager()//InitializewithNSObject(whatIwanttobemydefaulttype)MyManager()//Thisdoesn'twork,butIwantthiskindoffunctionalityclassMyManager{}//SoIcancreatemymanagerlikesoanditinsertsthedefaulttypeasNSObjectMyManager()//OrMyManager(

swift - 为什么在 swift 中我们不能在不从 NSObject 继承类的情况下采用协议(protocol)?

如果我使用下面的代码,它会显示错误“类型‘HttpConnection’不符合协议(protocol)‘NSObjectProtocol’”classHttpConnection:NSURLConnectionDataDelegate{varurlConnection:NSURLConnection?weakvardelegate:HttpConnecting?init(delegate:HttpConnecting){self.delegate=delegate;}funcstartAsynRequestWithUrlString(url:NSString,withMethod:NS

swift - 为什么在 swift 中我们不能在不从 NSObject 继承类的情况下采用协议(protocol)?

如果我使用下面的代码,它会显示错误“类型‘HttpConnection’不符合协议(protocol)‘NSObjectProtocol’”classHttpConnection:NSURLConnectionDataDelegate{varurlConnection:NSURLConnection?weakvardelegate:HttpConnecting?init(delegate:HttpConnecting){self.delegate=delegate;}funcstartAsynRequestWithUrlString(url:NSString,withMethod:NS

swift - Swift 的 hash 和 hashValue 的区别

Swift中的Hashable协议(protocol)要求您实现一个名为hashValue的属性:protocolHashable:Equatable{///Returnsthehashvalue.Thehashvalueisnotguaranteedtobestable///acrossdifferentinvocationsofthesameprogram.Donotpersistthehash///valueacrossprogramruns.//////Thevalueof`hashValue`propertymustbeconsistentwiththeequality///

swift - Swift 的 hash 和 hashValue 的区别

Swift中的Hashable协议(protocol)要求您实现一个名为hashValue的属性:protocolHashable:Equatable{///Returnsthehashvalue.Thehashvalueisnotguaranteedtobestable///acrossdifferentinvocationsofthesameprogram.Donotpersistthehash///valueacrossprogramruns.//////Thevalueof`hashValue`propertymustbeconsistentwiththeequality///

ios - [NSObject : AnyObject] ?' does not have a member named ' subscript' error in Xcode 6 beta 6

当键盘显示在屏幕上时,我使用下面的几行代码来获取键盘的框架。我已经注册了UIKeyboardDidShowNotification通知。funckeyboardWasShown(notification:NSNotification){varinfo=notification.userInfovarkeyboardFrame:CGRect=info.objectForKey(UIKeyboardFrameEndUserInfoKey).CGRectValue()}这曾经在beta5中工作。我下载了最新的Xcode6版本,它是beta6,这个错误发生在第二行。'[NSObject:Any

ios - [NSObject : AnyObject] ?' does not have a member named ' subscript' error in Xcode 6 beta 6

当键盘显示在屏幕上时,我使用下面的几行代码来获取键盘的框架。我已经注册了UIKeyboardDidShowNotification通知。funckeyboardWasShown(notification:NSNotification){varinfo=notification.userInfovarkeyboardFrame:CGRect=info.objectForKey(UIKeyboardFrameEndUserInfoKey).CGRectValue()}这曾经在beta5中工作。我下载了最新的Xcode6版本,它是beta6,这个错误发生在第二行。'[NSObject:Any

swift - -[NSObject description] 的 Swift 等价物是什么?

在Objective-C中,可以在类中添加一个description方法来帮助调试:@implementationMyClass-(NSString*)description{return[NSStringstringWithFormat:@"",[selfclass],foo_foo];}@end然后在调试器中,您可以:pofooClassSwift中的等价物是什么?Swift的REPL输出可能会有所帮助:1>classMyClass{letfoo=42}2>3>letx=MyClass()x:MyClass={foo=42}但我想覆盖此行为以打印到控制台:4>println("x=