This is a bit scary for all beginners. You made your pretty view in Interface Builder, attached UIViewController and trying to:
let vc = new MyNewController() self.present(vc, animated: true, completion: nil)
This is a bit scary for all beginners. You made your pretty view in Interface Builder, attached UIViewController and trying to:
let vc = new MyNewController() self.present(vc, animated: true, completion: nil)
If you already upgraded XCode to newest 10.3 version, you may notice that opening XIBs created in older versions causes “Internal error” and UI elements are not visible. But there is simple solution for that. Continue reading
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
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
Yeah, I know it’s been a while. Will try to get back with some new interesting stuff this month.
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:
let decoder = JSONDecoder(); let myData = try! decoder.decode(MyModel.self, from: data!)
Check out provided playground here!
Output in console should be:
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")
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.
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.
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:
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.