小编Jak*_*Lin的帖子

我们总是在Swift中使用[unowned self]内部封闭

在WWDC 2014会议403 中级Swift成绩单中,有以下幻灯片

在此输入图像描述

在这种情况下,发言人说,如果我们不在[unowned self]那里使用,那将是内存泄漏.这是否意味着我们应该始终使用[unowned self]内部封闭?

Swift Weather应用程序的ViewController.swift的第64行,我不使用[unowned self].但我通过使用一些@IBOutletself.temperature和更新UI self.loadingIndicator.它可能没问题,因为@IBOutlet我所定义的都是weak.但为了安全起见,我们应该一直使用[unowned self]吗?

class TempNotifier {
  var onChange: (Int) -> Void = {_ in }
  var currentTemp = 72
  init() {
    onChange = { [unowned self] temp in
      self.currentTemp = temp
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

ios automatic-ref-counting swift

455
推荐指数
7
解决办法
14万
查看次数

如何从Swift语言访问Objective-C类方法

在我的Swift应用程序中,我需要weibo()从Objective-C 访问下面调用的类方法

@interface Weibo : NSObject
+ (Weibo*)weibo;
@end
Run Code Online (Sandbox Code Playgroud)

我已经配置了桥接头并尝试了以下语句

let w = Weibo.weibo() as Weibo
Run Code Online (Sandbox Code Playgroud)

它不起作用.

更新:我已经分配了回购并解决了这个问题,如下所示.

let w = Weibo.getWeibo() as Weibo // the method has been changed.
Run Code Online (Sandbox Code Playgroud)

它之所以不起作用,是因为Swift将其+ (Weibo*)weibo;视为一种便利构造函数.由于案例不同weibo,因此与班级名称Weibo相同.我需要更改名称以getWeibo解决此问题以支持Swift.

感谢每个人为这个答案做出贡献.特别感谢@Anil和@David

可靠的人

objective-c ios swift

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

RestKit 0.2错误'预期状态代码在(400-499),得到200'

我正在使用RestKit 0.2,我收到以下错误.

E restkit.network:RKObjectRequestOperation.m:237 GET 'http://some.url.com/o/3134' (200 OK / 0 objects) [request=3.2563s mapping=0.0000s total=3.2955s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=-1011 "Expected status code in (400-499), got 200" UserInfo=0x87712e0 {NSLocalizedRecoverySuggestion={"d":"2013-07-15T02:30:00.000Z","t":16.1,"at":13.8}, AFNetworkingOperationFailingURLRequestErrorKey=<NSMutableURLRequest http://some.url.com/o/3134>, NSErrorFailingURLKey=http://some.url.com/o/3134, NSLocalizedDescription=Expected status code in (400-499), got 200, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x9647260>}
Run Code Online (Sandbox Code Playgroud)

我使用nodejs和restify作为服务器端.我可以使用谷歌浏览器获取json数据,我可以看到Chrome的内容类型响应是application/json.

但是当我使用RestKit时,我得到了关于'预期状态代码在(400-499),得到200'的错误,我认为200很好,为什么RestKit期望400 - 499而不是200?我也可以在错误消息中看到json对象.这是{"d":"2013-07-15T02:30:00.000Z","t":16.1,"at":13.8}.

谢谢.

ios restkit-0.20

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

- [NSObject(NSObject)doesNotRecognizeSelector:]调用时崩溃 - [ViewController prepareForSegue:sender:]

我正在使用Crashlytics来检测我的应用程序中的崩溃.我偶尔会得到以下崩溃报告.

关键崩溃点是 - [NSObject(NSObject)doesNotRecognizeSelector:]和MyViewController.m第596行 - [MyViewController prepareForSegue:sender:].我不知道日志中的问题是什么.是否可能出现多线程问题?我也在使用Parse SDK从Parse云中检索数据.而prepareForSegue:sender:方法将在用户点击披露指标时调用,它应该在主线程中运行.你能不能给我一些提示来解决这个问题.提前致谢.

这是我如何调用prepareForSegue:sender:method.

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"oneSegue" sender:indexPath];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"oneSegue"]) {
        NSIndexPath *indexPath = (NSIndexPath*)sender;
        OneViewController *destViewController = segue.destinationViewController;
        OneClass* oneObject = self.array[indexPath.row];
        destViewController.objectName = oneObject.name;
    }
}
Run Code Online (Sandbox Code Playgroud)

prepareForSegue:sender:方法由accessoryButtonTappedForRowWithIndexPath:方法触发.我看不到任何其他方式来调用prepareForSegue:sender:方法.所以我不知道为什么indexPath.row会导致异常.

Fatal Exception NSInvalidArgumentException
-[UITableViewCell row]: unrecognized selector sent to instance 0x1f8a6dd0
0    CoreFoundation  __exceptionPreprocess + 162
1    libobjc.A.dylib     objc_exception_throw + 30
2    **CoreFoundation    -[NSObject(NSObject) doesNotRecognizeSelector:] + 170**
3    CoreFoundation  ___forwarding___ + 392
4    CoreFoundation …
Run Code Online (Sandbox Code Playgroud)

objective-c ios crashlytics

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

无法在iOS7上看到动态子视图(在iOS6上工作)

我有一个自定义的TableViewCell.在单元格中,我将两个交叉图标(使用unicode)添加到单元格的两侧.当用户平移单元格时,它将在侧面显示十字图标.

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // add a cross
        _crossLabel = [self createCueLabel];
        _crossLabel.text = @"\u274C";
        _crossLabel.textAlignment = NSTextAlignmentLeft;
        // none of the following code works
        [self insertSubview:_crossLabel aboveSubview:self];
        [self insertSubview:_crossLabel belowSubview:self];
        [self addSubview:_crossLabel];

