小编Olh*_*iuk的帖子

iOS照片扩展finishContentEditingWithCompletionHandler:无法保存更改

我的照片扩展程序应用可以访问相机和照片.一切正常,但按完成后,无法保存图像.

标准完成处理程序代码:

- (void)finishContentEditingWithCompletionHandler:(void (^)(PHContentEditingOutput *))completionHandler {
    // Update UI to reflect that editing has finished and output is being rendered.

    // Render and provide output on a background queue.
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        PHContentEditingOutput *output = [[PHContentEditingOutput alloc] initWithContentEditingInput:self.input];

        NSError* error = nil;

        NSData *renderedJPEGData = UIImageJPEGRepresentation(filtered_ui_image, 1.0);
        assert(renderedJPEGData != nil);
        //BOOL written_well = [renderedJPEGData writeToURL:output.renderedContentURL atomically:YES];

        BOOL written_well = [renderedJPEGData writeToURL:output.renderedContentURL options:NSDataWritingAtomic error:&error];
        assert(written_well);



        // Call completion handler to commit edit to Photos.
        completionHandler(output);
    });
}
Run Code Online (Sandbox Code Playgroud)

renderedJPEGData …

file-io photo-gallery ios

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

如何在 SwiftUI 中仅使用 ForEach 而不是列表来滑动删除

我正在 SwiftUI 中使用 ForEach 制作自定义列表。我的目标是进行滑动删除手势,而不是将 ForEach 嵌入到列表中。

到目前为止,这是我的代码:

import SwiftUI

struct ContentView: View {
let list = ["item1", "item2", "item3", "item4", "item5", "item6"]

var body: some View {
    VStack {
        List{
            
            ForEach(list, id: \.self) { item in
                Text(item)
                    .foregroundColor(.white)
                    .frame(maxWidth: .infinity)
                    .padding()
                    .background(Color.red)
                    .cornerRadius(20)
                    .padding()
                
            }
        }
    }
  }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Run Code Online (Sandbox Code Playgroud)

我似乎找不到一种手势可以让我在不使用列表视图的情况下进行滑动删除。

我还想制作一个自定义删除按钮,当用户向左滑动项目时显示该按钮(如下图所示)。

在此输入图像描述

swift swiftui

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

c ++动态数组初始化与声明

我有这样的功能:

void findScarf1(bool ** matrix, int m, int n, int radius, int connectivity); 
Run Code Online (Sandbox Code Playgroud)

main函数中我创建了2d动态数组来传递这个函数

