Using and Extending the Xcode Source Editor

Similar documents
What s New in Xcode App Signing

Data Delivery with Drag and Drop

Extending Your Apps with SiriKit

Getting the Most Out of HealthKit

Monetize and Promote Your App with iad

Modern User Interaction on ios

Using Grouped Notifications

Enhancing your apps for the next dimension of touch

What s New in imessage Apps

Seamless Linking to Your App

Introduction to Siri Shortcuts

What s New in MapKit. App Frameworks #WWDC17. Fredrik Olsson

Advanced Debugging and the Address Sanitizer

What s New in watchos

What s New in tvos 12

Mastering Drag and Drop

What s New in HomeKit

Quick Interaction Techniques for watchos

Implementing UI Designs in Interface Builder

Introducing the Photos Frameworks

Mastering UIKit on tvos

Introducing Password AutoFill for Apps

What s New in Testing

Introducing the Modern WebKit API

imessage Apps and Stickers, Part 2

Advanced Notifications

Thread Sanitizer and Static Analysis

Engineering for Testability

What s New in ARKit 2

Building for Voice with Siri Shortcuts

Managing Documents In Your ios Apps

What s New in Core Data?

What s New in Notifications

Enabling Your App for CarPlay

Accessibility on ios. Developing for everyone. Frameworks #WWDC14. Session 210 Clare Kasemset ios Accessibility

What s New in Core Bluetooth

Accessibility on OS X

Core ML in Depth. System Frameworks #WWDC17. Krishna Sridhar, Core ML Zach Nation, Core ML

CloudKit Tips And Tricks

Creating Audio Apps for watchos

What s New in Cocoa for macos

Touch Bar Fundamentals

What's New in UIKit Dynamics and Visual Effects Session 229

Introducing On Demand Resources

Media and Gaming Accessibility

Leveraging Touch Input on ios

Building Watch Apps #WWDC15. Featured. Session 108. Neil Desai watchos Engineer

New Ways to Work with Workouts

What s New in tvos #WWDC16. App Frameworks. Session 206. Hans Kim tvos Engineer

What's New in Core Spotlight

Finding Bugs Using Xcode Runtime Tools

Mastering Xcode for iphone OS Development Part 2. Marc Verstaen Sr. Manager, iphone Tools

What s New in SpriteKit

Cross Platform Nearby Networking

WatchKit In-Depth, Part 2

What s New in SiriKit

Mysteries of Auto Layout, Part 1

Introducing SiriKit. Hey Siri, say hello to apps #WWDC16. App Frameworks. Session 217

Apple Watch Design Tips and Tricks

CarPlay Audio and Navigation Apps

Creating Complications with ClockKit Session 209

What s New in NSCollectionView Session 225

App Extension Best Practices

Advanced Scrollviews and Touch Handling Techniques

Advances in AVFoundation Playback

ios Accessibility Developing for everyone Session 201 Ian Fisch ios Accessibility

Building Faster in Xcode

Your Apps and the Future of macos Security

Designing for Apple Watch

Introducing Swift Playgrounds

Optimizing Swift Performance Session 409

Creating Extensions for ios and OS X, Part Two

Creating Great App Previews

Deploying AirPrint in Enterprise

Mastering Xcode for iphone OS Development Part 1. Todd Fernandez Sr. Manager, IDEs

Swift API Design Guidelines

What s New in CloudKit

What s New in Foundation for Swift Session 207

Introducing CloudKit. A how-to guide for icloud for your Apps. Frameworks #WWDC14. Session 208 Olivier Bonnet CloudKit Client Software

Building Apps with Dynamic Type

Understanding Undefined Behavior

Validating HTTP Live Streams

Localizing with Xcode 9

Power, Performance, and Diagnostics

Audio Unit Extensions

View Controller Advancements for ios8

Vision Framework. Building on Core ML. Media #WWDC17. Brett Keating, Apple Manager Frank Doepke, He who wires things together

Writing Great Alerts. Design #WWDC17. Natalie Calvert, Designer

Adopting Advanced Features of the New UI

Integrating Apps and Content with AR Quick Look

What s New in Core Location

Adapting to the New UI of OS X Yosemite

Designing Great Apple Watch Experiences

Getting to Know Swift Package Manager

What s New in Energy Debugging

What s New in Cocoa. App Frameworks #WWDC17. Ali Ozer Daphne Larose

