nshipster.com | overlooked bits in Objective-C , Swift , and Cocoa | iOS library
kandi X-RAY | nshipster.com Summary
kandi X-RAY | nshipster.com Summary
NSHipster is a journal of the overlooked bits in Swift, Objective-C and Cocoa. Updated weekly. This repository hosts the source code that generates and deploys NSHipster.com and its translations. For the articles themselves, see this repository.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of nshipster.com
nshipster.com Key Features
nshipster.com Examples and Code Snippets
Community Discussions
Trending Discussions on nshipster.com
QUESTION
I'm trying to add documentation to my code in Xcode. I've followed a couple of articles that suggest my markup should work with Xcode preview (https://nshipster.com/swift-documentation/ and https://sarunw.com/posts/swift-documentation/) but the bullet point list isn't displaying. Have I missed something obvious?
...ANSWER
Answered 2022-Apr-03 at 09:54Here is fixed part (removed #, and wrapping comment is only /** */, you don't need * at every line for comment itself, but it's a mark for list item)
QUESTION
In this article on Xcode Source Editor extensions, it mentions that XPC is a way to circumvent the app sandbox:
The extension must be sandboxed just to be loaded by Xcode, whereas calls to SourceKit needs to be un-sandboxed, which of course won’t fly in the App Store. We could distribute independently and use an un-sandboxed XPC service embedded in the extension.
However, I'm not sure how to tie everything together to use an XPC service.
How do I tie my Xcode Source Editor extension to an XPC service?
...ANSWER
Answered 2021-May-17 at 19:16I was able to figure this out thanks to the LinuxSupportForXcode extension.
I'm going to make the assumption that you followed the tutorial on creating an Xcode Extension Editor, and made the main project a macOS App. You should have a target structure similar to:
- MyApp (macOS App target)
- MyAppExtension (Xcode Source Editor Extension target)
To use XPC with a Source Editor Extension:
File > New > Target... > XPC Service.
For example purposes, we'll assume it's called
MyAppXPCService
and its bundle identifier iscom.example.MyAppXPCService
.Move the XPC service dependency from the App to the Extension:
If you don't do this step, you may run into issues where your XPCService isn't being executed by the extension. E.g. you invoke a command that should launch the XPCService, but in the Xcode Debug Navigator, your XPCService never comes up.
- Go to your app's target.
- Remove MyAppXPCService.xpc from the Frameworks and Libraries.
- Go to your extension's target.
- Add MyAppXPCService.xpc to Frameworks and Libraries by dragging it in from the products folder in the Project Navigator. Leave it on the default "Embed Without Signing".
In the XPC Service, convert it to Swift, mainly following the instructions here:
Note: If you'd prefer to not convert to Swift, and use a mixed target instead, simply create a Swift file and when prompted, choose to create the bridging header, then include
#import "MyAppXPCServiceProtocol.h"
in the bridging header.Create
main.swift
,MyService.swift
,MyServiceDelegate.swift
,MyServiceProtocol.swift
normally.Set the following build settings:
- Install Objective-C Compatibility Header:
NO
- Objective-C Generated Interface Header Name: `` (blank)
- Install Objective-C Compatibility Header:
Choose your desired Swift Language Version in Build Settings.
In Build Settings, add (don't replace):
@loader_path/../../../../Frameworks
to Runtime Search Paths.If you accidentally replace, and use an embedded framework, XPC will crash on launch.
In your extension target:
import MyAppXPCService
so that it can see the protocol.Create the connection, using your XPC target's bundle identifier for
serviceName
:
QUESTION
I'm trying to set up another Xcode project as the one passed on launch for the purposes of testing an Xcode extension:
Rather than hardcoding a path like this, I'd like to make it relative to the current directory.
I created a placeholder build script and output the environment variables. I found out that the current project directory can be accessed via the PROJECT_DIR
environment variable.
How do I reference this environment variable in the Arguments Passed On Launch screen?
For example, instead of /Users/zoesmith/Desktop/Sample/TestableCode.xcodeproj
, I'd like the path to be something like this instead:
ANSWER
Answered 2021-Apr-23 at 19:28Looks like the following works:
QUESTION
I want to use SWIFT reflection to resolve all implementations of a certain protocol.
The problem I'm trying to solve is that I want to test all present and future implementations of a certain protocol.
The reflection in SWIFT is limited, but after reading up on it, I believe it should be possible. I have found the following articles on reflection in SWIFT, but I am having trouble mapping it in to my specific use case.
https://nshipster.com/mirror/ https://www.swiftbysundell.com/articles/reflection-in-swift/
How can I resolve and iterate over all implementations of a specific protocol?
...ANSWER
Answered 2021-Mar-04 at 07:03The definition says: Reflection
is a common programming language feature that enables us to inspect, and work with, the members of a type — dynamically, at runtime. Members
are list of properties inside a class/struct.
So, if you want to iterate over all your types that confirm Animal
protocol, you need to have them as members in a type, and then iterate over it.
Check code below-:
QUESTION
I'm trying to pass a string (though my real goal is to pass an array) from one macOS app to the other. The receiver app is sandboxed while the sender app is not sandboxed.
I've added an App Group (DEV_TEAM_ID.com.if.APP_NAME.UNIQUE_NAME
) to both apps.
In the receiver app, I have implemented creating the port and runloop:
ANSWER
Answered 2021-Feb-17 at 05:19I was able to sort this out after reading Using App Groups for communication between macOS/iOS apps from the Same Vendor
The problem was that as of Big Sur (or possibly Catalina), macOS apps using App Groups require a group container to be created in the developer portal. after doing that, you need to reconfigure the code-signing your app to include a provisioning profile. I'm not really sure when this all became a requirement since setting up App Groups isn't really well-documented by Apple. Everything works great after following the steps in the above linked article.
I was able to get my array passed from one app to another:
QUESTION
I'd like to create a property wrapper to accommodate the well known precision issues. However, when I use the @PropertyWrapper
as I understand it to be used and demonstrated here, I get the following errors:
ANSWER
Answered 2021-Feb-05 at 03:39According to the docs:
When you include property wrapper arguments, you can also specify an initial value using assignment. Swift treats the assignment like a
wrappedValue
argument and uses the initializer that accepts the arguments you include.
So it translates your property declaration into something like:
QUESTION
I would like to create an Xcode Source Editor Extension. A tutorial from this website shows a template for this in the new project menu. However, as of Xcode 11.5, this is missing from the list of templates. Is there still a way to do this?
...ANSWER
Answered 2020-Jun-04 at 18:57As stated in the documentation,
begin by creating a new macOS project in Xcode. Add a new Xcode Source Editor Extension target to your project
In other words, first create a new project. Then create a new target in said project. That target being an Xcode Source Editor Extension.
QUESTION
I'm trying to make an Objective-C iOS library work for macOS applications. Removing UIKit-based notifications is the only real task here. When trying to replace—for example—UIApplicationDidEnterBackgroundNotification
with NSApplicationDidResignActiveNotification
, I run into the odd error of the latter variable being called an undeclared identifier.
ANSWER
Answered 2020-Jun-03 at 23:35Silly solution, though aided by @Willeke's comment that they weren't seeing an error with the same code snippet—the library needed Cocoa.h in place of the iOS imports.
QUESTION
Is there a way to get the Siri voices for NSSpeechSynthesizer
? NSSpeechSynthesizer.availableVoices()
does not list them, but maybe there is an undocumented trick or something?
I've also tried to use AVSpeechSynthesizer
, even tough it should be available on macOS 10.14+, I couldn't get it to read out loud …
I've used a Playground to test this with the following code from NSHipster:
...ANSWER
Answered 2020-May-26 at 09:16I'm not aware of any trick to make the Siri voice available and I'm afraid it's impossible to make it working via public API.
- Both
NSSpeechSynthesizer
andAVSpeechSynthesizer
do utilizeSpeechSynthesis.framework
(included in theApplicationServices.framework
). - Quickly checked it and the function
BuildDefaultVoiceList(bool)
checks bundle identifier (viaPermitAllVoices
which compares it withcom.apple.VoiceOverUtility
,com.apple.VoiceOver
,com.apple.VoiceOverUtilityCacheBuilder
). - There're other checks probably.
All the voices are stored in the /System/Library/Speech/Voices
folder. Tried to copy the voice, change Info.plist
values to make it look like another voice, but still not available/working.
How far do you want to go? Do you want to disable SIP, modify framework, preload your stuff, ... Is it worth it?
AVSpeechSynthesizer
on macOS
It works, but it's buggy and you have to kill the service from time to time.
List of available voicesQUESTION
iOS 13 introduced the progress
property in the OperationQueue
class. At the same time Apple marked the operations
and operationCount
properties as deprecated which indicates they should not be used anymore for reporting progress on a queue.
My problem is that I cannot get the progress
property to work as I expect it to work (which is basically out of the box). Also I could not find any documentation regarding this new property (other than that it now exists).
I tried to get it to work in a new SingleView project that has one UIProgressView
on the main UIViewController
. This sample is heavily inspired by https://nshipster.com/ios-13/.
ANSWER
Answered 2020-Mar-28 at 10:36I just received feedback from Apple about this. The documentation is currently well hidden in the header file NSOperation.h. Here is the extract for anybody who encounters the same problem:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install nshipster.com
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page