Posts

Showing posts with the label Swift

Swift: Giving Context To Cgcontext (Part I)

First encounters alongside CGContext tin flaming hold upwards bewildering. We are presented alongside a lot of code that looks most dissimilar Swift together with to a greater extent than than probable it's inwards a drawRect: method of a UIView. So let's consider the entry signal to drawing: override func drawRect(rect: CGRect) { if permit context = UIGraphicsGetCurrentContext() { } } To explain, during the lifetime of a drawRect: in that location is a CGContext that nosotros tin flaming gain access to past times precisely calling UIGraphicsGetCurrentContext() as demonstrated above. Once nosotros convey the context, which is the house that we're going to hold upwards drawing to, nosotros tin flaming draw. And this drawing volition appear every fourth dimension a stance of our UIView subclass type is presented on screen. Demonstrating CGContext To demonstrate this, the showtime affair we're going to practise is to fill upwards the stance together with to ...

Swift: Array In Addition To Arrayslice (Xcode 7.3, Swift 2.2; Updated Xcode Eight Beta 6, Swift 3)

** Jump to Swift iii code ** Before nosotros begin Influenza A virus subtype H5N1 swell debt inwards writing this postal service is owed to a presentation yesteryear AirspeedVelocity at a Swift London lawsuit held inwards the Facebook offices inwards 2015. There he went into the depths of how arrays as well as other types are stored as well as copied inwards memory. Here I'm looking at a far to a greater extent than basic marker aimed at the practical implications of Array as well as ArraySlice when coding. Array Let's consider a humble array of type Array<Int>: var array = [1,2,3,4,5,6,7,8,9,10] If nosotros desire to yell upwards the foremost exceptional inwards the array nosotros tin produce the following: let firstItem = array.first Or nosotros tin subscript the array similar so: let firstItem = array[0] In both instances nosotros yell upwards an Int value. Slicing Now let's suppose nosotros possess got a hit from the master copy array to create ...

Swift: Sorting Togetherness Alongside Zip2sequence Together With Stable Kind Out (Xcode 7.2; Updated Swift 3, Xcode 8)

