Skip to content

Commit 3533273

Browse files
committed
Add macOS support
Most of the code can be shared, except for the `UIKit` imports, which I conditionally replaced by `Cocoa` imports on macOS. Image handling is slightly different, as the `UI*` classes are not available on macOS. Due to the initializer of `NSImageView` not accepting an optional `NSImage` I refrained from adding a convenient initializer accepting a `QRCode`, where it is unclear if an image could be constructed.
1 parent 1b8111d commit 3533273

15 files changed

Lines changed: 1675 additions & 34 deletions

File tree

Example_macOS/AppDelegate.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// AppDelegate.swift
3+
// Example_macOS
4+
//
5+
// Created by Maximilian Blochberger on 2017-08-09.
6+
// Copyright © 2017 Alexander Schuch. All rights reserved.
7+
//
8+
9+
import Cocoa
10+
11+
@NSApplicationMain
12+
class AppDelegate: NSObject, NSApplicationDelegate {
13+
14+
func applicationDidFinishLaunching(_ aNotification: Notification) {
15+
// Insert code here to initialize your application
16+
}
17+
18+
func applicationWillTerminate(_ aNotification: Notification) {
19+
// Insert code here to tear down your application
20+
}
21+
22+
}
23+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "mac",
5+
"size" : "16x16",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "mac",
10+
"size" : "16x16",
11+
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "mac",
15+
"size" : "32x32",
16+
"scale" : "1x"
17+
},
18+
{
19+
"idiom" : "mac",
20+
"size" : "32x32",
21+
"scale" : "2x"
22+
},
23+
{
24+
"idiom" : "mac",
25+
"size" : "128x128",
26+
"scale" : "1x"
27+
},
28+
{
29+
"idiom" : "mac",
30+
"size" : "128x128",
31+
"scale" : "2x"
32+
},
33+
{
34+
"idiom" : "mac",
35+
"size" : "256x256",
36+
"scale" : "1x"
37+
},
38+
{
39+
"idiom" : "mac",
40+
"size" : "256x256",
41+
"scale" : "2x"
42+
},
43+
{
44+
"idiom" : "mac",
45+
"size" : "512x512",
46+
"scale" : "1x"
47+
},
48+
{
49+
"idiom" : "mac",
50+
"size" : "512x512",
51+
"scale" : "2x"
52+
}
53+
],
54+
"info" : {
55+
"version" : 1,
56+
"author" : "xcode"
57+
}
58+
}

Example_macOS/Base.lproj/Main.storyboard

Lines changed: 737 additions & 0 deletions
Large diffs are not rendered by default.

Example_macOS/Info.plist

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIconFile</key>
10+
<string></string>
11+
<key>CFBundleIdentifier</key>
12+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>$(PRODUCT_NAME)</string>
17+
<key>CFBundlePackageType</key>
18+
<string>APPL</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleVersion</key>
22+
<string>1</string>
23+
<key>LSMinimumSystemVersion</key>
24+
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
25+
<key>NSHumanReadableCopyright</key>
26+
<string>Copyright © 2017 Alexander Schuch. All rights reserved.</string>
27+
<key>NSMainStoryboardFile</key>
28+
<string>Main</string>
29+
<key>NSPrincipalClass</key>
30+
<string>NSApplication</string>
31+
</dict>
32+
</plist>

Example_macOS/ViewController.swift

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//
2+
// ViewController.swift
3+
// Example_macOS
4+
//
5+
// Created by Maximilian Blochberger on 2017-08-09.
6+
// Copyright © 2017 Alexander Schuch. All rights reserved.
7+
//
8+
9+
import Cocoa
10+
import QRCode
11+
12+
class ViewController: NSViewController {
13+
14+
@IBOutlet weak var imageViewSmall1: NSImageView!
15+
@IBOutlet weak var imageViewSmall2: NSImageView!
16+
@IBOutlet weak var imageViewSmall3: NSImageView!
17+
@IBOutlet weak var imageViewSmall4: NSImageView!
18+
@IBOutlet weak var imageViewMedium: NSImageView!
19+
@IBOutlet weak var imageViewLarge: NSImageView!
20+
21+
override func viewDidLoad() {
22+
super.viewDidLoad()
23+
24+
// large
25+
// default
26+
imageViewLarge.image = {
27+
var qrCode = QRCode("http://github.com/aschuch/QRCode")!
28+
qrCode.size = self.imageViewLarge.bounds.size
29+
qrCode.errorCorrection = .High
30+
return qrCode.image
31+
}()
32+
33+
// medium
34+
// purple
35+
imageViewMedium.image = {
36+
var qrCode = QRCode("http://schuch.me")!
37+
qrCode.size = self.imageViewMedium.bounds.size
38+
qrCode.color = CIColor(rgba: "8e44ad")
39+
return qrCode.image
40+
}()
41+
42+
// small
43+
// red (inverted)
44+
imageViewSmall1.image = {
45+
var qrCode = QRCode("http://objc.at")!
46+
qrCode.size = self.imageViewSmall1.bounds.size
47+
qrCode.color = CIColor(rgba: "fff")
48+
qrCode.backgroundColor = CIColor(rgba: "e74c3c")
49+
return qrCode.image
50+
}()
51+
52+
// small
53+
// green
54+
imageViewSmall2.image = {
55+
var qrCode = QRCode("http://apple.com")!
56+
qrCode.size = self.imageViewSmall1.bounds.size
57+
qrCode.color = CIColor(rgba: "16a085")
58+
qrCode.backgroundColor = CIColor(rgba: "000")
59+
return qrCode.image
60+
}()
61+
62+
// small
63+
// orange
64+
imageViewSmall3.image = {
65+
var qrCode = QRCode("http://example.com")!
66+
qrCode.size = self.imageViewSmall1.bounds.size
67+
qrCode.color = CIColor(rgba: "c0392b")
68+
qrCode.backgroundColor = CIColor(rgba: "f1c40f")
69+
return qrCode.image
70+
}()
71+
72+
// small
73+
// blue
74+
imageViewSmall4.image = {
75+
var qrCode = QRCode("http://example.com")!
76+
qrCode.size = self.imageViewSmall1.bounds.size
77+
qrCode.color = CIColor(rgba: "2980b9")
78+
return qrCode.image
79+
}()
80+
}
81+
82+
}
83+

0 commit comments

Comments
 (0)