Skip to content

Commit

Permalink
Swift 3 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Suragch committed Dec 30, 2016
1 parent 0103fd3 commit 8ee2425
Show file tree
Hide file tree
Showing 14 changed files with 266 additions and 275 deletions.
39 changes: 24 additions & 15 deletions aePronunciation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
objects = {

/* Begin PBXBuildFile section */
505489151BBD672B00C4B141 /* raw in Resources */ = {isa = PBXBuildFile; fileRef = 505489141BBD672B00C4B141 /* raw */; settings = {ASSET_TAGS = (); }; };
5074CC0A1BBCCDAF005B0871 /* LearnSingleSoundsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5074CC091BBCCDAF005B0871 /* LearnSingleSoundsViewController.swift */; settings = {ASSET_TAGS = (); }; };
508360571BC29A0A00A225E6 /* PracticeSoundsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508360561BC29A0A00A225E6 /* PracticeSoundsViewController.swift */; settings = {ASSET_TAGS = (); }; };
508360591BC29ABA00A225E6 /* Player.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508360581BC29ABA00A225E6 /* Player.swift */; settings = {ASSET_TAGS = (); }; };
50D64FD31BBE5083003657A4 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 50D64FD21BBE5083003657A4 /* Localizable.strings */; settings = {ASSET_TAGS = (); }; };
50D64FD51BBE5D8B003657A4 /* String+localized.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D64FD41BBE5D8B003657A4 /* String+localized.swift */; settings = {ASSET_TAGS = (); }; };
50D64FD71BBE7E96003657A4 /* SingleSound.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D64FD61BBE7E96003657A4 /* SingleSound.swift */; settings = {ASSET_TAGS = (); }; };
50D64FD91BBE912C003657A4 /* LearnDoubleSoundsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D64FD81BBE912C003657A4 /* LearnDoubleSoundsViewController.swift */; settings = {ASSET_TAGS = (); }; };
505489151BBD672B00C4B141 /* raw in Resources */ = {isa = PBXBuildFile; fileRef = 505489141BBD672B00C4B141 /* raw */; };
5074CC0A1BBCCDAF005B0871 /* LearnSingleSoundsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5074CC091BBCCDAF005B0871 /* LearnSingleSoundsViewController.swift */; };
508360571BC29A0A00A225E6 /* PracticeSoundsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508360561BC29A0A00A225E6 /* PracticeSoundsViewController.swift */; };
508360591BC29ABA00A225E6 /* Player.swift in Sources */ = {isa = PBXBuildFile; fileRef = 508360581BC29ABA00A225E6 /* Player.swift */; };
50D64FD31BBE5083003657A4 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 50D64FD21BBE5083003657A4 /* Localizable.strings */; };
50D64FD51BBE5D8B003657A4 /* String+localized.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D64FD41BBE5D8B003657A4 /* String+localized.swift */; };
50D64FD71BBE7E96003657A4 /* SingleSound.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D64FD61BBE7E96003657A4 /* SingleSound.swift */; };
50D64FD91BBE912C003657A4 /* LearnDoubleSoundsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50D64FD81BBE912C003657A4 /* LearnDoubleSoundsViewController.swift */; };
50DC216F1BB8FF65000075AE /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50DC216E1BB8FF65000075AE /* AppDelegate.swift */; };
50DC21761BB8FF65000075AE /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 50DC21741BB8FF65000075AE /* Main.storyboard */; };
50DC21781BB8FF65000075AE /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 50DC21771BB8FF65000075AE /* Assets.xcassets */; };
50DC217B1BB8FF65000075AE /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 50DC21791BB8FF65000075AE /* LaunchScreen.storyboard */; };
50DC21861BB8FF65000075AE /* aePronunciationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50DC21851BB8FF65000075AE /* aePronunciationTests.swift */; };
50DC21911BB8FF65000075AE /* aePronunciationUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50DC21901BB8FF65000075AE /* aePronunciationUITests.swift */; };
50E2EAF41BD6182600842ED3 /* TestResultsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E2EAF31BD6182600842ED3 /* TestResultsViewController.swift */; settings = {ASSET_TAGS = (); }; };
50E420251BBF5DD40092F74B /* DoubleSoundsCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E420241BBF5DD40092F74B /* DoubleSoundsCollectionViewCell.swift */; settings = {ASSET_TAGS = (); }; };
50E420271BBF684C0092F74B /* DoubleSound.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E420261BBF684C0092F74B /* DoubleSound.swift */; settings = {ASSET_TAGS = (); }; };
50E9E6421BD4A577002CC689 /* TestSetupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E9E6411BD4A577002CC689 /* TestSetupViewController.swift */; settings = {ASSET_TAGS = (); }; };
50E9E6441BD4ABBB002CC689 /* Answer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E9E6431BD4ABBB002CC689 /* Answer.swift */; settings = {ASSET_TAGS = (); }; };
50E9E64A1BD50717002CC689 /* Key.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E9E6491BD50717002CC689 /* Key.swift */; settings = {ASSET_TAGS = (); }; };
50E9E64C1BD50A50002CC689 /* TestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E9E64B1BD50A50002CC689 /* TestViewController.swift */; settings = {ASSET_TAGS = (); }; };
50E2EAF41BD6182600842ED3 /* TestResultsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E2EAF31BD6182600842ED3 /* TestResultsViewController.swift */; };
50E420251BBF5DD40092F74B /* DoubleSoundsCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E420241BBF5DD40092F74B /* DoubleSoundsCollectionViewCell.swift */; };
50E420271BBF684C0092F74B /* DoubleSound.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E420261BBF684C0092F74B /* DoubleSound.swift */; };
50E9E6421BD4A577002CC689 /* TestSetupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E9E6411BD4A577002CC689 /* TestSetupViewController.swift */; };
50E9E6441BD4ABBB002CC689 /* Answer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E9E6431BD4ABBB002CC689 /* Answer.swift */; };
50E9E64A1BD50717002CC689 /* Key.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E9E6491BD50717002CC689 /* Key.swift */; };
50E9E64C1BD50A50002CC689 /* TestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E9E64B1BD50A50002CC689 /* TestViewController.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -267,15 +267,18 @@
50DC216A1BB8FF65000075AE = {
CreatedOnToolsVersion = 7.0;
DevelopmentTeam = HSUZ2UJNHR;
LastSwiftMigration = 0820;
};
50DC21801BB8FF65000075AE = {
CreatedOnToolsVersion = 7.0;
DevelopmentTeam = 6W926R56AA;
LastSwiftMigration = 0820;
TestTargetID = 50DC216A1BB8FF65000075AE;
};
50DC218B1BB8FF65000075AE = {
CreatedOnToolsVersion = 7.0;
DevelopmentTeam = 6W926R56AA;
LastSwiftMigration = 0820;
TestTargetID = 50DC216A1BB8FF65000075AE;
};
};
Expand Down Expand Up @@ -495,6 +498,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.aepronunciation.ipa;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -509,6 +513,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.aepronunciation.ipa;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand All @@ -521,6 +526,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.aepronunciation.aePronunciationTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/aePronunciation.app/aePronunciation";
};
name = Debug;
Expand All @@ -533,6 +539,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.aepronunciation.aePronunciationTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/aePronunciation.app/aePronunciation";
};
name = Release;
Expand All @@ -544,6 +551,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.aepronunciation.aePronunciationUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_TARGET_NAME = aePronunciation;
USES_XCTRUNNER = YES;
};
Expand All @@ -556,6 +564,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.aepronunciation.aePronunciationUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_TARGET_NAME = aePronunciation;
USES_XCTRUNNER = YES;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "aePronunciation/TestViewController.swift"
timestampString = "467645590.648241"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "150"
endingLineNumber = "150">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
Expand All @@ -30,7 +16,7 @@
startingLineNumber = "218"
endingLineNumber = "218"
landmarkName = "getRandomIpa()"
landmarkType = "5">
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
Expand Down
22 changes: 11 additions & 11 deletions aePronunciation/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,40 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

override init() {
let defaults = NSUserDefaults.standardUserDefaults()
let defaultValues = [
let defaults = UserDefaults.standard
let defaultValues : [String : Any] = [
Key.name : "",
Key.numberOfQuestions : 50,
Key.contentType : ExamType.Doubles.rawValue
Key.contentType : ExamType.doubles.rawValue
]
defaults.registerDefaults(defaultValues as! [String : AnyObject])
defaults.register(defaults: defaultValues)
super.init()
}

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

func applicationWillResignActive(application: UIApplication) {
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(application: UIApplication) {
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

Expand Down
10 changes: 5 additions & 5 deletions aePronunciation/DoubleSound.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DoubleSound {
"il", "ɪl", "el", "ɛl", "æl", "ɑl", "ɔl", "ol", "ʊl", "ul", "ʌl", "aɪl", "aʊl", "ɔɪl", "ɝl", "ɑrl", "ɛrl", "ɪrl", "ɔrl"
]

private let fileNameDictionary = [
fileprivate let fileNameDictionary = [
"pi": "pairs01_01",
"": "pairs01_02",
"pe": "pairs01_03",
Expand Down Expand Up @@ -870,7 +870,7 @@ class DoubleSound {

// MARK: - Methods

func fileNameForIpa(ipa: String) -> String? {
func fileNameForIpa(_ ipa: String) -> String? {

return fileNameDictionary[ipa]
}
Expand All @@ -884,7 +884,7 @@ class DoubleSound {
return ipaStringList[Int(index)]
}

func parse(ipaDouble: String) -> (String, String)? {
func parse(_ ipaDouble: String) -> (String, String)? {

let length = ipaDouble.characters.count

Expand Down Expand Up @@ -917,7 +917,7 @@ class DoubleSound {
return (firstSound, secondSound)
}

func isValidIpaDouble(ipa: String) -> Bool {
func isValidIpaDouble(_ ipa: String) -> Bool {

if fileNameDictionary[ipa] == nil {
return false
Expand All @@ -928,4 +928,4 @@ class DoubleSound {
}


}
}
4 changes: 2 additions & 2 deletions aePronunciation/DoubleSoundsCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class DoubleSoundsCollectionViewCell: UICollectionViewCell {

@IBOutlet weak var cellLabel: UILabel!

override var highlighted: Bool {
override var isHighlighted: Bool {
didSet {
if (highlighted) {
if (isHighlighted) {
self.layer.opacity = 0.6;
} else {
self.layer.opacity = 1.0;
Expand Down
12 changes: 6 additions & 6 deletions aePronunciation/LearnDoubleSoundsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ import AudioToolbox
class LearnDoubleSoundsViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {


private let player = Player()
fileprivate let player = Player()
let reuseIdentifier = "cell"
let doubleSound = DoubleSound()

// MARK: - UICollectionViewDataSource protocol

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return doubleSound.ipaStringList.count
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! DoubleSoundsCollectionViewCell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! DoubleSoundsCollectionViewCell

cell.cellLabel.text = doubleSound.ipaStringList[indexPath.item]
cell.cellLabel.textColor = self.view.tintColor
//cell.backgroundColor = UIColor.yellowColor()
cell.layer.borderColor = self.view.tintColor.CGColor // UIColor.blueColor().CGColor
cell.layer.borderColor = self.view.tintColor.cgColor // UIColor.blueColor().CGColor
cell.layer.borderWidth = 1
cell.layer.cornerRadius = 8

Expand All @@ -30,7 +30,7 @@ class LearnDoubleSoundsViewController: UIViewController, UICollectionViewDataSou

// MARK: - UICollectionViewDelegate protocol

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

// play sound
let ipa = doubleSound.ipaStringList[indexPath.item]
Expand Down
28 changes: 14 additions & 14 deletions aePronunciation/LearnSingleSoundsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import AudioToolbox

class LearnSingleSoundsViewController: UIViewController {

private let player = Player()
private let defaultIpaToShowFirst = "æ"
private let singleSound = SingleSound()
fileprivate let player = Player()
fileprivate let defaultIpaToShowFirst = "æ"
fileprivate let singleSound = SingleSound()

// MARK: - Outlets

Expand All @@ -17,7 +17,7 @@ class LearnSingleSoundsViewController: UIViewController {

// MARK: - Actions

@IBAction func keyTapped(sender: UIButton) {
@IBAction func keyTapped(_ sender: UIButton) {

let buttonText = sender.titleLabel?.text ?? ""

Expand All @@ -30,7 +30,7 @@ class LearnSingleSoundsViewController: UIViewController {

}

@IBAction func example1(sender: UIButton) {
@IBAction func example1(_ sender: UIButton) {


if let ipa = ipaLabel.text {
Expand All @@ -41,7 +41,7 @@ class LearnSingleSoundsViewController: UIViewController {

}

@IBAction func example2(sender: UIButton) {
@IBAction func example2(_ sender: UIButton) {

if let ipa = ipaLabel.text {
if let fileName = singleSound.exampleTwoFileNameFromIpa(ipa) {
Expand All @@ -50,7 +50,7 @@ class LearnSingleSoundsViewController: UIViewController {
}
}

@IBAction func example3(sender: UIButton) {
@IBAction func example3(_ sender: UIButton) {

if let ipa = ipaLabel.text {
if let fileName = singleSound.exampleThreeFileNameFromIpa(ipa) {
Expand All @@ -68,23 +68,23 @@ class LearnSingleSoundsViewController: UIViewController {
updateDisplayForIpa(defaultIpaToShowFirst)

// Center button text
example1.titleLabel?.textAlignment = NSTextAlignment.Center
example2.titleLabel?.textAlignment = NSTextAlignment.Center
example3.titleLabel?.textAlignment = NSTextAlignment.Center
example1.titleLabel?.textAlignment = NSTextAlignment.center
example2.titleLabel?.textAlignment = NSTextAlignment.center
example3.titleLabel?.textAlignment = NSTextAlignment.center
}



func updateDisplayForIpa(ipa: String) {
func updateDisplayForIpa(_ ipa: String) {

if let fileName = singleSound.fileNameForIpa(ipa) {

ipaLabel.text = ipa
ipaDescription.text = "\(fileName)_description".localized
ipaDescription.scrollRangeToVisible(NSRange(location: 0, length: 0))
example1.setTitle("\(fileName)_example1".localized, forState: UIControlState.Normal)
example2.setTitle("\(fileName)_example2".localized, forState: UIControlState.Normal)
example3.setTitle("\(fileName)_example3".localized, forState: UIControlState.Normal)
example1.setTitle("\(fileName)_example1".localized, for: UIControlState())
example2.setTitle("\(fileName)_example2".localized, for: UIControlState())
example3.setTitle("\(fileName)_example3".localized, for: UIControlState())

}
}
Expand Down
Loading

0 comments on commit 8ee2425

Please sign in to comment.