我正在学习CoreData.显然,你所包含的主要类之一是NSManagedObjectContext.我不清楚这个的确切作用.从我读过的文章中,您似乎可以拥有多个NSManagedObjectContexts.这是否意味着NSManagedObjectContext基本上是后端的副本?
当存在多个不同的副本时,如何将其解析为一致的后端?
所以,基本上有两个问题:
NSManagedContext是后端数据库的副本吗?
和...
例如,假设我在上下文A中进行了更改,并在上下文B中进行了一些其他更改.然后我先调用保存在A上,然后是B?B会占上风吗?
谢谢
cocoa-touch core-data objective-c nsmanagedobjectcontext ios
我的应用程序一度崩溃.它没有告诉我为什么,异常断点发生在
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
Run Code Online (Sandbox Code Playgroud)
所以我不知道是什么导致了崩溃.在左侧,它告诉我这是因为objc_expcetion_throw.我该怎么调试呢?谢谢
我正在使用rub redis gem。想知道我是否例如:
redis.pipelined do
REDIS.del("users:#{current_user_id}:i-unread")
REDIS.lpush("users:#{current_user_id}:i-read", items)
REDIS.ltrim("users:#{current_user_id}:i-read", 0, Interaction::MAX_INTERACTIONS)
end
Run Code Online (Sandbox Code Playgroud)
这样的执行顺序得到保证吗?
在XCode中,我可以指定Base SDK.我想知道幕后工作是怎么做的?如果我正在运行应用程序,例如,在具有iOS 7且我的基础SDK是iOS 6的设备上,那么该应用程序为何具有旧的"外观和感觉"?XCode是否会编译较旧的SDK并将其包含在我的应用程序中,或者新版本的iOS是否附带较旧的库/ SDK?
换句话说,运行时是否知道这个应用程序是使用较低的基础SDK编译的,而且它在UIKit的代码中的某个位置:
if (lower SDK) {
//show old look/feel
} else {
//show new look/feel
}
Run Code Online (Sandbox Code Playgroud)
或者应用程序本身是否包含旧库并加载它?
谢谢
我正在分析算法,我只是想知道我是否在正确的轨道上.
对于这个算法,我只计算行中有***的乘法.
这是算法:

p=p*20*z执行完全正确的(j) + (j-1)+(j-2)+(j-3)...1次数.这碰巧等于j(j+1)/2.2 * (j(j+1)/2).n(2 * (n(n+1)/2)).这是我背后的思考过程.我对么?谢谢.
我有一个界面:
#import <Foundation/Foundation.h>
@interface Picture : NSObject;
@property (readonly) NSString *filepath;
- (UIImage *)image;
@end
Run Code Online (Sandbox Code Playgroud)
和实施:
#import "Picture.h"
#define kFilepath @"filepath"
@interface Picture () <NSCoding> {
NSString *filepath;
}
@end
@implementation Picture
@synthesize filepath;
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:filepath forKey:kFilepath];
}
- (UIImage *)image {
return [UIImage imageWithContentsOfFile:filepath];
}
@end
Run Code Online (Sandbox Code Playgroud)
我收到错误:ARC问题 - 'NSObject'没有可见的@interface声明选择器'initWithCoder:'
使用ARC时,NSCoding有什么不同吗?谢谢
我非常喜欢Objective-C中的新文字.我想知道如果有新的增加,有一个更好的方法来比较数字.
例如,如果我想比较a和b:
a = @1;
b = @2;
Run Code Online (Sandbox Code Playgroud)
这是比较它们的唯一方法:
[a intValue] > [b intValue]
Run Code Online (Sandbox Code Playgroud)
还是有更好,更优雅的解决方案?
我从命令行运行ruby脚本.该脚本下载一个文件(15 MB),解压缩,将其解析为JSON,然后用它填充mysql数据库.
当我运行它时,我会收到一条简单的"被杀"消息.这是怎么回事?我怎样才能找出问题所在?
我在EC2微实例上使用它.
谢谢
这是脚本
require 'open-uri'
require 'zlib'
require 'json'
require_relative '../db/db.rb'
dl = open('........')
ex = Zlib::GzipReader.new dl
json = JSON.parse ex.read
events = json['resultsPage']['results']['event']
puts "starting to parse #{events.count} event(s)..."
created = 0
updated = 0
events[1..10].each do |event|
performances = event['performance']
performances.each do |performance|
ar_show = Show.find_or_initialize_by_songkick_id performance['id']
ar_show.artist_name = performance['displayName']
ar_show.new_record? ? created += 1 : updated += 1
ar_show.save!
end
end
Import.create :updated => updated, :new => created
puts "complete. new: #{created} - …Run Code Online (Sandbox Code Playgroud) 这段代码:
__weak VeryCool *weakSelf = self;
something.changeHandler = ^(NSUInteger newIndex) {
if (newIndex == 0) {
[weakSelf.options removeObjectForKey:@"seller"];
}
};
Run Code Online (Sandbox Code Playgroud)
给我一个警告,找不到财产选择.这是真的,因为选项是一个ivar,但没有声明为属性.是否有可能以某种方式从weakSelf获取选项而不将其声明为属性?
我正在努力加载一堆图像:
for (NSDictionary *s in things) {
[manager downloadWithURL:[NSURL URLWithString:s[photo]]
options:0
progress:nil
completed:nil];
}
Run Code Online (Sandbox Code Playgroud)
它不是下载这些图像.但是,如果我传入一个空的完成块,就像这样:
for (NSDictionary *s in things) {
[manager downloadWithURL:[NSURL URLWithString:s[photo]]
options:0
progress:nil
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { }];
}
Run Code Online (Sandbox Code Playgroud)
然后它工作得很好.我的问题是:为什么?有一个更好的方法吗?传入空座对我来说似乎不对.
objective-c ×7
cocoa-touch ×6
ios ×6
ruby ×2
algorithm ×1
big-o ×1
comparison ×1
core-data ×1
nscoding ×1
redis ×1
sdwebimage ×1
xcode ×1