        _crossLabel2 = [self createCueLabel];
        _crossLabel2.text = @"\u274C";
        _crossLabel2.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_crossLabel2];

        // add a pan recognizer
        UIGestureRecognizer* recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
        recognizer.delegate = self;
        [self addGestureRecognizer:recognizer];
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

我使用上面的代码来实现这一点.并且_crossLabel确实添加了Custom TableView Cell.

我使用 …

objective-c uitableview addsubview ios ios7

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

如何在iOS7 SpriteKit中为不同大小的图像制作动画?

我正在使用流动的代码来动画我的精灵节点.

        NSMutableArray *jumpUpTextures = [NSMutableArray arrayWithCapacity:10];
        for (int i = 0; i < 4; i++) {
            NSString *textureName = [NSString stringWithFormat:@"runnerJumpUp%d", i];
            SKTexture *texture = [SKTexture textureWithImageNamed:textureName];
            [jumpUpTextures addObject:texture];
        }

        SKAction *jumpUpAnimation = [SKAction animateWithTextures:jumpUpTextures timePerFrame:0.2]; 
Run Code Online (Sandbox Code Playgroud)

除了一个图像看起来更大和模糊之外,动画效果还可以.我有4张图片,大小如下:

runnerJumpUp0.png 62*56
runnerJumpUp1.png 62*56
runnerJumpUp2.png 62*56
runnerJumpUp3.png 47*56
Run Code Online (Sandbox Code Playgroud)

最后一个的大小与其他三个不同.动画运行时,最后一个图像将向上扩展.精灵的最后一帧看起来比其他帧大.你能告诉我该如何解决这个问题?

非常感谢.

可靠的人

ios7 sprite-kit skspritenode sktexture

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

Shopify使用Liquid脚本对cart.items数组进行排序

我想在cart.liquid文件中对cart.items数组进行排序.然后我可以按预期的顺序显示表格中的时间.

    {% for item in cart.items sort_by:item.line_price %}
    <div class="row">
      <div class="span12">
      <h1>Your cart</h1>
      <form action="/cart" method="post" id="cartform">
        <table>
        </table>
      </form>
      </div>
    </div>
    {% endfor %}
Run Code Online (Sandbox Code Playgroud)

但是代码不起作用,因为我不能sort_by:item.line_pricefor语句中使用.

如何使用内置功能对数组进行排序?

另一个问题是Shopify液体不支持创建阵列.如果我使用自己的算法对数组进行排序.但是如何将输出保存到新阵列?

非常感谢.

liquid-layout liquid shopify

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

通过 Shopify API 设置产品发布日期无法正常工作

当我通过Shopify 产品更新 API ( https://ashop.myshopify.com/admin/products/product_id.json PUT)使用以下 JSON 将published_at 设置为未来日期时。

{
  "product": {
    "id": 632910392,
    "published": false,
    "published_at": "2015-01-01T00:00:00+11:00"
  }
}
Run Code Online (Sandbox Code Playgroud)

它返回 200 和以下 JSON

{
    "product": {
        "body_html": "something",
        "created_at": "2014-01-07T14:49:00+11:00",
        "handle": "test-product",
        "id": 206281997,
        "product_type": "MERCHANDISE",
        "published_at": "2015-01-01T00:00:00+11:00",
        "published_scope": "",
       },
    /* some other JavaScript properties*/
}
Run Code Online (Sandbox Code Playgroud)

Shopify 接受了发布日期,但产品仍然可见。下面是产品可见性的截图 在此处输入图片说明

但是,如果我从请求 JSON 中删除 "published_at": "2015-01-01T00:00:00+11:00" ,该产品将更改为隐藏。

如何通过 Shopify API 设置发布日期?是否可能是 Shopify API 的错误?

谢谢你的帮助。

shopify

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