    bool matrix[6][7] = {
    {0, 0, 1, 1, 1, 0, 0},
    {0, 0, 1, 1, 1, 0, 0},
    {0, 0, 1, 1, 1, 0, 0},
    {0, 0, 1, 1, 1, 0, 0},
    {0, 0, 1, 1, 1, 0, 0},
    {0, 0, 1, 1, 1, 0, 0}
};
Run Code Online (Sandbox Code Playgroud)

问题是:

findScarf1(matrix, 6, 7, 3, 4);
Run Code Online (Sandbox Code Playgroud)

导致 错误C2664:'findScarf1':无法将参数1从'bool [6] [7]'转换为'bool**'

如何紧凑地初始化数组(同时声明)?

抱歉,如果这是重复的问题,但我花了1.5个小时搞清楚

c++ dynamic-arrays

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

是否可以在PyCharm CE中使用Docker?

我必须调试python项目.PyCharm IDE似乎很好(我下载了Community Edition,因为它是免费的).

但主要脚本是从Docker"调用"的(我对它不太熟悉).我发现的所有资源都说可以将Docker添加为远程解释器.
在此输入图像描述

PyCharm CE有局限性,因此无法在此IDE中添加"远程解释器".

你知道一些解决方法吗?
也许PyCharm可以连接到"某些东西"(一些非官方项目),而"某些东西"使用Docker?
或者也许还有另一个有这种可能性的好IDE?(我不想在命令行中调试).

提前致谢.

pycharm python-3.x docker

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

Xcode 13 beta:“xcrun:错误:无法找到‘仪器’”

请注意,我正在寻找/Applications/Xcode.app/Contents/Developer/usr/bin/instrumentsutil(小写),而不是Instruments可以在 中找到的应用程序Xcode.app/Contents/Applications

\n
\n

我的电脑上有 和Xcode12Xcode13-beta-5\n运行时xcrun instruments -w <device id>,Xcode13 显示xcrun: error: Failed to locate 'instruments'

\n
\n

在 Xcode12 中找到“instruments”:

\n
olia@Olhas-MacBook-Pro % ls /Applications/Xcode.app/Contents/Developer/usr/bin/*instruments* \n\n# output \xe2\x9c\x85\n/Applications/Xcode.app/Contents/Developer/usr/bin/instruments\n
Run Code Online (Sandbox Code Playgroud)\n

在 Xcode13 中找到“instruments”:

\n
olia@Olhas-MacBook-Pro % ls /Applications/Xcode-beta.app/Contents/Developer/usr/bin/*instruments* \n\n# output \xe2\x9d\x8c      \nzsh: no matches found: /Applications/Xcode-beta.app/Contents/Developer/usr/bin/*instruments*   \n
Run Code Online (Sandbox Code Playgroud)\n

这里,Xcode-beta.app是Xcode13,Xcode.app是Xcode12。

\n

xcode continuous-integration ios ios-simulator

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

有没有办法在没有内部缓存的情况下从 CGImage 读取数据?

我正在与CGContextDrawImage/CGDataProviderCopyData函数中的内部缓存(15 mp 图像大约 90 MB)作斗争。
这是分析器中的堆栈跟踪:

在此处输入图片说明

在所有情况下,IOSurface都是作为“缓存”创建的,并且在@autoreleasepool排空后不会被清除。
这给应用程序留下了极少的生存机会。
缓存并不取决于图像大小:我试图呈现512x512,以及4500x5124500x2500(全尺寸)图像块。

在清理它们之前@autoreleasepool,我使用,CFGetRetainCount返回1所有CG对象。

操作数据的代码:

+ (void)render11:(CIImage*)ciImage fromRect:(CGRect)roi toBitmap:(unsigned char*)bitmap {
    @autoreleasepool
    {
        int w = CGRectGetWidth(roi), h = CGRectGetHeight(roi);

        CIContext* ciContext = [CIContext contextWithOptions:nil];
        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

        CGContextRef cgContext = CGBitmapContextCreate(bitmap, w, h,
                                                   8, w*4, colorSpace,
                                                   kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);


        CGImageRef cgImage = [ciContext createCGImage:ciImage
                                         fromRect:roi
                                           format:kCIFormatRGBA8
                                       colorSpace:colorSpace
                                         deferred:YES];


        CGContextDrawImage(cgContext, CGRectMake(0, …
Run Code Online (Sandbox Code Playgroud)

caching core-graphics core-image ios iosurface

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

如何分析/优化 Objc/C++ 项目编译时间?

我的 Objc/C++ 项目编译时间太长。即使 Xcode 进行增量构建,也可能需要 140 秒 = 2.5 分钟。

问题是,2.5 分钟的增量构建告诉我没有什么可以改进的。例如Xcode Report Navigator显示一些文件被编译在4.2s

在此处输入图片说明

如何检查此文件是否可以编译2.1s0.3s? 除了生成的二进制文件中的符号数量外,还有哪些限制?

我听说应该使用模块来加速增量构建,但让我们假设我正在尝试加快已提取模块的编译时间。


我听说有某种“符号依赖图”,但还没有找到任何实用的建议如何使用它来解决编译时问题。

我已经尝试过这样的工具来发现“符号依赖关系”,但它们似乎太高级了(第一个生成的文件太大而无法graphviz在 MacOS上打开):

  1. https://github.com/nst/objc_dep
  2. http://github.com/PaulTaykalo/objc-dependency-visualizer

我也见过这样的 Swift 构建标志:-warn-long-function-bodies=200/ -warn-long-expression-type-checking=200。这些标志可以标记长函数,但它们能解释为什么这些函数这么长吗?例如,也许有些for loop写得不好,编译器必须对其进行优化以加快执行速度。在这种情况下,如果程序员以更优化的方式编写该循环,编译器就不必对其进行优化,并且程序员不会在每次构建时等待 1-2 秒。


所以,假设有一个在 N 秒内编译的 Objc/C++ 文件。问题是:

  1. 如何查看此文件的“分割”时间?例如preprocessing a whole file:N/4 秒,compile func1:N/4 秒,compile func2:N/4 秒,optimize an assembly:N/4 秒。
  2. 有没有clang这种东西的实用程序?
  3. 如何检查是否有不必要的#include/#import这会减慢编译速度。
  4. 编译时间是否与 Xcode 必须打印的许多警告相关?(我知道我可以通过消除警告来检查它,但是有些 …

c++ xcode compilation objective-c clang

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