Improving your Existing Apps with Swift

Multitasking Support on the ios Platform

Localizing with Xcode 6

itunes Connect Development to distribution #WWDC15 Distribution Session 304

Transcription:

Developer Tools #WWDC16 Using and Extending the Xcode Source Editor Session 414 Mike Swingler Xcode Infrastructure and Editors Chris Hanson Xcode Infrastructure and Editors 2016 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

Overview Using New features in Xcode 8 Other not so new, but useful features

Overview Using New features in Xcode 8 Other not so new, but useful features Extending How to add your own features and share them!

Demo New features in the Xcode 8 source editor

Xcode Source Editor Extensions Enhancing Xcode

Extending Xcode What you can do

Extending Xcode What you can do Add commands to the source editor

Extending Xcode What you can do Add commands to the source editor Edit text

Extending Xcode What you can do Add commands to the source editor Edit text Change selections

Extending Xcode What you can do Add commands to the source editor Edit text Change selections One extension, several commands

Extending Xcode How it works Xcode Extensions are Application Extensions

Extending Xcode How it works Xcode Extensions are Application Extensions Each runs in its own process

Extending Xcode How it works Xcode Extensions are Application Extensions Each runs in its own process Sandboxed and uses entitlements

Extending Xcode How it works Xcode Extensions are Application Extensions Each runs in its own process Sandboxed and uses entitlements Gets access to text at invocation

Stability,

Stability, Security,

Stability, Security, Speed

App Store

Delivering Xcode Extensions Getting them into users hands An Xcode Extension is embedded in an application

Delivering Xcode Extensions Getting them into users hands An Xcode Extension is embedded in an application Your App is a great place to put your extension s preferences

Delivering Xcode Extensions Getting them into users hands An Xcode Extension is embedded in an application Your App is a great place to put your extension s preferences Any other UI you want to provide no UI in extensions

Delivering Xcode Extensions Getting them into users hands An Xcode Extension is embedded in an application Your App is a great place to put your extension s preferences Any other UI you want to provide no UI in extensions Distribute via the Mac App Store

Delivering Xcode Extensions Getting them into users hands An Xcode Extension is embedded in an application Your App is a great place to put your extension s preferences Any other UI you want to provide no UI in extensions Distribute via the Mac App Store Distribute on your own via Developer ID

The Xcode Extension Lifecycle Startup

The Xcode Extension Lifecycle Startup Xcode automatically finds and starts extensions

The Xcode Extension Lifecycle Startup Xcode automatically finds and starts extensions Extensions are kept alive while the user is likely to need them

The Xcode Extension Lifecycle Startup Xcode automatically finds and starts extensions Extensions are kept alive while the user is likely to need them Extensions sent extensiondidfinishlaunching

The Xcode Extension Lifecycle Startup Xcode automatically finds and starts extensions Extensions are kept alive while the user is likely to need them Extensions sent extensiondidfinishlaunching Do any needed startup as fast as possible

The Xcode Extension Lifecycle Startup Xcode automatically finds and starts extensions Extensions are kept alive while the user is likely to need them Extensions sent extensiondidfinishlaunching Do any needed startup as fast as possible Asynchronous with Xcode and other extensions

The Xcode Extension Lifecycle Providing commands Xcode asks each extension for its commands, which can come from:

The Xcode Extension Lifecycle Providing commands Xcode asks each extension for its commands, which can come from: Your extension s Info.plist <key>nsextensionattributes</key> <dict> <key>xcsourceeditorcommanddefinitions</key> <array> <dict> <key>xcsourceeditorcommandclassname</key> <string>chrisformat.wraptext</string> <key>xcsourceeditorcommandidentifier</key> <string>com.example.chrisformat.wraptext</string> <key>xcsourceeditorcommandname</key> <string>wrap Text</string> </dict> </array> <key>xcsourceeditorextensionprincipalclass</key> <string>chrisformat.chrisformatextension</string> </dict>

The Xcode Extension Lifecycle Providing commands Xcode asks each extension for its commands, which can come from: Your extension s Info.plist Your extension s commanddefinitions property, overriding the Info.plist <key>nsextensionattributes</key> var commanddefinitions { <dict> <key>xcsourceeditorcommanddefinitions</key> return [[ <array>.classnamekey: <dict> "ChrisFormat.WrapText", <key>xcsourceeditorcommandclassname</key> <string>chrisformat.wraptext</string>.identifierkey: <key>xcsourceeditorcommandidentifier</key> <string>com.example.chrisformat.wraptext</string>.namekey: <key>xcsourceeditorcommandname</key> <string>wrap "Wrap Text</string> Text" ]] } </dict> </array> <key>xcsourceeditorextensionprincipalclass</key> <string>chrisformat.chrisformatextension</string> </dict> "com.apple.chrisformat.wraptext",

