So you made brand new and shiny enum, and want to use it in f.e. picker? To achieve this you need to prepare array of strings which every picker can use. How to do it? Continue reading
Using Swift with Objective-C in framework project
I’m pretty sure there are lot of tutorials about mixing ObjectiveC with Swift in both ways. But most of them are covering only normal projects. If you have framework in which you need to mix both languages, you cannot create simple bridging header because you will hit “using bridging headers with framework targets is unsupported” error. What to do then?Continue reading
No updates
Yeah, I know it’s been a while. Will try to get back with some new interesting stuff this month.
Expected argument of type “string”, “NULL” given when using form in Symfony 4.1
Expected argument of type “string”, “NULL” given is very common question and seems to not be handled since Symfony 2
Parsing JSON with Swift 4 JSONDecoder
Probably you saw many JSON parsing examples, but this one is really easy. And available out of the box with Swift 4.
All you have to do is create models from Codable superclass, and use:
1 2 |
let decoder = JSONDecoder(); let myData = try! decoder.decode(MyModel.self, from: data!) |
Check out provided playground here!
Output in console should be:
1 2 3 4 5 6 7 |
Colors: Color(color: "black", category: "hue", type: "primary") Color(color: "white", category: "value", type: "primary") Color(color: "red", category: "hue", type: "primary") Color(color: "blue", category: "hue", type: "primary") Color(color: "yellow", category: "hue", type: "primary") Color(color: "green", category: "hue", type: "secondary") |
TLSV1_ALERT_PROTOCOL_VERSION when trying to install python packages
If executing:
python setup.py install
give you error like:
[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:645) -- Some packages may not be found!
it may be caused by outdate OpenSSL. But if after executing:
python -c "import ssl; print(ssl.OPENSSL_VERSION)"
you see something like:
OpenSSL 1.0.2n 7 Dec 2017
then your SSL is pretty good. What to do then?
1. If you are in Virtual Env mode, deactivate it
2. Remove your Virtual Env
3. Run “brew update”
4. Run “brew install openssl” just in case
5. Run “brew install python3”
Next thing is check available python versions which you can use in venv:
ls /Library/Frameworks/Python.framework/Versions/
If you will see only “3.5”, go to python.org and download newest MacOs package (currently 3.6.5) then install as usual.
After installing make you that:
ls /Library/Frameworks/Python.framework/Versions/
will show:
3.5 3.6
Now you can create new Virtual Env with forced python 3.6:
virtualenv envname --python=python3.6
Now installing packages should work.
How to enable php-intl extension for php 7.1 using XAMPP on MacOS High Sierra
This may seem trivial, but in fact about 2 months ago some clever guys made changes in brew repository, so doing just:
brew install php71-intl
will show you error with message that such recipe doesn’t exists. Also XAMPP comes without intl extension so is there any working solution which does not require full and manual php compilation?
Fortunately, there is. There is temporary fix in another brew repo, so all you have to do is:
brew tap kyslik/homebrew-php
brew install kyslik/php/php71-intl
And this works. Really. Enjoy.
How to get UIImage from OpenGL in Swift 3
As you probably notices, simple screen drawing is useless if it comes to OpenGL view. So is it possible to generate UIImage from such? Of course, lets suppose your custom drawing class extends UIView, then just add:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
func getSnapshot() -> UIImage? { let s = CGRect(x: 0.0, y: 0.0, width: self.bounds.width, height: self.bounds.height) let dataLength = Int(s.size.width * s.size.height * 4.0) let buffer: UnsafeMutableRawPointer? = malloc(dataLength) glReadPixels(0, 0, GLsizei(s.size.width), GLsizei(s.size.height), GLenum(GL_RGBA), GLenum(GL_UNSIGNED_BYTE), buffer); let pixelData: UnsafePointer = (UnsafeRawPointer(buffer)?.assumingMemoryBound(to: UInt8.self))! let cfdata: CFData = CFDataCreate(kCFAllocatorDefault, pixelData, dataLength * MemoryLayout<GLubyte>.size) let provider: CGDataProvider! = CGDataProvider(data: cfdata) let iref: CGImage? = CGImage(width: Int(s.size.width), height: Int(s.size.height), bitsPerComponent: 8, bitsPerPixel: 32, bytesPerRow: Int(s.size.width)*4, space: CGColorSpaceCreateDeviceRGB(), bitmapInfo: CGBitmapInfo.byteOrder32Big, provider: provider, decode: nil, shouldInterpolate: true, intent: CGColorRenderingIntent.defaultIntent) UIGraphicsBeginImageContext(CGSize(width: CGFloat(s.size.width), height: CGFloat(s.size.height))) let cgcontext: CGContext? = UIGraphicsGetCurrentContext() cgcontext!.setBlendMode(CGBlendMode.copy) cgcontext!.draw(iref!, in: CGRect(x: CGFloat(0.0), y: CGFloat(0.0), width: CGFloat(s.size.width), height: CGFloat(s.size.height))) let image: UIImage? = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() return image } |
This code works in XCode 9 and Swift 3.x.
OpenGL2: Very basic Swift3 example
As you guys probably notices, it was a while since last post here. I was quite busy with lot of projects, so did not had time for blogging. Continue reading
RxSwift: How to stream values with dynamic delay
Imagine such case – you have list of messages, each one with timestamp. And you want to show them in the same way they arrived, with same timings. How to achieve this with RxSwift?Continue reading