小编Als*_*ler的帖子

swift中对象数组的深层复制

我有这个名为Meal的课程

class Meal {
    var name : String = ""
    var cnt : Int = 0
    var price : String = ""
    var img : String = ""
    var id : String = ""

    init(name:String , cnt : Int, price : String, img : String, id : String) {
        self.name = name
        self.cnt = cnt
        self.price = price
        self.img = img
        self.id = id
    }
}
Run Code Online (Sandbox Code Playgroud)

我有一系列的餐:

var ordered = [Meal]()
Run Code Online (Sandbox Code Playgroud)

我想复制该数组,然后对其中一个中的Meal实例进行一些更改而不更改第二个中的Meal实例,我将如何制作它的深层副本?

此搜索结果对我没有帮助 如何制作数组的完全重复副本?

deep-copy swift

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

从我在swift中使用modal打开的viewController访问navigationController

我正在使用navigationController(推和弹出),但在一个特殊情况下,我必须使用模态segue显示下一个viewcontroller,当我解雇该模态我想在navigationController中弹出最后一个viewController,然后推出一个新的后出现解雇模态一,我如何从模态viewController访问充满viewControllers的navigationController我可以发送导航控制器中的最后一个元素作为自我在prepareForSegue中的模态,但我问是否有另一种方式,对不起,我的问题是总是很复杂

uiviewcontroller uinavigationcontroller ios swift

3
推荐指数
2
解决办法
5399
查看次数

在UIImageView上绘制而不替换其原始图像iOS

此代码对imageview进行了更改,但它替换了原始图像.我需要在原始图像上进行编辑而不是替换它.

- (void)drawShapes {
    //NSLog(@"In drawShapes!");

    UIGraphicsBeginImageContext(self.planView.frame.size);
    CGContextRef context = UIGraphicsGetCurrentContext();

    for(myShape *i in _collection) {
        [self drawShapesSubroutine:i contextRef:context];
        if(i.selected == true) {
            CGContextSetLineWidth(context, 1.0f);
            CGContextSetStrokeColorWithColor(context, [[UIColor darkGrayColor] CGColor]);
            float num[] = {6.0, 6.0};
            CGContextSetLineDash(context, 0.0, num, 2);

            CGRect rectangle;
            [self drawShapeSelector:i selectorRect: &rectangle];
            CGContextAddRect(context, rectangle);
            CGContextStrokePath(context);


            //tapped = true;
        }
    }

    if(!skipDrawingCurrentShape && (selectedIndex == -1)) {
        [self drawShapesSubroutine:_currentShape contextRef:context];
    }
    self.planView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
}
Run Code Online (Sandbox Code Playgroud)

当我删除此行时:

self.planView.image = UIGraphicsGetImageFromCurrentImageContext();
Run Code Online (Sandbox Code Playgroud)

图像不会消失但也不会消失.我需要绘制而不删除原始照片.

core-graphics objective-c uiimageview ios

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