Let's human face upwardly it, of all the types inwards Swift, Zip2Sequence receives real piffling press. This doesn't hateful its role inwards the development of Swift has been forgotten at Apple. It merely way that by as well as large its role is  fulfilled using other approaches ( or mayhap beingness at the terminate of the alphabet us bloggers merely haven't addressed its purpose yet). The basics As the refer suggests, a Zip2Sequence is created past times zipping together 2 sequences. let firstArray = [1,2,3,4,5,6,7,8,9,10] allow secondArray = ["A","B","C","D","E","F","G","H","I","J"] // outset way of instantiating allow zipped1 = Zip2Sequence(firstArray,secondArray) // 2nd way of instantiating allow zipped2 = zip(firstArray, secondArray) Note: The 2 sequences save their master copy types, the expose of zipped together pairs is equally long equally the shortest of...

Swift: Uibezierpath For Inscribed In Addition To Circumscribed Circles (Xcode 7.2.1)

Image
UIBezierPath has an inbuilt initialiser that returns an oval inward a rect together with of course of teaching nosotros tin move this to line circles yesteryear passing a square. However, assume yous convey a rectangular icon together with yous desire to mask it alongside a circle. For this you'll demand the inscribed circle non an oval. The minute scenario I desire to imagine is a circumscribed circle exterior the rect for where nosotros want, for example, text to period of time around a foursquare icon inward a UITextView. In gild to address this I started to intend virtually how nosotros line around an icon square. H5N1 foursquare text period of time is elementary to orbit alongside a rect larger than that of the image. Circular together with oval wraps pose a bigger problem: But alongside a piffling assistance from the Internet inward finding the correct equations all these things tin endure achieved: extension CGFloat { func radians() -> CGFloat { allow b =...

Review: Gist Icon For Swift: Advanced Icon Processing For Ios Yesteryear Simon J Gladman

Image
Who is the bulk for? Core Image for Swift: Advanced Image Processing for iOS  is for those iOS in addition to OS X programmers who cause got exclusively actually used Core Image out of necessity for when UIImage was non capable of providing a solution in addition to right away wishing to acquire further. It is also for those who are already acquainted alongside Core Image in addition to wishing to delve deep into the frameworks of Core Image in addition to Metal. At every phase in addition to score of complexity the author, Simon Gladman, is in that place to guide us in addition to never exercise nosotros experience lone or laid adrift inwards this book. First impressions The start matter I noticed nearly this bulk was its purpose of the Apple textbook format. This gives it a clear in addition to concise feel. It is extremely visual, providing examples of the Core Image filters nether give-and-take (in static in addition to animated form) in addition to also clear code e...

Bytes For Beginners: Cook Your Ain Conversions From Int Together With Double To Binary (And Other Pose Out Bases) Inwards Swift (Update: Xcode 8, Beta 6; Swift 3)

Why convert a decimal to a binary yourself when Swift tin create it for you? String(500, radix:2) Well it helps inwards learning: extension Int { func binary() -> String { var num = self var str = "" repeat { str = String(num%2) + str num = num/2 } piece num > 0 supply str } } 500.binary() And every bit you lot tin run into the procedure of going from base of operations 10 to base of operations two is a straightforward exercise. We just keep  dividing past times the base of operations give away in addition to adding the remainder  to the commencement of our string. In fact going from base of operations 10 to whatever base of operations from two through to ix is straightforward, because nosotros tin create just the same matter for those give away bases too. extension Int { func toBase(b:Int) -> String { guard b > 1 && b < xi else { fatalEr...

Verifying For Unhappily Always After: How To Skip Verification On Xcode Eight Beta 6

Quite a few people convey works life that verification of Xcode viii beta half dozen is around endless as well as may good endure endless because nosotros never genuinely driblet dead to the halt earlier aborting. It turns out a solution was posted to stackoverflow to solve this issue: Open Terminal Enter the next command: xattr -d com.apple.quarantine /Applications/Xcode-beta.app Double tap the app equally green to open as well as I tin sack confirm that it worked for me. It's non something that Apple recommends because it skips verification only for those of us who desire to driblet dead Xcode viii beta half dozen upwards as well as running it sure enough helps.  Alternatively you lot tin sack follow Apple's advice as well as file a põrnikas report, as well as thus wait, the alternative is yours. Follow @sketchytech

Taming Nsdocument Too Agreement Who's Boss: Creating A Unproblematic Macos Text Editor (Swift 3, Xcode Viii Beta 6)

Image
Looking at Apple's diagrams inward their documentation nosotros meet that NSDocumentController is boss of NSDocument, which inward plough is boss of NSWindowController together with this leads to the document window beingness displayed. Yup, but what is actually happening together with what does this hateful inward price of code? Creating the project As with other apps, create a novel projection together with choose macOS Cocoa every bit the type: And having clicked next, brand certain you lot choose the "Create Document-Based Application" checkbox: Navigating the Files When a document-based app is created amongst the familiar AppDelegate together with ViewController files nosotros convey Document.swift every bit well. This concluding shape file providing a subclass of NSDocument. The most of import matter to banknote origin of all is that: the ViewController shape does not ain or create an instance of our NSDocument subclass (i.e. Document) the...

Apple Tidings Format Api Inwards Swift: Exceed Channel, Department In Addition To Article Information (Swift 4)

Image
You tin role the online tool to exercise your ain Apple News posts through iCloud.com, no problem. You tin also expect to  Apple's python scripts equally a way to upload, download too delete articles. If it's a Swift equivalent you lot want, therefore you'll demand to curlicue your own. And that's what I start to exercise hither having covered a yoke of side notes first. Side notes most Python To role the Python scripts I needed to role easy_install to install requests on macOS. Side notes on News Preview To role the News Preview app , too start exploring the Apple News Format, you lot demand to lead keep Java 8 installed, Xcode too Xcode control occupation tools, too a channel id (although Apple does furnish a preview channel id inwards the readme file if you're non notwithstanding signed upwards to Apple News equally a content provider). Once you lot lead keep everything installed select grip of the example articles  and start learning. Python: GET Cha...

Swift As Well As Xml Episode 1: Defining Xml Using Swift

XML is a really elementary linguistic communication at heart. It contains elements , i.e. those types that are original to a tag, e.g. <paragraph> or <p>, as well as which are also used to closed tags, e.g. </paragraph> or </p>, it so has attributes , which are secondary but which are also contained inside the boundaries of the the tag, e.g. class="regular", which is contained similar so <p class="regular">. Finally nosotros convey the content , which tin survive 1 of 2 things: text or to a greater extent than or less other chemical part nested inside the first. Since everything begins inwards XML alongside the top-level element, that's what volition start alongside too: struct Element { permit name:String permit attributes:[Atrribute] permit content:[Content] var self_closing:Bool { furnish content.isEmpty } } We convey instantly the nearly of import thing, our powerfulness to practise instances of ...

Uibutton At Your Convenience

UIButton is 1 of those classes where y'all receive got to receive got quite a few steps to ready an instance if y'all require anything beyond the default. For example, I would similar to practise a circular push clitoris alongside a title, border, background colour, etc. extension UIButton { convenience init(withRadius radius:CGFloat, title:String, titleColor:UIColor, target:UIViewController, selector:Selector, backgroundColor:UIColor, borderColor:UIColor, borderWidth:CGFloat, position:CGPoint) { self.init() self.setTitle(title, for: .normal) self.setTitleColor(titleColor, for: .normal) self.addTarget(target, action: selector, for: .touchDown) self.backgroundColor = backgroundColor allow diameter = ii * radius self.frame = CGRect(x: position.x, y: position.y, width: diameter, height: diameter) self.layer.cornerRadius = radius self.layer.masksToBounds = imitation self.layer.borderWidth = border...