Blog

Preparation for JLPT N3

I’ve registered to take the JLPT N3 exam in December. I’ve found the following resources to be useful:

IOS Apps:

  1. JLPT Study – let’s you test your knowledge of Kanji or Vocabulary, sorted by level, N5 all the way to N1. I’ve ignored the Kanji, and am just going for the Vocabulary.
  2. Quizlet – let’s you create your own flash cards for Kanji / words you don’t know. I’ve created two sets: one for words I don’t know in the various JLPT N3 books, and one for other words I come across that I don’t know – could be any level.
  3. Google translate – let’s me enter Japanese text by typing or writing the Kanji. the translation is often not so accurate, but good enough.
  4. aNote (awesome note) – let’s me copy and paste or enter Japanese words, but in a large font size for readability. Any app where you can specify the font size should do. If I also highlight the text it gives me the option to ‘lookup’ the word in the iPhone built-in Japanese dictionaries which is quicker than using Google Translate.

Websites:

  1. news.tbs.co.jp – excellent resource – short news clips, complete with corresponding transcriptions. You can either watch the video, or try and read the transcription, or do both!
  2. jisho.org – I use this for looking up Kanji. In the search field enter #kanji followed by the Kanji you want to look up

Books:

I started with reading:

N3 読む 文章の文法。読解 published by UNICOM Inc. ISBN978-4-89689-471-4

This book was pretty good for reading practise. I then decided to try a practise test to see where I needed to focus on. Seems that the only official practise papers are published by 凡人社 – 公式問題集N3. My weak point was grammar.

After checking reviews I then bought TRY!文法から伸ばす日本語 published by ASK. ISBN978-4-87217-902-6.

I’m only on Section 2 out of 11, but the book seems well organised. Even better it has English explanations for the grammar points. This book will definitely help me prepare for the grammar questions.

-Stuart.

 

How to Create Ringtones for iPhone from any audio

You can create ringtones for iPhone on your mac by following the steps below.

  1. Install iShowU Audio Capture from here. This gives you the ability to redirect audio playing on your macbook to GarageBand or other applications.
  2. Go to System Preferences…Audio and set the Output to be ‘iShowU Audio Capture’.
  3. Record the audio you want to turn into a ringtone using GarageBand or another application. In the case of GarageBand you can create a new Project and choose ‘Record Using a Microphone or line input’. Although you won’t hear what you’re recording, you’ll see the levels for the track move up and down.
  4. Go back to ‘System Preferences…Audio’ on the mac and change the Output back to ‘Internal Speakers’. Then go ahead and edit the Audio you recorded in step 3.
  5. Export/save to disk the audio as AAC. Note: the total length has to be 30 sec or under. Don’t use any special characters in the file name.
  6. In Finder, locate the file and change the file extension from m4v to m4r.
  7. In iTunes, make sure your iPhone is connected (via wifi or cable), and under your device there should be a submenu item called ‘Tones’. Click on that item to open it.
  8. Drag and drop the m4r file from Finder to the right-hand side of iTunes. It should then be listed if successful.
  9. on the iPhone go to settings…Sounds…then tap on ‘Ringtone’. You should then see your new ringtone listed at the top under  the ‘RINGTONES’ section. Select it, and you’re done!

Note: I’ve tried this once so far. It works, but I have some issues with the quality of the audio in the ringtone. Need to figure that out…

How to copy Objects in Swift

I wanted to populate an array with multiple unique copies of an existing object. If you just append the same object in a loop, you just end up with an array with multiple references to the one object!

I thought that there would be a simple way to copy the instance of an object in Swift. I was wrong! The simplest way is to use copy() which requires the following three steps:

  1. Make your class conform to NSCopying. This isn’t strictly required, but it makes your intent clear.
  2. Implement the method copy(with:), where the actual copying happens.
  3. Call copy() on your object.

See hackingwithswift.com for more details…

 

How to add a ‘Done’ button to a numberPad in Swift

The best way to add a ‘Done‘ button to a numberPad, which doesn’t have it by default,  is to extend UITextField. Three steps:

1. set the keyboard type for your UITextField in your viewController subclass:

e.g. myTextField.keyboardType = UIKeyboardType.numberPad

2. save the code below the line as  ‘UITextField+Extensions.swift’ and add to your project.

3. After this, if you select any UITextField in the storyboard editor, there will be a new item under the ‘Attributes Inspector’ for that UITextField, where you can set ‘Done Access…’ On, Off or default. Choose ‘On’ if you want the ‘Done’ button to show up.


