小编ste*_*vex的帖子

codesign fail:用户取消了操作

看似突然出现,一个正在构建好的应用程序开始提供此消息:

/usr/bin/codesign --force --sign (my-identity) --resource-rules=/(path)/ResourceRules.plist --entitlements /(path)/MyApp.app.xcent /(path)/MyApp.app

/(path)/MyApp.app: User canceled the operation.
Command /usr/bin/codesign failed with exit code 1
Run Code Online (Sandbox Code Playgroud)

codesign命令看起来正确(上面的例子省略了括号中的项目); 身份的SHA1哈希值与打印的身份相匹配security find-identity,并且配置文件存在,并且是我正在尝试签名的应用程序的正确配置文件.

我只发现了一些关于这个特定错误的提及,我尝试了一些建议:

  • 重新启动
  • 锁定和解锁钥匙串

寻找有关下一步尝试的建议.

code-signing ios

10
推荐指数
0
解决办法
2407
查看次数

Android ListView实时更新

我在ListActivity中有一个ListView绑定到一些数据.我有一个提供数据的内容提供商.

ListActivity通过查询内容解析器来获取数据:

Uri uri = Uri.parse("content://my.provider.DocumentProvider/mystuff");
contentCursor = this.getContentResolver().query(uri, null, null, null, null);
Run Code Online (Sandbox Code Playgroud)

所以现在活动有了光标.它创建一个适配器并将其附加到列表:

ListAdapter adapter = new DocumentListCursorAdapter(this, R.layout.main_row_layout, contentCursor, new String[] { "titleColumn" }, new int[] { titleColumnIndex  });
setListAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

这很好用; 列表显示光标中的数据.

但现在内容提供商有了新的数据.我希望列表更新以显示新数据.

我见过的例子涉及对适配器的notifyDataSetChanged的调用,但在我看来,这打破了内容提供者和列表之间的分离,这就是消费内容.

内容提供者是否需要知道哪些适配器附加到游标,以便它可以调用其notifyDataSetChanged方法?或者是否有更好的方式,不会看到这两种方式耦合这种方式.

android listview cursor

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

UIManagedDocument没有保存

我正在使用UIManagedDocument来管理我的数据.我创建模型并使用它,一切似乎都在工作,但我的更改不会被写回SQLite存储.

UIManagedDocument的文档说自动保存应该将数据持久化到数据库,但这似乎并没有发生.

    NSManagedObjectContext *moc = [doc managedObjectContext];
    NSError *error = nil;
    MyItem *itemToAdd = (MyItems *)[moc existingObjectWithID:(NSManagedObjectID *)itemsID error:&error];
Run Code Online (Sandbox Code Playgroud)

这将获取我想要添加的对象(并成功).

   [itemContainer addItemsObject:itemToAdd];
   [doc updateChangeCount:UIDocumentChangeDone];
Run Code Online (Sandbox Code Playgroud)

这会将项添加到另一个对象的项集合中,然后告诉文档我已完成更改.

我希望在此之后不久有一段时间可以看到写入Core Data商店的更改,但是在Instruments中观看,我发现它永远不会发生.

items集合是一个NSOrderedSet,由于对此项目的评论:

NSOrderedSet生成的访问器抛出异常

我已经为包含集合的对象添加了一个addItemsObject:

- (void)addItemsObject:(MyItem *)value 
{
    NSMutableOrderedSet* tempSet = [NSMutableOrderedSet orderedSetWithOrderedSet:self.items];
    [tempSet addObject:value];
    self.items = tempSet;
}
Run Code Online (Sandbox Code Playgroud)

也许出现了一些问题,Core Data被告知物品集合已经改变,但我不知道如何.

core-data objective-c ios5 uimanageddocument

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

Xcode git自动检测电子邮件错误

使用Xcode 7,我在将代码提交给git时遇到了问题.

I get this error:

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'stevex@stevebookpro.(none)')
Run Code Online (Sandbox Code Playgroud)

我试过建议的git命令; 当我在存储库中运行git config user.email时,我看到了一个正确的电子邮件地址.我没有看到它从哪里拉出不正确的.

git xcode

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

UIViewControllerRepresentable 要求类型“some View”和“Never”等效

使用 Xcode 11 GM Seed 编写一些 SwiftUI 代码,我遇到了一个我不明白的 Swift 错误。

struct MainViewController: View {
    var body: some View {
        VStack {
            Text("Hello World!")
        }
    }
}

extension MainViewController : UIViewControllerRepresentable {
    func makeUIViewController(context: UIViewControllerRepresentableContext<MainViewController>) -> UINavigationController {
        return UINavigationController()
    }

    func updateUIViewController(_ uiViewController: UINavigationController, context: UIViewControllerRepresentableContext<MainViewController>) {

    }
}
Run Code Online (Sandbox Code Playgroud)

这篇报道:

'UIViewControllerRepresentable' requires the types 'some View' and 'Never' be equivalent
Run Code Online (Sandbox Code Playgroud)

swift swiftui

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

SwiftUI - ReferenceFileDocument - 无法指示文档需要保存

创建符合 的类时ReferenceFileDocument,如何指示文档需要保存。即相当于 的NSDocument方法updateChangeCount

swiftui

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

Swift访问可变长度数组

Core Audio有一个C API,可以复制你提供的内存中的一些数据.在一种情况下,我需要传入指向AudioBufferList的指针,该指针定义为:

struct AudioBufferList {
    var mNumberBuffers: UInt32
    var mBuffers: (AudioBuffer) // this is a variable length array of mNumberBuffers elements
}
Run Code Online (Sandbox Code Playgroud)

UInt32标识缓冲区的数量,紧接着是实际的缓冲区.

我能成功地做到这一点:

let bufferList = UnsafeMutablePointer<AudioBufferList>.alloc(Int(propsize));
AudioObjectGetPropertyData(self.audioDeviceID, &address, 0, nil, &propsize, bufferList);
Run Code Online (Sandbox Code Playgroud)

我不认识(AudioBuffer)语法,但我不认为它很重要 - 我认为括号被忽略而mBuffers只是一个AudioBuffer而且由我来做指针数学以找到第二个.

我试过这个:

let buffer = UnsafeMutablePointer<AudioBuffer>(&bufferList.memory.mBuffers);
// and index via buffer += index;
// Cannot invoke 'init' with an argument of type 'inout (AudioBuffer)'
Run Code Online (Sandbox Code Playgroud)

还尝试过:

let buffer = UnsafeMutablePointer<Array<AudioBuffer>>(&bufferList.memory.mBuffers);
// and index via buffer[index];
// error: Cannot invoke 'init' with an argument of …
Run Code Online (Sandbox Code Playgroud)

swift

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

在shared_from_this()中提升weak_ptr_cast

我正在使用boost的共享指针,并enable_shared_from_this启用返回共享指针.代码如下所示:

class foo : public boost::enable_shared_from_this<foo>
{
  boost::shared_ptr<foo> get()
  {
    return shared_from_this();
  }
}
Run Code Online (Sandbox Code Playgroud)

为什么shared_from_this会抛出weak_ptr_cast异常?

c++ boost

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

为什么NSDictionary报告一个不寻常的类名?

NSDictionary *dict = [NSDictionary dictionary];
NSLog(@"%@", NSStringFromClass([dict class])); 
Run Code Online (Sandbox Code Playgroud)

此代码打印"__NSDictionary0".

对于我自己的类,它会打印实际的类名.

为什么NSDictionary被标识为__NSDictionary0,依赖于此是否安全?

reflection objective-c

5
推荐指数
2
解决办法
2091
查看次数

在 Mac 上包含自动换行的 SwiftUI 列表

我在 Mac 上遇到了包含文本行的列表的问题,这些文本行具有换行的文本。

这是代码:

struct ContentView: View {
    var messages = [
        "This is a long piece of text that's going to need to be wrapped to fit into the view.",
        "This is another long piece of text that's going to need to be wrapped to fit into the view."
    ]

    var body: some View {
        List(messages, id: \.self) { message in
            Text(message)
                .lineLimit(nil)
                .border(Color.blue)
                .fixedSize(horizontal: false, vertical: true)

                // Also tried .fixedSize(horizontal: true, vertical: false)
                // which seems more …
Run Code Online (Sandbox Code Playgroud)

macos swiftui

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

建立并分析泄漏检测的误报?

我有这个代码:

- (CGImageRef)createImageWithContext:(CGContextRef)context
{
    return CGBitmapContextCreateImage(context);
}

- (void)fooWithContext:(CGContextRef)context
{
    CGImageRef imgRef = [self createImageWithContext:context];
    CGImageRelease(imgRef);
}
Run Code Online (Sandbox Code Playgroud)

这是一个在Xcode中构建的Objective-C项目,启用了ARC.构建和分析报告两个错误:一个在CGBitmapContextCreateImage行上标识潜在的泄漏,一个在CGImageRelease上,注意到"调用者此时不拥有的对象的引用计数的不正确减少".

如果我将这两个函数合并为一个:

- (void)fooWithContext:(CGContextRef)context
{
    CGImageRef imgRef = CGBitmapContextCreateImage(context);
    CGImageRelease(imgRef);
}
Run Code Online (Sandbox Code Playgroud)

我没有得到任何警告.

静态代码分析bug?或者我在这里遗漏了什么?

objective-c automatic-ref-counting

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

UITextView没有在属性更改时触发textViewDidChange?

UITextView配置了一个委托.我已经通过设置启用编辑属性allowsEditingTextAttributesYES.

当用户在文本视图中键入字符时,委托会收到 textViewDidChange:message.

但是当用户更改属性(例如进行选择并点击Bold或Italic)时,no textViewDidChange:message.

文档具体说明textViewDidChange:当用户更改属性时应该收到消息:

告诉委托者用户更改了指定文本视图中的文本或属性.

但这对我不起作用.我在这里错过了什么?

iphone uitextview

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

在init中引发异常时如何防止泄漏?

这是情况.假设我有一个名为MYFoo的课程.这是初始化程序:

-init
{
  self = [super init];
  if (self)
  {
    // during initialization, something goes wrong and an exception is raised
    [NSException raise ...];
  }
  return self;
}
Run Code Online (Sandbox Code Playgroud)

现在我想在其他地方使用MYFoo对象,所以我使用了一个常见的模式:

MYFoo *foo = [[[MYFoo alloc] init] autorelease];
Run Code Online (Sandbox Code Playgroud)

但是会发生什么,即使第二部分有一个try/catch,一个MYFoo对象将被分配,异常将被抛出,自动释放错过,未初始化的MYFoo对象将泄漏.

这里应该发生什么来防止这种泄漏?

memory-leaks memory-management objective-c

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