iOS CoreData与自身的反向关系

我试图build立一个类似于Twitter用户的CoreData模型,当用户可以有许多其他用户跟随他和许多其他用户跟着他。 我附加了我试图使用的模型,但似乎越来越复杂的检索追随者。 处理这种情况的最好方法是什么?

添加到SpriteKit中的父项时,未存档的节点不会显示

以前我一直在质疑是否可以使用场景编辑器创build复杂的SKSpriteNodes,而不是使用它来布局SKScenes。 在@Anton Rogachevskyi的帮助下,我开始使用unarchiveNodeFromFilefind.SKS文件。 它会像我所期望的那样加载sks文件,但是当我尝试将它添加到当前场景时,不会出现任何内容。 如果我在addChild行中断,并预览正确显示在预览窗口中的对象,所以我知道它find了正确的文件。 sks文件里面是一个自定义对话框类,并在“必需的init?(coder aDecoder:NSCoder)”中设置断点。“我可以告诉自定义对象正在初始化正确。 在对话框类的内部,我以编程方式向对象添加一个粉红色的框,以显示它到达类的init class TeamDialog: SKSpriteNode { init(size: CGSize) { super.init(texture: nil, color: .red, size: size) } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) setup() } func setup() { let pinkBox = SKSpriteNode(color: .magenta, size: CGSize(width: 100, height: 100)) pinkBox.zPosition = 500 addChild(pinkBox) } } 而在场景中,这是我如何find对象,并尝试将其添加到场景,它出现在预览中,但没有显示在屏幕上 private func displayDialog() { […]

Objective-C中的位转换工具

在iOS的objective-c库中是否有内置的实用程序或macros,这将允许您将字节转换为整数和整数? 请不要告诉我使用位移操作。 我试图避免编写自定义代码,如果它已经存在。 我想代码将NSData *转换为原始types(int,uint,short等),并将原始types转换回NSData *。

无法将types'NSObject – >() – > PostFeed'的值转换为期望的参数types'AnyObject?'

我以下面的方式添加一个UISwitch : let anonSwitch : UISwitch = { let mySwitch = UISwitch() mySwitch.on = false mySwitch.setOn(false, animated: false); mySwitch.tintColor = UIColor(red: (69/255.0), green: (209/255.0), blue: (153/255.0), alpha: 1.0) mySwitch.addTarget(self, action: #selector(handleAnonSwitch), forControlEvents: .ValueChanged) return mySwitch }() 现在,我在mySwitch.addTarget的self关键字上收到以下错误消息: Cannot convert value of type 'NSObject -> () -> PostFeed' to expected argument type 'AnyObject?' 我在我的所有其他addTarget函数为UIButton使用self ,我从来没有遇到这个错误

如何让我的精灵套件场景出现在UIView上方?

我已经做了一些search,但没有find任何直接解决我的问题:我有一个SKScene与几个SKNodes每个SKSpriteNode对象为我的游戏,我使用的背景UIImageView (有一些事情,我需要做的背景至less在我看来,这不可能合理地用sprite工具包来完成)。 我遇到的问题是UIImageView出现在一切之上,我看不到我的游戏对象。 在我的视图控制器(.m文件)我有以下代码来调用我的场景 @implementation GameViewController – (void)viewDidLoad { [super viewDidLoad]; SKView * skView = (SKView *)self.view; SKScene * scene = [GameScene sceneWithSize:skView.bounds.size]; scene.scaleMode = SKSceneScaleModeAspectFill; [skView presentScene:scene]; } 在上面的GameScene ,我有几个SKNodes ,其中我所有的游戏对象都是子nodeHDU (例如nodeHDU , nodePlay , nodePauseMenu …),我使用UIImageView作为背景(我在背景场景之间切换,使用一些不错的转换,如UIViewAnimationOptionTransitionCrossDissolve;不能使用SKSpriteNode作为背景来实现这一点,而不使用多个SKSpriteNodes和一个复杂的SKActions数组,所以我使用UIImageView ) UIView *backgrounds = [[UIView alloc] init]; [self.view insertSubview:backgrounds belowSubview:self.view]; UIImageView *imageBackground = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)]; [backgrounds […]

IOS多个左右alignment在同一行上

我想写在我的tableview单元格detailTextLabel的同一行。 例如Left string right string 。 我正在这样做: NSMutableAttributedString *descriptionAttribute = [[NSMutableAttributedString alloc] initWithString:descriptionString]; NSMutableAttributedString *dateAttribute = [[NSMutableAttributedString alloc] initWithString:finalDate]; NSMutableAttributedString *shareAttribute = [[NSMutableAttributedString alloc] initWithString:@"Share"]; NSMutableParagraphStyle *dateStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; [dateStyle setAlignment:NSTextAlignmentLeft]; NSMutableParagraphStyle *shareStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; [shareStyle setAlignment:NSTextAlignmentRight]; [dateAttribute addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(0, 13)]; [dateAttribute addAttribute:NSParagraphStyleAttributeName value:dateStyle range:NSMakeRange(0, 13)]; [shareAttribute addAttribute:NSForegroundColorAttributeName value:[UIColor […]

使用新的PHPhotoLibrary保存exif元数据

我目前使用AVCaptureStillImageOutput获得全分辨率的图片。 我也能够使用以下代码获取exif元数据: [self.stillImageOutput captureStillImageAsynchronouslyFromConnection:videoConnection completionHandler: ^(CMSampleBufferRef imageSampleBuffer, NSError *error) { CFDictionaryRef metaDict = CMCopyDictionaryOfAttachments(NULL, imageSampleBuffer, kCMAttachmentMode_ShouldPropagate); CFMutableDictionaryRef mutableDict = CFDictionaryCreateMutableCopy(NULL, 0, metaDict); NSLog(@"test attachments %@", mutableDict); // set the dictionary back to the buffer CMSetAttachments(imageSampleBuffer, mutableDict, kCMAttachmentMode_ShouldPropagate); NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageSampleBuffer]; UIImage *image = [[UIImage alloc] initWithData:imageData]; [self.delegate frameReadyToSave:image withExifAttachments: mutableDict]; }]; 元数据位于mutableDictvariables中。 现在,我想把这张照片保存在两个不同的地方,包括元数据。 […]

iOS Core Audio:在kAudioFormatFlagsCanonical和kAudioFormatFlagsAudioUnitCanonical之间转换

我需要在这个格式之间转换: format.mSampleRate = 44100.0; format.mFormatID = kAudioFormatLinearPCM; format.mFormatFlags = kAudioFormatFlagsCanonical | kLinearPCMFormatFlagIsNonInterleaved; format.mBytesPerPacket = sizeof(AudioUnitSampleType); format.mFramesPerPacket = 1; format.mBytesPerFrame = sizeof(AudioUnitSampleType); format.mChannelsPerFrame = 2 ; format.mBitsPerChannel = sizeof(AudioUnitSampleType)*8; 和这种格式 format.mSampleRate = 44100.0; format.mFormatID = kAudioFormatLinearPCM; format.mFormatFlags = kAudioFormatFlagsAudioUnitCanonical; format.mBytesPerPacket = sizeof(AudioUnitSampleType); format.mFramesPerPacket = 1; format.mBytesPerFrame = sizeof(AudioUnitSampleType); format.mChannelsPerFrame = 2; format.mBitsPerChannel = sizeof(AudioUnitSampleType)*8; 在audio呈现callback的范围内有下面的代码,buffer []是第二种格式,array […]

将两个iOS应用程序合并为一个

我有两个独立的公司希望将他们的iOS应用程序“连接”在一起形成一个应用程序(以便只需要一个应用程序商店下载)的情况。 这些应用程序完全独立的代码库。 这些公司正在寻找合作伙伴,但他们并不是真的要彼此看到对方的代码。 一定程度的代码摆弄是可以接受的。 有没有什么办法来“包装”代码库或二进制文件,以便应用程序1可以合并到app2中,而不需要app2开发者访问应用程序1代码库? 谢谢

当MPMoviePlayerController正在播放的时候,有没有什么办法来截图

我尝试了下面的步骤捕捉屏幕截图,但得到MPMoviePlayerController的黑色背景 -(UIImage*)screenshot { CGSize imageSize = [[UIScreen mainScreen] bounds].size; CGFloat imageScale = imageSize.width / FRAME_WIDTH; if (NULL != UIGraphicsBeginImageContextWithOptions) UIGraphicsBeginImageContextWithOptions(imageSize, NO, imageScale); else UIGraphicsBeginImageContext(imageSize); CGContextRef context = UIGraphicsGetCurrentContext(); for (UIWindow *window in [[UIApplication sharedApplication] windows]) { if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) { CGContextSaveGState(context); CGContextTranslateCTM(context, [window center].x, [window center].y); CGContextConcatCTM(context, [window transform]); […]