Jason


  • Categories

  • Search

Action When Enter-key is Pressed on NSTextField

Posted on 2016-04-17 | In Cocoa

Add Action in NSTextField’s Delegate

1
2
3
@IBAction func textFieldAction(sender: NSTextField) {
print(sender.stringValue)
}

Connect NSTextField’s Action to Delegate’s One

Set NSTextField’s Action Type

XCode Debug Flag for Swift

Posted on 2016-04-16 | In Cocoa

Set Debug Flag in XCode for Swift

  • Open ‘Build Settings’ for Project (not target)
  • Search ‘Swift Compiler - Custom Flags‘. Add a -D DEBUG entry in Other Swift Flags

Use Debug Flag in Swift

1
2
3
4
5
#if DEBUG
print("I'm running in DEBUG mode")
#else
print("I'm running in a non-DEBUG mode")
#endif

Swift & Cocoa: Localization

Posted on 2016-04-15 | In Cocoa

This article records the detailed steps to add localizations for a project. The project could be downloaded here.

Development environment:

  • OS X: 10.11.4
  • XCode: 7.3
  • Swift: 2.2

Auto Layout and Double-Length Pseudolanguage

For localized app, typically you need to set the UI to ‘Auto Layout‘. As the same string in different languages may have very different length, the ‘auto layout’ could let each language corecttly display.

How to test the auto layout correclty work or not? Beside really test the app with different language, you can also use ‘Double-Length Pseudolanguage‘. This localization simply takes the text of your development language, and doubles it. So, for example, “Tell the World” becomes “Tell the World Tell the World.” While many pieces of text won’t actually double in length when translated to another langauge, it serves as a great way to test to see whether your interface can handle the wide variation in length.

Steps to preview a localization in Interface Builder:

  • In project navigator, select the .storyboard or .xib file you want to preview.
  • Choose View > Assistant Editor > Show Assistant Editor.
  • In the assistant editor jump bar, open the Assistant pop-up menu, scroll to and choose the Preview item, and choose the .storyboard or .xib file from the submenu.
    If a preview of the app’s user interface doesn’t appear in the assistant editor, select the window or view you want to preview in the icon or outline view.

  • In the assistant editor, choose the localization you want to preview from the language pop-up menu in the lower-right corner.

Now, a preview of the localization appears in the assistant editor. If you choose a real language, strings that do not need to be localized or need to be localized, but currently are not, appear in uppercase.

Read more »
1234
Jason

Jason

Digital Nomad, Mac Developer

12 posts
2 categories
RSS
GitHub Twitter
Links
  • Toolinbox
© 2011 - 2019 Jason