Tag: 目标C

在Swift上委托Objective-C协议

我使用Swift语言在iOS上实现UDP Listener。 为此,我在CocoaAsyncSocket项目上继续。 我成功地使用Bridging-Header.h导入CocoaAsyncSocket库,我可以从Objective-C类调用函数,但是我无法在swift上编写委托函数。 这是我设置Socket并将ViewController.swif定义为侦听器的委托类的代码: func setupSocket() { var udpSocket : GCDAsyncUdpSocket = GCDAsyncUdpSocket(delegate: self, delegateQueue: dispatch_get_main_queue()) var error : NSError? let port : UInt16 = 12121 let address : String = "228.5.12.12" udpSocket.bindToPort(port, error: &error) udpSocket.joinMulticastGroup(address, error: &error) udpSocket.enableBroadcast(true, error: &error) println("228.5.12.12") } 这是Objective-C中的前一个委托函数: – (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data fromAddress:(NSData *)address withFilterContext:(id)filterContext; 最后,这就是我在Swift上实现的function: override […]

extern NSString * const在一个类中。

嗨,我有这个头文件: #import <Foundation/Foundation.h> @interface PCConstants : NSObject extern NSString *const kPCUserProfileKey; extern NSString *const kPCUserProfileNameKey; extern NSString *const kPCUserProfileFirstNameKey; extern NSString *const kPCUserProfileLocationKey; extern NSString *const kPCUserProfileGenderKey; extern NSString *const kPCUserProfileBirthDayKey; extern NSString *const kPCUserProfileInterestedInKey; @end 执行: #import "PCConstants.h" @implementation PCConstants NSString *const kPCUserProfileKey = @"profile"; NSString *const kPCUserProfileNameKey = @"name"; NSString *const kPCUserProfileFirstNameKey = […]

如何从目标C中的文件创build私钥?

我已经创build了这样的公钥: NSString *pkFilePath = [[NSBundle mainBundle] pathForResource:@"public_key" ofType:@"der"]; NSData *myCertData = [NSData dataWithContentsOfFile:pkFilePath]; SecCertificateRef cert = SecCertificateCreateWithData (kCFAllocatorDefault, (CFDataRef)myCertData); CFArrayRef certs = CFArrayCreate(kCFAllocatorDefault, (const void **) &cert, 1, NULL); SecTrustRef trust; SecPolicyRef myPolicy = SecPolicyCreateBasicX509(); SecTrustCreateWithCertificates(certs, myPolicy, &trust); SecTrustResultType trustResult; SecTrustEvaluate(trust, &trustResult); SecKeyRef pub_key_leaf = SecTrustCopyPublicKey(trust); NSLog(@"%@",pub_key_leaf); 但是如何从文件创build私钥? 这里有一些相关的代码来创build一个私钥,但我没有得到如何使用我的私钥文件创build私钥。 https://developer.apple.com/library/mac/#documentation/security/conceptual/CertKeyTrustProgGuide/iPhone_Tasks/iPhone_Tasks.html#//apple_ref/doc/uid/TP40001358-CH208-SW10

如何防止JSONKit从ASP.NET JSONdate格式转义反斜杠?

我正在使用JSONKit在ASP.NET RESTful服务之间对JSON进行编码/解码。 服务使用的date格式在这里讨论,如下所示: "\/Date(1198908717056)\/" 问题是当JSONKit处理一个看起来像上面的string时,它会转义反斜杠,所以最终结果如下所示: "\\/Date(1198908717056)\\/" JSON规范说你可以select转义正斜杠(/),所以JSONKit应该解释“\ /”原样,而不是转义反斜杠。 有没有人知道一种方法来防止JSONKit逃避反斜杠时,正如上面的情况下的ASP.NET JSONdate格式的正斜杠?

bodyWithEdgeLoopF​​romRect不能在横向工作

我只是试图在景观中设置一个基本场景,引力,并在一个边缘循环的场景。 我设置了场景的物理体和mainCharacter精灵物理体,这里是我的代码: -(id)initWithSize:(CGSize)size { if (self = [super initWithSize:size]) { self.backgroundColor = [SKColor redColor]; [self setPhysicsBody:[SKPhysicsBody bodyWithEdgeLoopFromRect:[self frame]]]; } return self; } -(void)setupMain { if (!self.mainCharacter) { self.mainCharacter = [[SKSpriteNode alloc] initWithImageNamed:@"spriteDefault"]; [self.mainCharacter setPosition:CGPointMake(CGRectGetMidX([self frame]), CGRectGetMidY([self frame]))]; [self addChild:self.mainCharacter]; self.mainCharacter.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.mainCharacter.frame.size]; self.mainCharacter.physicsBody.dynamic = YES; self.mainCharacter.physicsBody.affectedByGravity = YES; self.mainCharacter.physicsBody.mass = 0.02; } } 所以,在肖像模式下,一切都很完美,但是在风景中,事情变得非常棘手。 […]

