Xcode + Swift: Is it possible to create custom comment marks? - swift

In Swift (I'm using Swift 3 / Xcode 8 stable): is it possible to create custom comment mark/tags that can be recognized by Xcode? (and thus added to the jump bar.)
For example, aside from the // TODO:, // FIXME: or // MARK:, can we add new ones, like // OPTIMIZE:, // EVAL:, or any other custom mark?

Fyi, this was done in XCode 10.2.1, just in case anyone rolls past this page. Haven't tested it under XCode 8.
Funny enough was just making a //MARK: comment, and found a new trick. While you can't just to //WHATEVER: to get that showing up the same as //FIXME, etc. What you can do is this.
//MARK: WHATEVER: this also works
//MARK: ASDOESTHIS: because why not.
Screenshow also attached for proof, hope that helps.

Related

Cleaning an older swift application project using storyboards

I have been assigned a "new" old app project from my company, where there is a mix of older swift code and newer swift code. I am slowly getting comfortable with deleting and refactoring parts of the code, trying to remove the Xcode warnings and making the code safer in general... But since I am new to swift (especially storyboards), I am not sure when an #IBOutlet or #IBAction can be removed.
I have some #IBOutlets and #IBActions, where there are no 'dots' next to them:
the circles to the left-side of the outlets don't have a dot
Does this mean it is safe to change these from outlets to "regular" views? and is this also true for #IBActions?
Is this simply straight forward, no dot = No #IBOutlet/#IBAction needed?
Or is it trial and error: Try and remove, build & run, see if broken, redo...?
Or are there smarter ways to check these things?

autocorrectType is not working on iOS 13 using swift

I know this is quiet simple and straight forward to disable autocorrection on iPhone and it worlds pretty much fine, but until now. Surprisingly, suggestion bar appear for text field even I have disabled it from storyboard and even programmatically.
self.textField.autocorrectionType = .no
Done that in sotoryboard as well.
But it does appear on iOS 13, not on previous versions and simulator.
There are many answers already for this one but none is working on iOS 13 so no need to mark the question as duplicate.
Cheers!
If you are using a Storyboard you can disable autocorrection on the attributes inspector (the down arrow icon) under the Text input traits. See the image below for details.

Drag and Drop using swift 4 on mac OS

I'm using swift 4 and Xcode 9 and I have a problem with implementation of drag and drop. I have a custom 'destination' view for drops and in swift 3 i call
register(forDraggedTypes: Array(NSURLPboardType))
to accept drags that contain those types.
How can I do somethings like this in swift 4?
Now I have this code
registerForDraggedTypes([.pdf])
And no one NSDraggingDestination method calls when I drop a pdf in my view.
(my custom view sits on top)
So my colleague found solution of this problem, in swift 4 you have to use kUTTypes casted as String for drag and drop, like this:
registerForDraggedTypes([NSPasteboard.PasteboardType(rawValue: kUTTypeFileURL as String), NSPasteboard.PasteboardType(rawValue: kUTTypeItem as String)])
With this code all NSDraggingDestination methods works fine, you can drop any file from finder in your view.

Why am I able to use MessageUI without a framework reference?

In my Swift 2 project, targeting iOS 9.2 and above, in Xcode 8.2.1, I have code that shows the mail-compose screen like so:
if MFMailComposeViewController.canSendMail() {
let composeMailVC = MFMailComposeViewController()
composeMailVC.mailComposeDelegate = self
composeMailVC.setSubject("Test")
// etc
}
Originally I had a reference to the MessageUI.framework in my project properties, but after removing the framework reference and cleaning the project, it still builds fine and when I run the code on my device the mail compose window still appears and seems fully functional.
I cannot find any explicit references to MessageUI.framework in the raw text of my .xcodeproj file, nor is there anything in my Objective-C bridging header.
I know that Swift does make some implicit framework references, but I couldn't find anything that suggests MessageUI.framework is one of them.
Curiously when I jump to the definition of MFMailComposeViewController XCode shows it in the MessageUI module.
The compiler automatically added the frame work in given its previous direction - IE. Import.

Xcode 4.3.2 - refering from a Text Field to a string member

I am new to Xcode and Objective-C. I could see a demo that make such a reference from a text field on the View to a string member of the class such that whenever the string is changed the contents of the Text Field is changed too. However this demo is not with the latest Xcode and I cannot find how to do the same with Xcode 4.3.2.
Thanks
This has nothing to do with XCode, this is objective-c. XCode is just an code editor.
What you are looking for is an observer. Add an observer to you NSString and whenever it gets changed you can update your UITextField. I think I have some code somewhere that does that, I'll see if I can find it.
edit
Here is a link to the a question I made once upon a time: Adding an observer to an NSString