This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 随机红包(仅带最小金额) | |
/// | |
/// - Parameters: | |
/// - amount: 总额(分) | |
/// - slice: 分成几份,至少一份 | |
/// - minimun: 每个红包的最小金额(分),默认1分(这和微信目前业务场景是一致的) | |
func redPacket(ammount: Int, slice: Int = 1, minimum: Int = 1) throws -> [Int] { | |
guard minimum > 0, slice > 0, ammount >= minimum * slice else { | |
throw NSError(domain: "com.tencent.wechat.redpacket", code: -1, userInfo: [NSLocalizedDescriptionKey: "无法按要求分配红包"]) | |
return [ammount] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Cause of 'unrecognized selector' crash | |
// 1. 内存问题,该对象已释放,垃圾内存区域被某个新的对象取代,而该新的对象很可能不认识这个selector | |
// 2. 头文件加到工程里了,但对应的.m文件未加入到工程设置的“compile sources”里————这个很诡异,Xcode并不会报错,只会运行时崩溃。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - Optional Unwrap 并转化为字符串 | |
extension String { | |
enum UnwrapType { | |
case describing | |
case reflecting | |
} | |
/// 将任意的Optional类型转化为String,并不会用Optional(abc)这样的包裹形式 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let TransformInt64 = TransformOf<Int64, String>(fromJSON: { (value: String?) -> Int64? in | |
guard let v = value else { | |
return nil | |
} | |
return Int64(value!) | |
}, toJSON: { (value: Int64?) -> String? in | |
return String(value ?? 0) | |
}) | |
let TransformUInt64 = TransformOf<UInt64, String>(fromJSON: { (value: String?) -> UInt64? in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ls -l /private/var/folders/92/v28csfjn6rzdvvg60nhyblb40000gn/C/ | |
total 3424 | |
drwx------@ 2 donald staff 68B Feb 7 2017 32HNEEH56A.com.outercorner.osx.Secrets.Helper | |
drwx------@ 3 donald staff 102B Feb 27 2017 AnZhg.ChineseCalendar | |
drwx------@ 2 donald staff 68B Feb 8 2017 AnZhg.ChineseCalendarHelper | |
drwx------ 3 donald staff 102B Sep 25 2016 AppIconMaker | |
drwx------ 2 donald staff 68B Nov 2 13:49 AudioComponentRegistrar | |
drwx------ 2 donald staff 68B Dec 22 2014 ComputeCache | |
drwx------@ 5 donald staff 170B Sep 20 2016 FN2V63AD2J.com.tencent.ScreenCapture2 | |
drwx------@ 3 donald staff 102B Sep 25 2016 FN2V63AD2J.com.tencent.localserver2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
textView.attributedText = originalContent | |
let lineLimit = 5 | |
textView.isEditable = true | |
textView.isScrollEnabled = false | |
// eliminate inner paddings, when right is minus number, it seems useless. | |
// textView.contentInset = UIEdgeInsets(top: 0, left: -5, bottom: 0, right: 0) | |
textView.textContainer.lineFragmentPadding = 0; // better way | |
textView.textContainerInset = .zero // default is (8, 0, 8, 0) | |
textView.textContainer.maximumNumberOfLines = lineLimit // Important condition |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 在 app.registerUserNotificationSettings(UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil)) 之后收到用户“接受”或“拒绝”及“默拒”后,此委托方法被调用 | |
func application(_ app: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) { | |
// 1. 征询“推送许可”时,用户把app切到后台————默拒了推送 | |
// 2. 在系统设置里打开推送,但关掉所有形式的提醒,等价于拒绝推送(得不到token,也收不到推送) | |
// 3. 关掉 badge, alert 和 sound 时,notificationSettings.types.rawValue == 0 && app.isRegisteredForRemoteNotifications 成立,但能得到token,也能收到推送(锁屏和通知中心也能看到推送)————说明types涵盖并不全面 | |
print(app.isRegisteredForRemoteNotifications, notificationSettings.types) // 对于模拟器来说,由于不能接收推送,所以 isRegisteredForRemoteNotifications 始终为 false | |
if !app.isRegisteredForRemoteNotifications && notificationSettings.types.rawValue == 0 { | |
BKPushSDKManager.onRefuseRemoteNotification() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 一些设备通用消息 // | |
struct DeviceInfo { | |
//获取设备名称 例如:elan的手机 | |
static let deviceName = UIDevice.current.name | |
//获取系统版本 例如:10.3 | |
static let sysVersion = UIDevice.current.systemVersion |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. 多行文本 | |
let label = UILabel() | |
label.font = Font.f14 | |
label.numberOfLines = 2 // 若此处的行数限定为0(即可无数行),则以下面的 limitedToNumberOfLines 为准;否则两个行数中较小的那个会生效 | |
label.text = model.svideoInfo.svideoTitle // 多行文本 | |
let titleRect = label.textRect(forBounds: CGRect(origin: .zero, size: CGSize(width: cellWidth - margins.xInset, height: CGFloat.greatestFiniteMagnitude)), limitedToNumberOfLines: 0) | |
// 事实上,用sizeThatFits(_:)就好了。 |