convenience init(by name: ee) {
self.init(name: ee, bundle: nil)
}
final class UserInfoManager {
private init() {}
static let shared = UserInfoManager()
}
import UIKit
import RealmSwift
class UserLoginInfoModel: Object {
dynamic var cardNum: String!
dynamic var companyId: String!
dynamic var companyName: String!
dynamic var userId: String!
override static func primaryKey() -> String? {
return "userId"
}
}
参考链接 http://www.cocoachina.com/ios/20161205/18282.html
import Foundation
import UIKit
extension UIResponder {
func handOutAction(by identifier: String, sender: Any!) {
if !responderRouterActionChain(by: identifier, sender: sender) {
guard let nextResponder = next else { return }
nextResponder.handOutAction(by: identifier, sender: sender)
}
}
internal func responderRouterActionChain(by identifier: String, sender: Any!) -> Bool {
return false
}
}
Demo地址:https://github.com/NirvanAcN/2017DayDayUp (Day2)
参考链接 https://realm.io/docs/swift/latest/#other-realms
在工程中可能需要拖入一些.realm文件来读取一些配置或者静态数据。这时候使用如下代码是无法读取Test.realm文件的(模拟器可以读取)
guard let fileURL = Bundle.main.url(forResource: "Test", withExtension: "realm") else {
return
}
let realm = try! Realm.init(fileURL: fileURL)
按照官网说明,只需要如下修改一下配置Configuration
guard let fileURL = Bundle.main.url(forResource: "Test", withExtension: ".realm") else {
return
}
let config = Realm.Configuration(fileURL: fileURL, readOnly: true)
let realm = try! Realm(configuration: config)
参考链接 http://www.jianshu.com/p/3705caee6995
let window = UIApplication.shared.keyWindow
View - Assistant Editor - Show Assistant Editor
快捷键组合 option + command + ↵
参考链接 http://blog.csdn.net/flyback/article/details/48268829
let Acode = UnicodeScalar("A")!.value //65
let Zcode = UnicodeScalar("Z")!.value //90
let array = (Acode...Zcode).map { String(format: "%c", $0) }
借助optional
protocol TestDelegate: NSObjectProtocol {
func testFunction()
}
.
.
.
weak var delegate: TestDelegate!
delegate?.testFunction()
参考链接 http://www.jianshu.com/p/7eb016e4ceb1
获取.allTouchEvents事件,将isHighlighted置否
btn.addTarget(self, action: #selector(onBtnsAllAction), for: .allTouchEvents)
.
.
.
@objc private func onBtnsAllAction(_ sender: UIButton) {
sender.isHighlighted = false
}
print(#line)
Bool (作为Object属性必须有默认值)
Int8
Int16
Int32
Int64
Double
Float
String (不能保存超过 16 MB 大小的数据,optional)
Date (精度到秒)
Data (不能保存超过 16 MB 大小的数据)
@IBDesignable
@IBInspectable
如图所示效果
Demo地址:https://github.com/NirvanAcN/2017DayDayUp (Day1)
let calendar = Calendar.init(identifier: .chinese)
let date = Date()
let localeComp = calendar.dateComponents([.year, .month, .day], from: date)
print(localeComp.year)
print(localeComp.month)
print(localeComp.day)
UIGraphicsBeginImageContext(someView.bounds.size)
someView.layer.render(in: UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
实现modelContainerPropertyGenericClass方法
class OrderModel: NSObject, YYModel {
var goods: [OrderGoodsModel]!
static func modelContainerPropertyGenericClass() -> [String : Any]? {
return [
"ddxq": OrderGoodsModel.self
]
}
}
class OrderGoodsModel: NSObject, YYModel {
}
修改完毕后需要在application(_:didFinishLaunchingWithOptions:)方法中对数据库的版本进行重新设置(默认schemaVersion为0,修改后的schemaVersion应大于原值):
Realm.Configuration.defaultConfiguration = Realm.Configuration(
schemaVersion: 0
)
StoreKit
参考链接:http://www.cocoachina.com/ios/20150928/13598.html
例如,允许来自 http://www.baidu.com 的相关链接进行http访问
NSAppTransportSecurity
NSExceptionDomains
www.baidu.com
NSExceptionAllowsInsecureHTTPLoads
__FILE__ -> #file
__LINE__ -> #line
__COLUMN__ -> #column
__FUNCTION__ -> #function
__DSO_HANDLE__ -> #dsohandle
参考链接:http://www.jianshu.com/p/25e9c1a864be
修改plist文件
UIStatusBarStyle
UIStatusBarStyleLightContent
UIViewControllerBasedStatusBarAppearance
错误截图
参考链接 http://stackoverflow.com/a/42067502/7760667
解决方案:重置模拟器
Simulator —— Reset content and Setting...
Scheme — Run — Diagnostics - Runtime Sanitization - Address Sanitizer
参考链接 https://guides.cocoapods.org/making/making-a-cocoapod.html#testing
You can test the syntax of your Podfile by linting the pod against the files of its directory, this won't test the downloading aspect of linting.
$ cd ~/code/Pods/NAME$ pod lib lint
Before releasing your new Pod to the world its best to test that you can install your pod successfully into an Xcode project. You can do this in a couple of ways:
Push your podspec to your repository, then create a new Xcode project with a Podfile and add your pod to the file like so:
pod 'NAME', :git => 'https://example.com/URL/to/repo/NAME.git'
Then run
pod install-- or --pod update
pod setup
rm ~/Library/Caches/CocoaPods/search_index.json
git tag -d 0.0.1
git push origin :refs/tags/0.0.1
参考链接 http://www.mincoder.com/article/3650.shtml
func testShowMe() {
/// Creates and returns an expectation associated with the test case.
let exp = expectation(description: "my_tests_identifying")
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 2) {
/// that vended the expectation has already completed.
exp.fulfill()
}
/// are fulfilled or the timeout is reached. Clients should not manipulate the run
waitForExpectations(timeout: 3, handler: nil)
}
参考链接 http://www.jianshu.com/p/6a7af360bf2a
let group = DispatchGroup()
let timeLine = DispatchTime.now()
(0..<10).forEach({ (idx) in
group.enter()
DispatchQueue.main.asyncAfter(deadline: timeLine + TimeInterval(idx), execute: {
group.leave()
})
})
group.notify(queue: DispatchQueue.main) {
/// finished
}
hidesBarsOnSwipe = true
参考链接 http://www.jianshu.com/p/b2585c37e14b
navigationBar.subviews[0].alpha = 0
参考链接 http://blog.csdn.net/ayuapp/article/details/54631592
// 1. 暴露Framework的Class文件
// 2. 使用public /*not inherited*/ init(for aClass: Swift.AnyClass)加载
let bundle = Bundle.init(for: JRConfigurations.self)
在AVCaptureSession执行startRunning()函数后,AVCaptureVideoPreviewLayer通过metadataOutputRectOfInterest方法转换即可得到转换后的坐标。
$ git config --global user.name "username"
$ git config --global user.email "email"
$ git rm -r --cached .
$ git add .
$ git commit -m 'update .gitignore'
extension Optional where Wrapped == String {
var isBlank: Bool {
return self?.isBlank ?? true
}
}
let des = NSMutableAttributedString.init(string: "hello world")
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 6
des.addAttributes([NSParagraphStyleAttributeName: paragraphStyle], range: NSRange.init(location: 0, length: des.length))
label.attributedText = des
附:NSMutableParagraphStyle其他属性
行间距
CGFloat lineSpacing
段间距
CGFloat paragraphSpacing
对齐方式
NSTextAlignment alignment
首行缩进
CGFloat firstLineHeadIndent
除首行之外其他行缩进
CGFloat headIndent
每行容纳字符的宽度
CGFloat tailIndent
换行方式
lineBreakMode
最小行高
CGFloat minimumLineHeight
最大行高
CGFloat maximumLineHeight
let age = 27
print(20...30 ~= age) /// true
let score = [100, 99, 80, 66, 40]
let filter = score.filter {
return 90...100 ~= $0
}
print(filter) /// [100, 99]
direction:
ASStackLayoutDirectionVertical
ASStackLayoutDirectionHorizontal
justifyContent:
ASStackLayoutJustifyContentStart
ASStackLayoutJustifyContentEnd
ASStackLayoutJustifyContentCenter
ASStackLayoutJustifyContentSpaceBetween
ASStackLayoutJustifyContentSpacAeround
alignItems:
ASStackLayoutAlignItemsStart
ASStackLayoutAlignItemsEnd
ASStackLayoutAlignItemsCenter
ASStackLayoutAlignItemsBaselineFirst
ASStackLayoutAlignItemsBaselineLast
ASStackLayoutAlignItemsStretch
ASInsetLayoutSpec
ASOverlayLayoutSpec
ASBackgroundLayoutSpec
ASCenterLayoutSpec
ASRatioLayoutSpec
ASStackLayoutSpec
ASAbsoluteLayoutSpec
ASRelativeLayoutSpec
ASWrapperLayoutSpec
foo.registerSupplementaryNode(ofKind: UICollectionElementKindSectionFooter)
func collectionNode(_ collectionNode: ASCollectionNode, nodeForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> ASCellNode {
return ASCellNode()
}
func collectionNode(_ collectionNode: ASCollectionNode, sizeRangeForFooterInSection section: Int) -> ASSizeRange {
return ASSizeRange()
}
searchController.hidesNavigationBarDuringPresentation = false
if #available(iOS 11.0, *) {
view.contentInsetAdjustmentBehavior = .never
} else {
automaticallyAdjustsScrollViewInsets = false
}
nodeB.style.spaceBefore = 15
$ ssh-keygen
$ cat ~/.ssh/id_rsa.pub
作者:ChiOS
链接:https://www.jianshu.com/p/4f7fd99ff95c/
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。