Literal
convenient initializers for CGPoint and etc..
Install / Use
/learn @leavez/LiteralREADME
Literal
Literal is a swift libiary to provide convenient initializers for CGPoint, CGRect, NSRange and etc..
let p: CGPoint = [0, 1]
view.frame = [10, 20, 100, 100]
mutableString.deleteCharacters(in: [0, 2])
In Swift, a literal could be used anywhere an instance of an ExpressibleByXXXLiteral type is expected. For example, let numbers: Set = [0, 1, 2] is compilable as Set is comform to ExpressibleByArrayLiteral.
This feature come with the first version of swift. A library called Literally is created at that time to demonstration this feature. However, the release of Swift 1.1 break this feature as it cannot be used on extension of object types. Fortunately, it could still be used on struct types and many of swift types have already implement this feature natively.
This lib implements ExpressibleByArrayLiteral protocol on some very commonly used types. With this a CGRect value could be initialized with an array of 4 numbers.
Support Types
ExpressibleByArrayLiteral
CGPointCGSizeCGRectCGVectorNSRangeUIEdgeInsets
NOTE: This break the complie safety. If you pass an array of 2 number to an CGRect variable, it won't produce an complie error. You may get an assert at runtime and a default value 0 is used in the release version. When the count of array is greater than needed, values in the front is used.
ExpressibleByStringLiteral
CharacterSet
These types support ExpressibleByArrayLiteral natively: IndexPath, NSSet, Set, NSOrderedSet, NSCountedSet, CharacterSet ...
Installation
Literal only have one source file. You could use it directly in your project as convenience.
or use Cocoapods:
pod "Literal"
or Swift Package Manager:
import PackageDescription
let package = Package(
name: "MyAwesomeApp",
dependencies: [
.Package(url: "https://github.com/leavez/Literal.git", "1.0"),
]
)
License
Literal is available under the MIT license.
Related Skills
node-connect
347.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
