小编Adr*_*ian的帖子

如何从NSNotification对象(核心数据)获取对象

我可以访问从NSManagedObjectContextObjectsDidChangeNotification添加/编辑/删除核心数据值时收到的通知.

我从以下数据获得以下数据userInfo:

Optional([deleted: {(
    <Product: 0x7f8d1a634370> (entity: Product; id: 0xd0000000002c0000 <x-coredata://A9A941BF-C4BA-4E1F-972D-F188032C93E0/Product/p11> ; data: {
    amount = 54;
    date = "2016-01-10 17:16:53 +0000";
    name = test65;
})
)}, managedObjectContext: <NSManagedObjectContext: 0x7f8d1a705040>])
Run Code Online (Sandbox Code Playgroud)

但我无法设法检索更改的Product对象,因此我可以访问其属性(金额,日期,名称).

我可以看到有[ NSObject: AnyObject]字典,但我仍然无法获得该对象.

core-data ios swift

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

如何计算当月/年的天数

有没有方法可以NSDate/NSCalendar计算当月和当年的天数?

我唯一看到的是获得给定日期或两个日期之间的天数.
这是唯一的方法吗?

ios swift

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

Is it possible to transfer ownership from a void* to a unique_ptr?

I am currently using the dlopen functions for some plugin project.
This function handle returns a void* and then I save all the handle to a map named handles:

void* handle = dlopen(path.c_str(), RTLD_LAZY);  
handles[file] = handle;
Run Code Online (Sandbox Code Playgroud)

My goal is to pass the ownership to the map, I was thinking of a unique_ptr, but not sure if this is even possible.

If it's not possible what other alternatives do I have ?

c++ c++11

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

防止子元素接收点击事件不起作用

我正在尝试创建一个模态组件,并在单击组件外部时将其关闭。这是我当前的设置:

  1. 在元素上设置单击事件的身份验证div组件:
    <template>   <div>
        <transition name="modal">
          <div class="modal-mask" @click="$parent.$emit('close')">
            <div class="modal-wrapper">
              <div class="modal-container">
                <div class="modal-header">
                  <slot name="header">Default Header</slot>
                </div>
                <div class="model-body">
                  <slot name="body">Default Body</slot>
                </div>
                <div class="modal-footer">
                  <slot name="footer">Default Footer</slot>
                </div>
              </div>
            </div>
          </div>
        </transition>   </div> </template>
Run Code Online (Sandbox Code Playgroud)
  1. 注入必要信息的SignIn组件:
<template>
  <div>
    <Auth />
  </div>
</template>
Run Code Online (Sandbox Code Playgroud)
  1. 使用 SignIn 组件的Home组件:
<template>
  <div class="home">
    <SignIn v-if="showModal" @close="showModal = false" />
  </div>
</template>
Run Code Online (Sandbox Code Playgroud)

现在,当我在模式之外单击时,它的行为正常,该close事件被调用。
但当我在模态中单击时也会调用它。

不是我尝试使用@click.self,但现在即使在模式之外单击,它也不再起作用。

      <div class="modal-mask" @click.self="$parent.$emit('close')">
Run Code Online (Sandbox Code Playgroud)

我目前正在学习VueJs,但我不明白这是如何工作的。我认为self会阻止将单击事件传播到子元素,仅此而已。

有人知道发生了什么事吗?

PS:我正在使用此设置,因为我想使用身份验证组件进行登录和注册。

vue.js

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

用C++对对象矢量进行排序

struct Keyword
{
    std::string keyword;
    int numUses;
};  

bool sortingVector(const Keyword& key1, const Keyword& key2)
{
    return key1.numUses < key2.numUses;
}

sort(topKeywords.begin(), topKeywords.end(), sortingVector);



: no matching function for call to 'sort(std::vector<Keyword>::iterator, std::vector<Keyword>::iterator, <unresolved overloaded function type>)'
        c:\mingw\bin\../lib/gcc/mingw32/4.5.0/include/c++/bits/stl_algo.h:5236:18: note: candidate is: void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<Keyword*, std::vector<Keyword> >, _Compare = bool (NewsAggregatorImpl::*)(const Keyword&, const Keyword&)]
Run Code Online (Sandbox Code Playgroud)

为什么这不正确,我的编译器给了我那个错误.
我希望我的功能是全球性的.
谢谢.

c++

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

C++中的临时问题

我有这段代码使用Boost.Filesystem打印目录的内容:

class Shell {
private:
    const string& command;
    const path& firstPath;
    const path& secondPath;
public:
    // constructor
    Shell(const string& _command, const path& _firstPath, const path& _secondPath = path()): command(_command), firstPath(_firstPath), secondPath(_secondPath) {}

    //destructor
    ~Shell() {}

    //execute commands
    void executeCommand()
    {
        if(command.compare("ls"))
        {
            ls();
        }
    }

    void ls()
    {
        if(exists(firstPath)) 
        {
            vector<path> vecPath;

            copy(directory_iterator(firstPath), directory_iterator(), back_inserter(vecPath));
            sort(vecPath.begin(), vecPath.end());
            for(vector<path>::iterator it = vecPath.begin(); it != vecPath.end(); ++it)
            {
                cout << *it << endl;
            }
        }
    }
};


int main(int argc, char** argv) …
Run Code Online (Sandbox Code Playgroud)

c++ boost

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

如何将元素添加到Boost.Tuple

也许这是一个简单的问题,但我无法弄明白如何将元素添加到元组中.我想要的是迭代一个向量并将每个元素添加到元组中:

for(it = vector.begin(); it != vector.end(); ++it)
{
   tuple.addElement(*it);
}
Run Code Online (Sandbox Code Playgroud)

我没有看到任何添加元素的具体方法.
谢谢你的帮助.

c++ boost

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

无法使用朋友类从基类访问私有成员

这是我的代码:

class Base
{
    friend class SubClass;
    int n;
    virtual int getN()
    {
        return n;
    }
};

class SubClass: public Base
{
public:
    SubClass() {}
    SubClass(const SubClass& s) {}


};

int _tmain(int argc, _TCHAR* argv[])
{
    SubClass s;
    int x = s.getN();

    return 0;
}


error C2248: 'Base::getN' : cannot access private member declared in class 'Base'
Run Code Online (Sandbox Code Playgroud)

从Base访问我的私人会员还需要做些什么?

c++

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

从Telnet发送http GET命令

我有这个简单的程序:

package main

import (
    "fmt"
    "net/http"
)

func main() {
    http.HandleFunc("/users", UsersHandler)

    fmt.Println("Starting server...")

    http.ListenAndServe(":8181", nil)
}

func UsersHandler(w http.ResponseWriter, r *http.Request) {
    fmt.Println("Users")
}
Run Code Online (Sandbox Code Playgroud)

如果我GET从浏览器发送命令:http://localhost:8181我可以看到打印的消息"用户",但如果我从telnet连接,则在执行时不会打印任何消息:

telnet 127.0.0.1 8181
GET /users HTTP/1.1
Run Code Online (Sandbox Code Playgroud)

知道为什么会这样吗?

http telnet go

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

如何检查std :: vector何时将状态从空状态更改为非空状态,反之亦然?

我想在vector更改从空状态变为非空状态或从非空状态变为空时生成事件.

检查这个的最简单方法是什么?

c++

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

当我调用一个仅在派生类中是虚拟的函数时,会发生什么

这是我的代码:

class Base {
public:
    void foo() {
        cout << "Base::foo" << endl;
    }
};

class Derived : public Base {
public:
    virtual void foo() {
        cout << "Derived::foo" << endl;
    }
};

int main()
{
    Base* base = new Derived;
    base->foo();

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

这会打电话Base::foo.在使用此代码时,我很好奇发生了什么.我知道将为其创建Derived一个包含指针的表,foo并且还有一个由Derived构造函数初始化的指针,该指针将指向包含虚函数的表.

所以结果表明静态绑定正在发生,我很好奇这是怎么发生的?

我想我有点困惑,因为如果Base::foo是虚拟的那么在Derivedv-table Base::foo中将被覆盖Dervied::foo(现在就是这种情况).

在编译代码时,编译器是否看到它Base::foo不是虚拟的并执行静态绑定?这是答案还是有另一个答案?

c++

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

在Pimpl习语中使用枚举时"不命名类型"错误

这是一个代码示例:

foo.h中

class Foo 
{
    .............
    class Bar;
    Bar* pimpl;
};
Run Code Online (Sandbox Code Playgroud)

Foo.cpp中

class Foo::Bar
{
    enum class PositionsEnum : int
    {
        Extended, Retracted
    };
    void MoveToPosition(PositionsEnum pos);
    PositionsEnum GetPosition();
};

void Foo::Bar::MoveToPosition(PositionsEnum  pos) {}

PositionsEnum Foo::Bar::GetPosition() {}
Run Code Online (Sandbox Code Playgroud)

GetPosition方法上,我得到了一个 error: 'PositionsEnum ' does not name a type.

我怎样才能解决这个问题 ?

c++

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

如何获取当前月份和当前的当日数字

我使用此代码获取当前周的天数:

static func currentDayOfWeek() -> Int {
    let comp = NSCalendar.current.dateComponents([.weekday], from: Date())
    if comp.weekday == 1 {
        return 7
    }

    return comp.weekday! - 1
}

Monday =  1
Tuesday = 2
...........
Sunday =  7
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚如何获得当月的当月数.

例如,对于今天,当月的数字应该是3和应该是的年份277.

有什么建议 ?

arrays ios swift

-3
推荐指数
1
解决办法
2738
查看次数

标签 统计

c++ ×8

ios ×3

swift ×3

boost ×2

arrays ×1

c++11 ×1

core-data ×1

go ×1

http ×1

telnet ×1

vue.js ×1