Import For Me - a simple Xcode source editor extension

I just built a little Xcode source editor extension to add an import line without jumping to the head of file.

Xcode extension

Sometime when you are busy at typing some coolest swift code in the world but find you need to import a missing module, you have to jump to the head of file, import it and lose yourself in no where.

This little extension will save you. Just typing the module name in a new line and launch the extension, the module will be automatically imported to the head of file and leave you at where you are.

It works with swift file. Have a check at robin/importForMe

2048 in swift playground

I composed a 2048 game with less than 400 lines of code in swift playground a couple of months ago. I just wanted to see how serious Swift Playground for iOS 10 could be. I wrote most of the code in a coffee bar with my iPad Pro. Dash for iPad was my best friend especially when I did not have Xcode along with me. It reminded me when I was in my teenage and typed lines of BASIC into my Apple II clone just to play Snake.

Now Swift Playground has been officially released with iOS 10 and I just updated my 2048 to the latest version of Swift 3.0. If you like, you can check it out and have some fun with numbers.

NSTextField’s attributedString and truncating

I have a NSTextField in a table cell view. Since it can be to long to show, I set the line break as Truncate Middle in interface builder. But no matter how I tried, the truncating just did not work.

After some investigation, I found the problem is that I set the ‘’’attributed string’’’ explicitly and it overrides the line break setting by interface builder. I have to set it when I made up the attributed string.

let paragraph = NSMutableParagraphStyle()
paragraph.lineBreakMode = .ByTruncatingMiddle

let attributes = [NSParagraphStyleAttributeName:paragraph]

attributedString.addAttributes(attributes, range:  range )

It is pretty obvious when you know the problem. Of course the setting of line break in interface building is overridden by the attributedString. It’s just the same as the the setting of text color, background color and so on. The line break setting is under Control section. I think that’s why I was confused in the first place.