The Xcode Extension Lifecycle Where commands live

The Xcode Extension Lifecycle Where commands live Each extension gets a submenu of the Editor menu for its commands

The Xcode Extension Lifecycle Where commands live Each extension gets a submenu of the Editor menu for its commands Extensions listed in Finder sort order

The Xcode Extension Lifecycle Where commands live Each extension gets a submenu of the Editor menu for its commands Extensions listed in Finder sort order Commands are in the order the extension provides

The Xcode Extension Lifecycle Invoking commands User chooses a command

The Xcode Extension Lifecycle Invoking commands User chooses a command Selecting menu item

The Xcode Extension Lifecycle Invoking commands User chooses a command Selecting menu item Pressing keyboard equivalent

The Xcode Extension Lifecycle Invoking commands User chooses a command Selecting menu item Pressing keyboard equivalent Your command is sent an invocation and a callback

The Xcode Extension Lifecycle Invoking commands User chooses a command Selecting menu item Pressing keyboard equivalent Your command is sent an invocation and a callback The invocation contains a text buffer and metadata to operate on

The Xcode Extension Lifecycle Invoking commands User chooses a command Selecting menu item Pressing keyboard equivalent Your command is sent an invocation and a callback The invocation contains a text buffer and metadata to operate on The command uses the callback to tell Xcode it s done

// Commands public protocol XCSourceEditorCommand : NSObjectProtocol { public func perform(with invocation: XCSourceEditorCommandInvocation, completionhandler: (NSError?) -> Void) -> Void }

// Commands public protocol XCSourceEditorCommand : NSObjectProtocol { public func perform(with invocation: XCSourceEditorCommandInvocation, completionhandler: (NSError?) -> Void) -> Void } public class XCSourceEditorCommandInvocation : NSObject { public let commandidentifier: String public var cancellationhandler: () -> Void public let buffer: XCSourceTextBuffer }

// Commands public protocol XCSourceEditorCommand : NSObjectProtocol { public func perform(with invocation: XCSourceEditorCommandInvocation, completionhandler: (NSError?) -> Void) -> Void } public class XCSourceEditorCommandInvocation : NSObject { public let commandidentifier: String public var cancellationhandler: () -> Void public let buffer: XCSourceTextBuffer }

// Commands public protocol XCSourceEditorCommand : NSObjectProtocol { public func perform(with invocation: XCSourceEditorCommandInvocation, completionhandler: (NSError?) -> Void) -> Void } public class XCSourceEditorCommandInvocation : NSObject { public let commandidentifier: String public var cancellationhandler: () -> Void public let buffer: XCSourceTextBuffer }

// Commands public protocol XCSourceEditorCommand : NSObjectProtocol { public func perform(with invocation: XCSourceEditorCommandInvocation, completionhandler: (NSError?) -> Void) -> Void } public class XCSourceEditorCommandInvocation : NSObject { public let commandidentifier: String public var cancellationhandler: () -> Void public let buffer: XCSourceTextBuffer }

// Text Buffer public class XCSourceTextBuffer : NSObject { public let contentuti: String public let tabwidth: Int public let indentationwidth: Int public let usestabsforindentation: Bool public var completebuffer: String public let lines: NSMutableArray<String> public let selections: NSMutableArray<XCSourceTextRange> }

// Text Buffer public class XCSourceTextBuffer : NSObject { public let contentuti: String public let tabwidth: Int public let indentationwidth: Int public let usestabsforindentation: Bool public var completebuffer: String public let lines: NSMutableArray<String> public let selections: NSMutableArray<XCSourceTextRange> }

// Text Buffer public class XCSourceTextBuffer : NSObject { public let contentuti: String public let tabwidth: Int public let indentationwidth: Int public let usestabsforindentation: Bool public var completebuffer: String public let lines: NSMutableArray<String> public let selections: NSMutableArray<XCSourceTextRange> }

