9 ms·
Awesome. I just finished a small Mac App in Swift [1], and I've run into lots of small situations where I wasn't sure what the best practice would be. Really lo
by terhechte 12y ago
Awesome. I just finished a small Mac App in Swift [1], and I've run into lots of small situations where I wasn't sure what the best practice would be. Really looking forward to reading this one.
In particular, I found the required casting of AnyObject! to whatever I was expecting it to be not perfect (sometimes I thought that the typechecker really ought to figure some types out). Also, best practices for when to use NSArray vs. Array / NSString vs. String, etc. is another thing I look forward to.
Also, Some of the issues I ran into are probably due to Swift being beta, so knowing what the right way should be (even though it doesn't work that way yet) is important as it keeps me from hanging on to bad style.
[1] https://github.com/terhechte/Swijito https://github.com/terhechte/Swijito
- k-mcgrady 12y ago>> "In particular, I found the required casting of AnyObject! to whatever I was expecting it to be not perfect (sometimes I thought that the typechecker really ought to figure some types out). Also, best practices for when to use NSArray vs. Array / NSString vs. String, etc. is another thing I look forward to." Same issues I was having. I was porting an obj-c class to Swift and continued to use obj-c objects (NSString etc.). I then had to put 'as NSString' at the end of most lines. I'm considering going back and experimenting to see where I can use swift native objects. Hopefully this book will shed more light on the subject.
- dunham 12y agoYeah, I managed to crash the compiler (SEGV) with AnyObject! casting. (I got the wrong idiom for iterating through an AnyObject[] ) The code contained a type error that the XCode compiler either missed or crashed before reporting. The command line compiler detected and reported my error. I guess not telling us the "right" way enables us to fuzz test the compiler. :)