import Foundation

import UIKit

extension UITextField{

       @IBInspectable var doneAccessory: Bool{

        get{

            return self.doneAccessory

        }

        set (hasDone) {

            if hasDone{

                addDoneButtonOnKeyboard()

            }

        }

    }

    

    func addDoneButtonOnKeyboard()

    {

        let doneToolbar: UIToolbar = UIToolbar(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))

        doneToolbar.barStyle = .default

        

        let flexSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)

        let done: UIBarButtonItem = UIBarButtonItem(title: “Done”, style: .done, target: self, action: #selector(self.doneButtonAction))

        

        let items = [flexSpace, done]

        doneToolbar.items = items

        doneToolbar.sizeToFit()

        

        self.inputAccessoryView = doneToolbar

    }

    

    @objc func doneButtonAction()

    {

    self.resignFirstResponder()

    }

}

how to do validation of a UITextField, while still being edited

If you want to add validation to an instance of UITextField, while editing is still going on, there are a few things you need to do.

Step 1:

Make the viewController adopts UITextFieldDelegate in the class declaration

e.g. class myViewController: UIViewController, UITextFieldDelegate {…}

Step 2:

Set the viewController as the delegate for each of your UITextFields, e.g. in the viewController’s viewDidLoad() function. ‘self’ refers to the viewController.

e.g. myTextField.delegate = self

Step 3:

You need to include the following optional delegate function within your viewController class:

    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {…}

The important thing to note is that you can’t just check if the UITextField.text is nil or empty when unwrapped, because that won’t work if the UITextField is currently being edited. For that you need to check the UITextField.text + the replacementString.

 

Note: Since UITextField.text can be nil, safer to set a variable using the nil coalescing operator, then concatonate with the string

e.g. let currentTextInTextField = textField.text ?? “”

then you can do your validation against (currentTextInTextField+string)

Step 4:

return false if your validation fails, or true if it succeeds.

iPhone / Apple Watch and EZ-Link, NETS Flashpay

Since my iPhone reacts when brought near to the NFC (near-field communication) terminal on the bus and brings up the “Pay with Touch ID” screen, I was wondering if you could use your iPhone instead of an EZ-Link or NETS Flashpay card to pay for a bus or train trip.

SMRT and SBS Transit support the EZ-Link and NETS Flashpay contactless cards for payment on buses and trains here in Singapore.

Since a few years ago both Android and iPhone handsets have started to include an NFC chip. I believe that there are android apps that let you use your android phone as an EZ-Link / NETS Flashpay card.

As far as the iPhone is concerned, Apple added some NFC support in iOS11 – it should now be possible to use an iPhone to *read* an NFC card. As far as using an iPhone with an NFC terminal however, they restrict that functionality to only support Apple Pay – that’s why you can’t currently use your iPhone to pay for a trip on the bus or train.

update – I heard that Apple do support the Suica transit card in Japan.

Let’s hope they start extending the support of transit cards to other countries – including Singapore…

-Stuart.

How to add your Starbucks Card to Apple Watch (if ‘Wallet’ isn’t an option)

Even though there’s no Starbucks app for Apple Watch here in Singapore, and no option for adding your Starbucks card to the ‘Wallet’, you can still use your Apple Watch as your Starbucks Card. Here’s how:

  1. open your Starbucks app on the iPhone.
  2. click on ‘Pay’ at the bottom. You will then see a screen showing your card’s barcode
  3. Do a screen-shot by pressing the home button and power button at the same time
  4. Tap on the small image in the bottom left to bring up the image editor
  5. Crop the image to only have the barcode showing, then tap ‘Done’ and chose ‘Save to Photos’.
  6. Open the barcode image in the Photos app. tap on ‘Edit’. Tap on the ‘rotate and crop’ button at the bottom. Then you’ll see a ‘rotate by 90 degrees’ button show up. Tap that twice to rotate the barcode image by 180 degrees.
  7. Tap ‘Done’.
  8. Create a new Album and call it ‘Starbucks’. Add that image to the album.
  9. Open the ‘watch’ app on the iPhone and under ‘Synced Album’ choose ‘Starbucks’. The image will then get copied over to the Apple Watch.
  10. When you want to pay at Starbucks using the watch, open the ‘Photos’ app on the watch. Turn your wrist so that the screen points to the barcode reader and press the crown or touch the screen so that the image shows on the watch.

Update: This has worked for me five times so far, at different outlets. Has only failed once – where the barcode scanner was in an odd position…