Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Swift 3 syntax for Chapter 6 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Chapter 06/Singleton/Singleton.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
TargetAttributes = {
667A1AA419F6A7B200060D1B = {
CreatedOnToolsVersion = 6.1;
LastSwiftMigration = 0820;
};
};
};
Expand Down Expand Up @@ -212,13 +213,15 @@
isa = XCBuildConfiguration;
buildSettings = {
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
667A1AAE19F6A7B200060D1B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -241,6 +244,7 @@
667A1AAE19F6A7B200060D1B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "667A1AA419F6A7B200060D1B"
BuildableName = "Singleton"
BlueprintName = "Singleton"
ReferencedContainer = "container:Singleton.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "667A1AA419F6A7B200060D1B"
BuildableName = "Singleton"
BlueprintName = "Singleton"
ReferencedContainer = "container:Singleton.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "667A1AA419F6A7B200060D1B"
BuildableName = "Singleton"
BlueprintName = "Singleton"
ReferencedContainer = "container:Singleton.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "667A1AA419F6A7B200060D1B"
BuildableName = "Singleton"
BlueprintName = "Singleton"
ReferencedContainer = "container:Singleton.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Singleton.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>667A1AA419F6A7B200060D1B</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
10 changes: 5 additions & 5 deletions Chapter 06/Singleton/Singleton/BackupServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ class DataItem {

final class BackupServer {
let name:String;
private var data = [DataItem]();
private let arrayQ = dispatch_queue_create("arrayQ", DISPATCH_QUEUE_SERIAL);
fileprivate var data = [DataItem]();
fileprivate let arrayQ = DispatchQueue(label: "arrayQ", attributes: []);

private init(name:String) {
fileprivate init(name:String) {
self.name = name;
globalLogger.log("Created new server \(name)");
}

func backup(item:DataItem) {
dispatch_sync(arrayQ, {() in
func backup(_ item:DataItem) {
arrayQ.sync(execute: {() in
self.data.append(item);
globalLogger.log(
"\(self.name) backed up item of type \(item.type.rawValue)");
Expand Down
12 changes: 6 additions & 6 deletions Chapter 06/Singleton/Singleton/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import Foundation;
let globalLogger = Logger();

final class Logger {
private var data = [String]()
private let arrayQ = dispatch_queue_create("arrayQ", DISPATCH_QUEUE_SERIAL);
fileprivate var data = [String]()
fileprivate let arrayQ = DispatchQueue(label: "arrayQ", attributes: []);

private init() {
fileprivate init() {
// do nothing - required to stop instances being
// created by code in other files
}

func log(msg:String) {
dispatch_sync(arrayQ, {() in
func log(_ msg:String) {
arrayQ.sync(execute: {() in
self.data.append(msg);
});
}

func printLog() {
for msg in data {
println("Log: \(msg)");
print("Log: \(msg)");
}
}
}
10 changes: 5 additions & 5 deletions Chapter 06/Singleton/Singleton/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import Foundation

var server = BackupServer.server;

let queue = dispatch_queue_create("workQueue", DISPATCH_QUEUE_CONCURRENT);
let group = dispatch_group_create();
let queue = DispatchQueue(label: "workQueue", attributes: DispatchQueue.Attributes.concurrent);
let group = DispatchGroup();

for count in 0 ..< 100 {
dispatch_group_async(group, queue, {() in
queue.async(group: group, execute: {() in
BackupServer.server.backup(DataItem(type: DataItem.ItemType.Email,
data: "bob@example.com"))
});
}

dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
group.wait(timeout: DispatchTime.distantFuture);

println("\(server.getData().count) items were backed up");
print("\(server.getData().count) items were backed up");
6 changes: 6 additions & 0 deletions Chapter 06/SportsStore/SportsStore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,11 @@
TargetAttributes = {
6636F77419F65D24002DE278 = {
CreatedOnToolsVersion = 6.1;
LastSwiftMigration = 0820;
};
6636F78919F65D24002DE278 = {
CreatedOnToolsVersion = 6.1;
LastSwiftMigration = 0820;
TestTargetID = 6636F77419F65D24002DE278;
};
};
Expand Down Expand Up @@ -353,6 +355,7 @@
INFOPLIST_FILE = SportsStore/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -363,6 +366,7 @@
INFOPLIST_FILE = SportsStore/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -381,6 +385,7 @@
INFOPLIST_FILE = SportsStoreTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SportsStore.app/SportsStore";
};
name = Debug;
Expand All @@ -396,6 +401,7 @@
INFOPLIST_FILE = SportsStoreTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SportsStore.app/SportsStore";
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6636F77419F65D24002DE278"
BuildableName = "SportsStore.app"
BlueprintName = "SportsStore"
ReferencedContainer = "container:SportsStore.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6636F78919F65D24002DE278"
BuildableName = "SportsStoreTests.xctest"
BlueprintName = "SportsStoreTests"
ReferencedContainer = "container:SportsStore.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6636F77419F65D24002DE278"
BuildableName = "SportsStore.app"
BlueprintName = "SportsStore"
ReferencedContainer = "container:SportsStore.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6636F77419F65D24002DE278"
BuildableName = "SportsStore.app"
BlueprintName = "SportsStore"
ReferencedContainer = "container:SportsStore.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "6636F77419F65D24002DE278"
BuildableName = "SportsStore.app"
BlueprintName = "SportsStore"
ReferencedContainer = "container:SportsStore.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>SportsStore.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>6636F77419F65D24002DE278</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>6636F78919F65D24002DE278</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
Loading