小编One*_*ake的帖子

获取std :: list <> :: iterator的值到指针?

我如何循环通过stl :: List并存储其中一个对象的值,以便稍后在函数中使用?

Particle *closestParticle;
for(list<Particle>::iterator p1 = mParticles.begin(); p1 != mParticles.end(); ++p1 )
     {
      // Extra stuff removed
            closestParticle = p1; // fails to compile (edit from comments)
     }
Run Code Online (Sandbox Code Playgroud)

c++ iterator stl

17
推荐指数
1
解决办法
5万
查看次数

CoreData无法保存上下文,说关系是零 - 但它肯定是设置的

当我尝试保存CoreData模型的上下文时,收到错误

Unresolved error Error Domain=NSCocoaErrorDomain Code=1560 "The operation couldn’t be completed. (Cocoa error 1560.)" UserInfo=0x76924b0 {NSDetailedErrors=( "Error Domain=NSCocoaErrorDomain Code=1570 " The operation couldn\U2019t be completed. (Cocoa error 1570.)" UserInfo=0x768c410 {NSValidationErrorObject=<Posts: 0x7177990> (entity: Posts; id: 0x7177010 <x-coredata:///Posts/tEF7138E6-A968-45B7-95CF-116C2AA93D605> ; data: {\n " business_entity" = nil;\n "
created_at" = " 2012-01-21 03:31:30 +0000" ;\n " own_description" = " Roasted this morning- Panama Duncan Estate: A rose fragrance debuts flavors of pear, coconut and marshmallow with caramel throughout the cup." ;\n postsID = 4;\n …

iphone core-data nsmanagedobjectcontext xcode4 ios5

8
推荐指数
1
解决办法
5404
查看次数

CoreData"验证商店的网址时出错"

我在我的应用程序中遇到问题,CoreData在模拟器中工作正常 - 但不在设备上.

我收到了

2010-09-30 12:45:07.500 CoreDataTutorial_iOS[130:307] Unresolved error Error Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed. (Cocoa error 513.)" UserInfo=0x1412a0 {NSUnderlyingException=Error validating url for store}, {
    NSUnderlyingException = "Error validating url for store";
Run Code Online (Sandbox Code Playgroud)

我在这个函数中调用PersistentStoreCoordinator(抛出上面的错误):

-(NSPersistentStoreCoordinator*)persistentStoreCoordinator
{
    if(persistentStoreCoordinator_ != nil) 
        return persistentStoreCoordinator_;

    NSURL *aStoreURL = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingFormat:@"corebase.sqlite"]];
    NSError *anError = nil;

    persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
    if(![persistentStoreCoordinator_ addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:aStoreURL options:nil error:&anError])
    {
        NSLog(@"Unresolved error %@, %@", anError, [anError userInfo]);
        abort();
    }

    return persistentStoreCoordinator;
}
Run Code Online (Sandbox Code Playgroud)

我在"objc_exception_throw"上设置了一个断点,看看aStoreURL是什么,它是:file://localhost/var/mobile/Applications/BE9A2982-BDC3-405D-A201-FB78E9E0790B/Documentscorebase.sqlite …

core-data ios

2
推荐指数
1
解决办法
2565
查看次数

这件目标做什么?

我不确定这是做什么的.dateFormatter第一次只能设置吗?

static NSDateFormatter *dateFormatter = nil;

if (dateFormatter == nil) {
    dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
} 
Run Code Online (Sandbox Code Playgroud)

通常我会读到这意味着,设置为零,然后检查它是否为零,但如果我在条件内的NSLog,它只被调用一次?

额外的点,如果你可以更深入地解释静态,我知道它创建一个全局变量(?),但这就是它.

c iphone objective-c

1
推荐指数
1
解决办法
263
查看次数

对C++内存释放感到困惑

所以在C++中,如果我创建一个使用的对象,new我应该总是使用delete
例如解除分配它

Segment::Segment(float length)
{
    segmentLength = length;

    angle = 0.0f;
    x = Rand::randFloat(1.0f, 1.5f);
    y = Rand::randFloat(1.0f, 1.5f);

    vx = Rand::randFloat(0.0f, 1.0f); 
    vy = Rand::randFloat(0.0f, 1.0f);
    prevX = Rand::randFloat(0.0f, 1.0f);
    prevX = Rand::randFloat(0.0f, 1.0f);
};
Run Code Online (Sandbox Code Playgroud)

并且我可以说我在另一个类中使用它,例如

this._segmentObject = Segment(2.0f);
this._segmentPointer = new Segment(2.0f);
Run Code Online (Sandbox Code Playgroud)

在该类的析构函数中,我知道我应该调用deletethis._segmentPointer,但是如何确保为另一个释放内存呢?

c++ memory-management

1
推荐指数
1
解决办法
249
查看次数

使用git log来解决前一次提交后,如何返回

这可能是一个简单的问题,但这是我的用例:
需要在旧分支中看到一些东西,运行
git log -10

它告诉我,我不在任何分支,所以我跑
git checkout master

但是,在我检查了之前的提交后,我似乎无法回到当前的提交.我收到了这条消息
:$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 7 commits.
:$ git pull
Already up-to-date.

我如何从那回到当前版本的主分支?

git

0
推荐指数
1
解决办法
340
查看次数