'BOOL'(又名'signed char')到'id'的隐式转换,objc_setAssociatedObject

我正在使用关联的引用作为我的类别的属性的存储 头文件包含: @interface UIImageView (Spinning) @property (nonatomic, assign) BOOL animating; @end 执行是 – (void)setAnimating:(BOOL)value { objc_setAssociatedObject(self, animatingKey, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } 但是,我得到了上面的行警告 Implicit conversion of 'BOOL' (aka 'signed char') to 'id' is disallowed with ARC 如果你知道我在这里做错了什么,请帮助如何避免这个问题

如何绘制渐变填充弧,即彩虹?

以下代码绘制了一个从红色到绿色渐变的半圆。 这不是我想要的。 我期望一个宽度为5像素的圆弧,用渐变绘制。 任何帮助显示我出了什么地方将不胜感激。 查尔斯 -(void) DrawRainbow { // Create an arc path float x = 150.0; float y = 220.0; float radius = 75.0; float startAngle = M_PI; float endAngle = 2*M_PI; bool clockWise = false; CGMutablePathRef path = CGPathCreateMutable(); CGPathAddArc(path, nil, x, y, radius, startAngle, endAngle, clockWise); // Setup the gradient size_t num_locations […]

upnpx库中的Apple Mach-O链接程序错误

使用upnpx库时遇到一个小问题。 我已经下载了库并打开了upnpdemo工作区。 我在同一个工作区创build了一个新项目,试图用这个库创build一个简单的应用程序。 我设置了一个演示项目的参数,但是XCode返回了21个错误: Apple Mach-O Linker Error Undefined symbols for architecture i386: "std::string::find(char const*, unsigned long) const", referenced from:

受支持的平台,基础SDK,仅在pod更新后恢复主动体系结构设置

我的团队最近开始雇用CocoaPods来pipe理我们的iOS应用程序项目中的依赖项。 这是podfile: platform :ios, '6.0' pod "UI7Kit" pod "AFNetworking", "~> 2.0" pod "TMCache" pod "SVProgressHUD" pod "SVPullToRefresh" 但是,使用CocoaPods后,build立iPhone 5的目标总是失败,但成功的模拟器。 这里是错误日志: ld: warning: ignoring file [DerivedData directory]/libPods.a, file was built for archive which is not the architecture being linked (armv7): [DerivedData directory]/libPods.a Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SVProgressHUD", referenced from: objc-class-ref in ….o "_OBJC_CLASS_$_TMCache", referenced from: […]

为什么你有时候会把一个NSArray转换成NSMutableArray,有时你不能呢?

特别: self.words = (NSMutableArray*)[self.text componentsSeparatedByString:@" "]; 只要有分离器就能正常工作。 但是我发现如果没有这个方法的话,这个方法会返回一个包装在NSArray中的原始string。 这个单独的元素NSArray固执地拒绝被转换为一个NSMutableArray。 但是,当我这样做: self.words = [NSMutableArray arrayWithArray:self.words]; 它工作得很好。 有什么我在这里失踪? 从NSArray投射到NSMutableArray是不好的做法吗?