Tag: nsobject

在Swift NSObject子类中使用CoreFoundation对象时发生运行时错误

下面是一个非常简单的类( NSObject子类),该类保存CGPath对象列表,并在init CGPath一个CGPath追加到数组: import Foundation class MyClass: NSObject { var list = [CGPath](); init() { list.append(CGPathCreateMutable()); } } 当试图使用这个类时: var instance = MyClass(); println(instance.list.count); // runtime error after adding this line 产生一个难看的崩溃: Playground execution failed: error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0). The process has been left at the point where it was interrupted, […]

基于NSObject的类的iOS JSON序列化

我想要JSON序列化我自己的自定义类。 我在Objective-C / iOS5中工作。 我想要做的事情如下: Person* person = [self getPerson ]; // Any custom object, NOT based on NSDictionary NSString* jsonRepresentation = [JsonWriter stringWithObject:person ]; Person* clone = [JsonReader objectFromJson: jsonRepresentation withClass:[Person Class]]; 看来,NSJSONSerialization(和其他一些库)需要“人”类基于NSDictionary等我想要的东西,将序列化任何自定义对象,我关心定义(在合理的范围内)。 让我们设想Person.h如下所示: #import <Foundation/Foundation.h> @interface Person : NSObject @property NSString* firstname; @property NSString* surname; @end 我想为实例生成的JSON看起来类似于以下内容: {"firstname":"Jenson","surname":"Button"} 我的应用程序使用ARC。 我需要使用对象序列化和反序列化的东西。 非常感谢。

如何复制UILabel?

我有IBOutlet UILabel *label; 我想这样做 UILabel *label = [titleLabel copy]; label.text = @"Clone"; titleLabel.text = @"Original"; NSLog(@"label : %@, title : %@",label.text,titleLabel.text); 这抛出exception *由于未捕获exception'NSInvalidArgumentException',原因:' – [UILabel copyWithZone:]:无法识别的select器发送到实例0x6a4a450'*终止应用程序*第一次抛出调用堆栈:(0x126f052 0x1823d0a 0x1270ced 0x11d5f00 0x11d5ce2 0x1271bd9 0x2ed6 0x1270e1a 0x2851 0x28264e 0x1e2a73 0x1e2ce2 0x1e2ea8 0x1e9d9a 0x24af 0x1ba9d6 0x1bb8a6 0x1ca743 0x1cb1f8 0x1beaa9 0x215cfa9 0x12431c5 0x11a8022 0x11a690a 0x11a5db4 0x11a5ccb 0x1bb2a7 0x1bca9b 0x21c2 0x2135)

什么是__NSArrayI和__NSArrayM? 如何转换为NSArray?

什么是__NSArrayI和__NSArrayM? __NSArrayI(或M)导致“无法识别的select器”错误。 如何转换为NSArray? 我做了testing来parsingjson,twitter api。 http://api.twitter.com/1/followers/ids.json?cursor=-1&screen_name=twitterapi ==>正常工作。 parsing对象是NSCFDictionary类。 (这个字典包含__NSArrayM类) http://api.twitter.com/1/statuses/user_timeline.json?&screen_name=twitterapi ==>错误。 parsing对象是__NSArrayM类。

'Set <NSObject>'没有一个名为'anyObject'的成员 – Xcode 6.3

我正在检查是否已经select了一个元素。 func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) { // First, see if the game is in a paused state if !gamePaused { // Declare the touched symbol and its location on the screen let touch = touches.anyObject! as? UITouch let location = touch.locationInNode(symbolsLayer) 而这之前已经在Xcode 6.2中编译好了,但是在6.3更新的时候,“let touch = touches.anyObject!as?UITouch”就是抛出这个错误: 'Set'没有名为'anyObject'的成员 我已经阅读了许多类似的问题,但我似乎无法绕过我的头。“要使用这个值,你需要先”解开“它。 特别是因为答案似乎集中在通知。 非常感谢。 w ^