当前位置: 动力学知识库 > 问答 > 编程问答 >

Swift/iOS: generified UIScrollView subclass causes memory issues

问题描述:

I tried to subclass UIScrollView and use generics on it. It has two arrays of those generified types.

import UIKit

class SomeView<T: NSObject, U: NSObject>: UIScrollView {

var array1 = [T]()

var array2 = [U]()

override init() {

super.init(frame: CGRectZero)

}

required init(coder aDecoder: NSCoder) {

fatalError("init(coder:) has not been implemented")

}

}

I tried to instantiate this class like so:

SomeView <NSObject, NSObject>()

Gives me the following error:

*** NSForwarding: warning: object 0x7f9cd9612660 of class 'Swift._IndirectArrayBuffer' does not implement

methodSignatureForSelector: -- trouble ahead Unrecognized selector

-[Swift._IndirectArrayBuffer addObject:]

What the f?!

I tried lots of things, but every time I got very different errors, all seem to indicate that some weird memory issue is going on. It seems to only happen when subclassing UIScrollView, when I try UIButton or UIView for example there seem to be no issues...

Try it! Paste the above class in a new XCode project (iOS) and instantiate this class from the AppDelegate and you will be able to reproduce it. I tried this in:

  • XCode 6.1.1 (6A2008a)
  • XCode-beta 6.3 (6D520o)

分享给朋友:
您可能感兴趣的文章:
随机阅读: