i've got frustrating situation swift 2.2 (xcode 7.3). simulate it, create variable in user defined, generic class, , reference class someplace else. example:
class a<t> { let genvar = 1 } class myviewcontroller: uiviewcontroller { let myvar = a<int>() // crash here }
if run code on device running ios 7 (iphone 4, in case), crash on attempt of creating variable of generic type. here first lines of device crash log:
exception type: exc_bad_access (sigbus) exception subtype: kern_protection_failure @ 0x00298910 triggered thread: 0 thread 0 crashed: 0 libswiftcore.dylib 0x006b1d64 0x4bd000 + 2051428 1 phone 0x001c76ec 0xab000 + 1165036 2 libswiftcore.dylib 0x006b307c 0x4bd000 + 2056316 3 libswiftcore.dylib 0x006b2f70 0x4bd000 + 2056048 4 libswiftcore.dylib 0x006b0f24 0x4bd000 + 2047780 5 libswiftcore.dylib 0x006b107c 0x4bd000 + 2048124 6 phone 0x0014e730 0xab000 + 669488 7 phone 0x00129390 0xab000 + 517008 8 uikit 0x31e9d9c4 -[uiclassswapper initwithcoder:] + 188
on ios 8 , 9 simulators/devices, code above works okay.
is swift support ios 7 going dropped in near future?
i've been tripped appears 2 bugs swift generics in ios 7. here's how fix them.
bug #1 - must define generic first property in class before others.
example - code fails:
public class testios7<t> { private var x: int? } let x = testios7<string>()
but here's workaround:
public class testios7<t> { private var kludge: t? private var x: int? } let x = testios7<string>()
bug #2: class constraints seem broken.
example - code fails:
class classa<b: classb> { } class classb { } let x = classa <string>()
i have not found workaround aside removing "classb" constraint , rewriting code deal fact basically, language feature no longer exists. particular painful when need call initializer of classb classa - had rewrite block hardwired if/then/else classb subclasses until apple fixes this.
if find workaround bug #2 please let me know!
Comments
Post a Comment