Skip to content

Commit 1289c94

Browse files
author
shangkun
committed
add AppIcon
1 parent d141007 commit 1289c94

File tree

13 files changed

+53
-32
lines changed

13 files changed

+53
-32
lines changed

SKGenerateModelTool/Assets.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,63 @@
11
{
22
"images" : [
33
{
4-
"idiom" : "mac",
54
"size" : "16x16",
5+
"idiom" : "mac",
6+
"filename" : "icon-16.png",
67
"scale" : "1x"
78
},
89
{
9-
"idiom" : "mac",
1010
"size" : "16x16",
11+
"idiom" : "mac",
12+
"filename" : "icon-16@2x.png",
1113
"scale" : "2x"
1214
},
1315
{
14-
"idiom" : "mac",
1516
"size" : "32x32",
17+
"idiom" : "mac",
18+
"filename" : "icon-32.png",
1619
"scale" : "1x"
1720
},
1821
{
19-
"idiom" : "mac",
2022
"size" : "32x32",
23+
"idiom" : "mac",
24+
"filename" : "icon-32@2x.png",
2125
"scale" : "2x"
2226
},
2327
{
24-
"idiom" : "mac",
2528
"size" : "128x128",
29+
"idiom" : "mac",
30+
"filename" : "icon-128.png",
2631
"scale" : "1x"
2732
},
2833
{
29-
"idiom" : "mac",
3034
"size" : "128x128",
35+
"idiom" : "mac",
36+
"filename" : "icon-128@2x.png",
3137
"scale" : "2x"
3238
},
3339
{
34-
"idiom" : "mac",
3540
"size" : "256x256",
41+
"idiom" : "mac",
42+
"filename" : "icon-256.png",
3643
"scale" : "1x"
3744
},
3845
{
39-
"idiom" : "mac",
4046
"size" : "256x256",
47+
"idiom" : "mac",
48+
"filename" : "icon-256@2x.png",
4149
"scale" : "2x"
4250
},
4351
{
44-
"idiom" : "mac",
4552
"size" : "512x512",
53+
"idiom" : "mac",
54+
"filename" : "icon-512.png",
4655
"scale" : "1x"
4756
},
4857
{
49-
"idiom" : "mac",
5058
"size" : "512x512",
59+
"idiom" : "mac",
60+
"filename" : "icon-512@2x.png",
5161
"scale" : "2x"
5262
}
5363
],

SKGenerateModelTool/SKCodeBuilder.swift

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class SKCodeBuilder: NSObject {
3131
lazy var yymodelPropertyGenericClassDicts = NSMutableDictionary()
3232
lazy var handlePropertyMapper = NSMutableDictionary()
3333

34-
3534
var fileTye:String {
3635
get {
3736
if config.codeType == .Swift {
@@ -381,10 +380,10 @@ class SKCodeBuilder: NSObject {
381380
}
382381
}
383382

383+
/// String
384384

385385
private func handleIdStringValue(idValue: String, key:String, hString:NSMutableString, ignoreIdValue:Bool) {
386-
/// String
387-
386+
388387
if config.codeType == .OC {
389388

390389
if key == "id" && !ignoreIdValue {
@@ -465,10 +464,8 @@ class SKCodeBuilder: NSObject {
465464
}
466465

467466
case .MJExtension:
468-
// 适配MJExtension
469-
470-
/// 1.The generic class mapper for container properties.
471467

468+
// 适配MJExtension
472469
var needLineBreak = false;
473470
if (self.yymodelPropertyGenericClassDicts.count > 0) {
474471
mString.append("+ (NSDictionary *)mj_objectClassInArray\n")
@@ -481,13 +478,10 @@ class SKCodeBuilder: NSObject {
481478
needLineBreak = true;
482479
}
483480

484-
/// 2.Custom property mapper.
485-
486481
if (self.handlePropertyMapper.count > 0) {
487482
if (needLineBreak) {
488483
mString.append("\n")
489484
}
490-
491485
mString.append("+ (NSDictionary *)mj_replacedKeyFromPropertyName\n")
492486
mString.append("{\n return @{\n")
493487
for (key, obj) in self.handlePropertyMapper {
@@ -496,7 +490,6 @@ class SKCodeBuilder: NSObject {
496490
mString.append(" };")
497491
mString.append("\n}\n")
498492
}
499-
500493
default:
501494
break
502495
}

SKGenerateModelTool/ViewController.swift

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import Cocoa
1010

11-
class ViewController: NSViewController {
11+
class ViewController: NSViewController, NSControlTextEditingDelegate {
1212

1313
@IBOutlet weak var urlTF: NSTextField!
1414
@IBOutlet weak var jsonTextView: NSTextView!
@@ -39,6 +39,7 @@ class ViewController: NSViewController {
3939
var builder = SKCodeBuilder()
4040

4141
var outputFilePath: String?
42+
var currentInputTF: NSTextField?
4243

4344
lazy var jsonTextColor = NSColor.blue
4445
lazy var codeTextColor = NSColor(red: 215/255.0, green: 0/255.0 , blue: 143/255.0, alpha: 1.0)
@@ -57,18 +58,15 @@ class ViewController: NSViewController {
5758
jsonTypeBtn.removeAllItems()
5859
jsonTypeBtn.addItems(withTitles: ["None","YYMode","MJExtension","HandyJSON"])
5960
jsonTypeBtn.selectItem(at: 0)
60-
6161
}
6262

6363
override func viewDidAppear() {
64+
super.viewDidAppear()
6465
loadUserLastInputContent()
6566
}
6667

6768
// MARK: - IBAction
68-
69-
///
70-
/// 今日热榜(微博):https://v1.alapi.cn/api/tophub/get?type=weibo
71-
///
69+
7270
/// GET request URL
7371

7472
@IBAction func requestURLBtnClicked(_ sender: NSButton) {
@@ -155,7 +153,6 @@ class ViewController: NSViewController {
155153
}
156154
}
157155

158-
159156
@IBAction func chooseOutputFilePath(_ sender: NSButton) {
160157
let openPanel = NSOpenPanel()
161158
openPanel.canChooseFiles = false
@@ -202,6 +199,31 @@ class ViewController: NSViewController {
202199
}
203200
}
204201

202+
// MARK: - NSControlTextEditingDelegate
203+
204+
func controlTextDidChange(_ obj: Notification) {
205+
if let tf = obj.object {
206+
currentInputTF = tf as? NSTextField
207+
NSObject.cancelPreviousPerformRequests(withTarget: self, selector: #selector(caculateInputContentWidth), object: nil)
208+
self.perform(#selector(caculateInputContentWidth))
209+
}
210+
}
211+
212+
@objc private func caculateInputContentWidth() {
213+
if let tf = currentInputTF {
214+
let constraints = tf.constraints
215+
let attributes = [NSAttributedString.Key.font : tf.font]
216+
let string = NSString(string: tf.stringValue)
217+
var strWidth = string.boundingRect(with: NSSizeFromCGSize(CGSize(width: Double(Float.greatestFiniteMagnitude), height: 22.0)), options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: attributes as [NSAttributedString.Key : Any]).width + 10
218+
strWidth = max(strWidth, 114)
219+
constraints.forEach { (constraint) in
220+
if constraint.firstAttribute == .width {
221+
constraint.constant = strWidth
222+
}
223+
}
224+
}
225+
}
226+
205227
/// load cache
206228

207229
private func loadUserLastInputContent() {
@@ -234,7 +256,7 @@ class ViewController: NSViewController {
234256
generateFileBtn.state = UserDefaults.standard.bool(forKey: SupportJSONModelTypeCacheKey) ? .on : .off
235257
}
236258

237-
/// MARK: save cache
259+
/// save cache
238260

239261
private func saveUserInputContent() {
240262

@@ -272,13 +294,9 @@ class ViewController: NSViewController {
272294
UserDefaults.standard.set(generateFileBtn.state == .on , forKey: ShouldGenerateFileCacheKey)
273295
}
274296

275-
276-
277297
override var representedObject: Any? {
278298
didSet {
279299
}
280300
}
281-
282-
283301
}
284302

0 commit comments

Comments
 (0)