// Text Buffer public class XCSourceTextBuffer : NSObject { public let contentuti: String public let tabwidth: Int public let indentationwidth: Int public let usestabsforindentation: Bool public var completebuffer: String public let lines: NSMutableArray<String> public let selections: NSMutableArray<XCSourceTextRange> }

// Text Buffer public class XCSourceTextBuffer : NSObject { public let contentuti: String public let tabwidth: Int public let indentationwidth: Int public let usestabsforindentation: Bool public var completebuffer: String public let lines: NSMutableArray<String> public let selections: NSMutableArray<XCSourceTextRange> }

// Text Buffer public class XCSourceTextBuffer : NSObject { public let contentuti: String public let tabwidth: Int public let indentationwidth: Int public let usestabsforindentation: Bool public var completebuffer: String public let lines: NSMutableArray<String> public let selections: NSMutableArray<XCSourceTextRange> }

// Text Buffer public class XCSourceTextBuffer : NSObject { public let contentuti: String public let tabwidth: Int public let indentationwidth: Int public let usestabsforindentation: Bool public var completebuffer: String public let lines: NSMutableArray<String> public let selections: NSMutableArray<XCSourceTextRange> }

// Text Buffer public class XCSourceTextBuffer : NSObject { public let contentuti: String public let tabwidth: Int public let indentationwidth: Int public let usestabsforindentation: Bool public var completebuffer: String public let lines: NSMutableArray<String> public let selections: NSMutableArray<XCSourceTextRange> }

// Positions and Ranges public class XCSourceTextRange : NSObject, NSCopying { public var start: XCSourceTextPosition public var end: XCSourceTextPosition } public struct XCSourceTextPosition { public var line: Int public var column: Int }

// Positions and Ranges public class XCSourceTextRange : NSObject, NSCopying { public var start: XCSourceTextPosition public var end: XCSourceTextPosition } public struct XCSourceTextPosition { public var line: Int public var column: Int }

// Positions and Ranges public class XCSourceTextRange : NSObject, NSCopying { public var start: XCSourceTextPosition public var end: XCSourceTextPosition } public struct XCSourceTextPosition { public var line: Int public var column: Int }

Demo Creating an Xcode source editor extension

Speed Text editing is user-synchronous

Speed Text editing is user-synchronous Users will invoke your command via typing

Speed Text editing is user-synchronous Users will invoke your command via typing User changes to a document are prevented while a command is running

Speed Text editing is user-synchronous Users will invoke your command via typing User changes to a document are prevented while a command is running The user can cancel your command

The command Speed Slide is still busy. Cancel Speed Text editing is user-synchronous Users will invoke your command via typing User changes to a document are prevented while a command is running The user can cancel your command A command that takes a while gets a cancellation banner

The command Speed Slide is still busy. Cancel Speed Text editing is user-synchronous Users will invoke your command via typing User changes to a document are prevented while a command is running The user can cancel your command A command that takes a while gets a cancellation banner

Speed How Xcode helps

Speed How Xcode helps Keeps your extension alive for fast invocation

Speed How Xcode helps Keeps your extension alive for fast invocation Optimizes data transfer for performance

Speed How Xcode helps Keeps your extension alive for fast invocation Optimizes data transfer for performance Cancellation is immediate for the user

Speed How you can help Xcode

Speed How you can help Xcode Start up quickly

Speed How you can help Xcode Start up quickly Use GCD and follow standard asynchronous patterns

Speed How you can help Xcode Start up quickly Use GCD and follow standard asynchronous patterns Don t replace the whole buffer if you don t have to

Speed How you can help Xcode Start up quickly Use GCD and follow standard asynchronous patterns Don t replace the whole buffer if you don t have to Handle cancellation quickly

Summary New features in the source editor Documentation comments Color and image literals, with code complete Recent features Fuzzy code completion Xcode source editor extensions How they work How to make them

More Information https://developer.apple.com/wwdc16/414

Related Sessions Optimizing App Startup Time Mission Wednesday 10:00AM Introduction to Xcode Nob Hill Thursday 1:40PM Creating Extensions for ios and OS X, Part 1 WWDC 2014 Creating Extensions for ios and OS X, Part 2 WWDC 2014 App Extension Best Practices WWDC 2015

Labs Xcode Open Hours Developer Tools Lab B Friday 9:00AM Xcode Open Hours Developer Tools Lab B Friday 12:00PM Xcode Open Hours Developer Tools Lab B Friday 3:00PM