SQLAlchemy文档说" session.merge()将实例及其关联子项的当前状态与数据库中的现有数据进行协调".
现有对象的状态是否会被数据库中的较新数据更新?怎么样?什么时候?
我有一个iPhone应用程序,它有一个MainWindow.xib,上面有一个UITabBarController,它在ViewControllers数组中有一个UINavigationController和一个自定义的UIViewController子类.UINavigationController和自定义视图控制器的根视图控制器都是从其他xib文件加载的.
该应用程序使用核心数据,堆栈在应用程序委托中初始化(根据惯例).
app委托将UITabBarController添加到窗口:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Configure and show the window
[window addSubview:[tabBarController view]];
[window makeKeyAndVisible];
}
Run Code Online (Sandbox Code Playgroud)
我意识到我需要传播一个指向应用程序委托中创建的ManagedObjectContext的指针,但我不知道如何继续(甚至在这里和这里阅读关于该主题的所有好的评论):
我想我不太了解如何使用UITabBarController.
iphone cocoa-touch core-data uitabbarcontroller cocoa-design-patterns
我有一个带有RESTful API 的Flask应用程序.其中一个API调用是带有JSON有效负载的"大量upsert"调用.我在努力表现.
我尝试的第一件事就是merge-result在一个Query物体上使用,因为......
这是一个优化的方法,它将合并所有映射的实例,保留结果行和未映射列的结构,其方法开销少于为每个值显式调用Session.merge()的方法开销.
这是最初的代码:
class AdminApiUpdateTasks(Resource):
"""Bulk task creation / update endpoint"""
def put(self, slug):
taskdata = json.loads(request.data)
existing = db.session.query(Task).filter_by(challenge_slug=slug)
existing.merge_result(
[task_from_json(slug, **task) for task in taskdata])
db.session.commit()
return {}, 200
Run Code Online (Sandbox Code Playgroud)
对该端点的请求包含〜5000条记录,所有记录都已存在于数据库中,返回的时间超过11米:
real 11m36.459s
user 0m3.660s
sys 0m0.391s
Run Code Online (Sandbox Code Playgroud)
由于这是一个相当典型的用例,我开始研究提高性能的替代方案.根据我更好的判断,我尝试merge了每个记录的会话:
class AdminApiUpdateTasks(Resource):
"""Bulk task creation / update endpoint"""
def put(self, slug):
# Get the posted data
taskdata = json.loads(request.data)
for task in taskdata:
db.session.merge(task_from_json(slug, **task))
db.session.commit()
return {}, 200 …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序有一个UINavigationController推进UITabBarController视图.这UITabBarController有四个选项卡,其中一个显示自定义UIViewController,一个实例EventInformationViewController.此自定义视图控制器中的按钮依次将另一个自定义视图控制器推EventRatingAddViewController入视图.此视图控制器中的操作应调用EventInformationViewController实例中的方法.以下代码使应用程序崩溃:
// get the index of the visible VC on the stack
int myIindex = [self.navigationController.viewControllers indexOfObject:self.navigationController.visibleViewController];
// get a reference to the previous VC
EventInformationViewController *prevVC = (EventInformationViewController *)[self.navigationController.viewControllers objectAtIndex:myIindex - 1];
[prevVC performSelector:@selector(rateCurrentEvent:)];
Run Code Online (Sandbox Code Playgroud)
我认为viewControllers属性在导航堆栈上保留了所有VC的数组,因此当前可见的减去索引的索引应指向将当前可见VC推入视图的VC.相反,它似乎指向我UITabBarController:
-[UITabBarController rateCurrentEvent:]: unrecognized selector sent to instance
Run Code Online (Sandbox Code Playgroud)
具体是什么,更重要的是,如何获得指向VC的指针,该指针将当前可见的VC推入视图?
编辑:我最终创建了一个委托协议,EventRatingAddViewController并指定EventInformationViewController为委托.这很好用 - 我仍然认为应该有一种方法来通过导航堆栈访问推送VC.
我想在Cocoa中有一个对象的描述性字符串.我正在考虑覆盖description方法或stringValue方法.哪个更好,为什么?我能找到的唯一指导就是在这里说明
你不赞成压倒一切的描述.
这确实是你建议的吗?任何其他首选的覆盖点?
我开始研究ObjectiveFlickr框架,目的是创建一个相对简单的iPhone地图应用程序,显示当前MKMapView区域内的地理标记flickr内容.我跑进线程相关的麻烦之前,现在我有我得到某种根本性错误在我的建筑感觉.基本上我所拥有的是:
第2步的代码段:
-(void)actionSearchForTripodPhotos {
if(currentBoundingBox == nil) {
// TODO add a messagebox saying we're waiting for location info - or just lock the app until we're sure.
return;
}
NSString *dateTakenMinimumUNIXTimeStampString = [NSString stringWithFormat:@"%f",[[NSDate dateWithTimeIntervalSinceNow:-100000] timeIntervalSince1970]];
OFFlickrAPIRequest *flickrAPIRequest = [[OFFlickrAPIRequest alloc] initWithAPIContext:[CloudMadeMap101AppDelegate sharedDelegate].flickrAPIContext];
[flickrAPIRequest setDelegate:self];
NSString *flickrAPIMethodToCall = @"flickr.photos.search";
NSString *bboxString = [NSString stringWithFormat:@"%f,%f,%f,%f",currentBoundingBox.bottomLeftLat ,currentBoundingBox.bottomLeftLon ,currentBoundingBox.topRightLat ,currentBoundingBox.topRightLon];
NSLog(@"bounding box to be sent to flickr: %@",bboxString);
NSDictionary *requestArguments = [[NSDictionary alloc] initWithObjectsAndKeys:FLICKR_API_KEY,@"api_key",[NSString stringWithFormat:@"%f",currentLocation.coordinate.latitude],@"lat",[NSString stringWithFormat:@"%f",currentLocation.coordinate.longitude],@"lon",dateTakenMinimumUNIXTimeStampString,@"min_upload_date",nil]; …Run Code Online (Sandbox Code Playgroud) 该函数record()中pyshp模块预计的序列作为输入:
outfile.record('First','Second','Third')
Run Code Online (Sandbox Code Playgroud)
我有一个清单:
row = ['First','Second','Third']
Run Code Online (Sandbox Code Playgroud)
当我这样调用record()函数时:
outfile.record(row)
Run Code Online (Sandbox Code Playgroud)
我收到一个tuple index out of range错误.事实证明功能接收
(['First','Second','Third'],)
Run Code Online (Sandbox Code Playgroud)
我怎么称呼record正确?我试过了
outfile.record((row[i] for i in range(len(row)))
Run Code Online (Sandbox Code Playgroud)
但这也不起作用.
python ×3
cocoa-touch ×2
iphone ×2
sqlalchemy ×2
cocoa ×1
core-data ×1
flask ×1
list ×1
objective-c ×1
overriding ×1
tuples ×1