Post

Replies

Boosts

Views

Activity

Reply to Some emojis are beyond the normal emoji unicode range.
As you know, Unicode consortium will add many emojis every year. https://unicode.org/emoji/charts/emoji-list.html I can find some more characters in range U+1FAD3...U+1FAD6. I'm not sure how many of them are already include in the Apple's emoji font, but eventually Apple may cover all. Which means, you may need to update the range list every time Unicode emojis are updated. One more, the code you found in the linked thread is far from complete. As you see in the whole list of emojis, some emojis are made of multiple code points. But the method isEmoji(_:) detects all the variation selectors as emoji, although there are many cases non-emoji character having variation selector. Find a better solution which detects emojis more completely, and which will be updated when Unicode standard is updated.
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’21
Reply to How to Use a Button in navigationBarItems to Work with List
You can try something like this: struct ContentView: View { @State private var users = ["George", "Kenny", "Susan", "Natalie"] @State var editMode: EditMode = .inactive //<- var body: some View { NavigationView { List { ForEach(users, id: \.self) { user in Text(user) } .onDelete(perform: delete) } .environment(\.editMode, $editMode) //<- .navigationBarTitle("My family") .navigationBarItems(trailing: Button(action: { print("Edit button pressed...") self.editMode = .active //<- }) { Text("Edit") } ) } } func delete(at offsets: IndexSet) { users.remove(atOffsets: offsets) } } Create a state representing EditMode and pass the Binding of it to the environment \.editMode of the inner view (List). You may want to add animating or change the button to Done, but I think you can do it yourself.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Sep ’21
Reply to Swift: how to check group membership between two ODRecord objects?
I'm guessing due to the idiosyncratic implementation of the underlying BOOL-returning NSError-taking method on the Objective-C side? Your guess seems to be right. The original method isMemberRecord:error: does not follow the convention of error throwing functions. To import error throwing functions correctly in Swift, the original Objective-C method should return false or nil only when error is thrown. You should better send a bug report to Apple. To work this around, you may need to write some Objective-C wrapper, something like this: ODRecord+hasMember.h #import <OpenDirectory/OpenDirectory.h> #import <Foundation/Foundation.h> NS_ASSUME_NONNULL_BEGIN @interface ODRecord (hasMember) - (NSNumber * _Nullable)hasMember: (ODRecord *)record error: (NSError **)error; @end NS_ASSUME_NONNULL_END ODRecord+hasMember.m #include "ODRecord+hasMember.h" @implementation ODRecord (hasMember) - (NSNumber * _Nullable)hasMember: (ODRecord *)record error: (NSError **)error { NSError *resultError = nil; BOOL result = [self isMemberRecord:record error:&resultError]; if( resultError != nil ) { if( error != nil ) { *error = resultError; } return nil; } return [NSNumber numberWithBool:result]; } @end {YourProjectName}-Bridging-Header.h #include "ODRecord+hasMember.h" And you can use it like this: func myIsMember_attempt3(_ r: ODRecord, ofGroup g: ODRecord) -> Bool? { do { let isM = try g.hasMember(r).boolValue return isM } catch { print("Error: \(error)") return nil } }
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’21
Reply to Completion with JSON
You are putting completion() at the wrong place: func first(completion: @escaping ()->()) { //<- let url = URL(string: "https://jsonplaceholder.typicode.com/users")! URLSession.shared.dataTask(with: url) { data, _, _ in if let data = data { let result = try? JSONDecoder().decode([User].self, from: data) self.result2 = result![0].name completion() //<- here } }.resume() //completion() //<- Not here }
Topic: Programming Languages SubTopic: Swift Tags:
Sep ’21
Reply to Array Elements - Getting Control
@azabug, I just would like to worry about the problems with enough info provided in a readable manner.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Forum's admin wake up! You are h*cked!
Not only you. Every public sites are attacked by this sort of spammers or malicious users. But the moderator of this site is too slow to remove them.
Topic: Media Technologies SubTopic: General Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Xcode: Why I need #available(iOS 14.0, *) even if the project iOS Deployment Target is 14.1?
Can you clarify the iOS version you set in DEPLOYMENT INFO of your app target?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Some emojis are beyond the normal emoji unicode range.
As you know, Unicode consortium will add many emojis every year. https://unicode.org/emoji/charts/emoji-list.html I can find some more characters in range U+1FAD3...U+1FAD6. I'm not sure how many of them are already include in the Apple's emoji font, but eventually Apple may cover all. Which means, you may need to update the range list every time Unicode emojis are updated. One more, the code you found in the linked thread is far from complete. As you see in the whole list of emojis, some emojis are made of multiple code points. But the method isEmoji(_:) detects all the variation selectors as emoji, although there are many cases non-emoji character having variation selector. Find a better solution which detects emojis more completely, and which will be updated when Unicode standard is updated.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to How to Use a Button in navigationBarItems to Work with List
You can try something like this: struct ContentView: View { @State private var users = ["George", "Kenny", "Susan", "Natalie"] @State var editMode: EditMode = .inactive //<- var body: some View { NavigationView { List { ForEach(users, id: \.self) { user in Text(user) } .onDelete(perform: delete) } .environment(\.editMode, $editMode) //<- .navigationBarTitle("My family") .navigationBarItems(trailing: Button(action: { print("Edit button pressed...") self.editMode = .active //<- }) { Text("Edit") } ) } } func delete(at offsets: IndexSet) { users.remove(atOffsets: offsets) } } Create a state representing EditMode and pass the Binding of it to the environment \.editMode of the inner view (List). You may want to add animating or change the button to Done, but I think you can do it yourself.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Count the number of managed objects in a @SectionedFetchRequest
According to the doc, SectionedFetchResults is a RandomAccessCollection of Section and Section is a RandomAccessCollection of Result (Result == CoreDataEntityClass, in your case). So, Please try something like this to get the total count: items.reduce(0, {$0 + $1.count})
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Converting UIImage to jpegData - [Metal] 9072 by 12198 iosurface is too large for GPU
Can you share the image which causes the issue?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Getting The Right Data Back
Your save(_:) does not make sense considering the fact prefArr is made of fetched results. Please clarify what you expect on calling save(_:)?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Swift: how to check group membership between two ODRecord objects?
I'm guessing due to the idiosyncratic implementation of the underlying BOOL-returning NSError-taking method on the Objective-C side? Your guess seems to be right. The original method isMemberRecord:error: does not follow the convention of error throwing functions. To import error throwing functions correctly in Swift, the original Objective-C method should return false or nil only when error is thrown. You should better send a bug report to Apple. To work this around, you may need to write some Objective-C wrapper, something like this: ODRecord+hasMember.h #import <OpenDirectory/OpenDirectory.h> #import <Foundation/Foundation.h> NS_ASSUME_NONNULL_BEGIN @interface ODRecord (hasMember) - (NSNumber * _Nullable)hasMember: (ODRecord *)record error: (NSError **)error; @end NS_ASSUME_NONNULL_END ODRecord+hasMember.m #include "ODRecord+hasMember.h" @implementation ODRecord (hasMember) - (NSNumber * _Nullable)hasMember: (ODRecord *)record error: (NSError **)error { NSError *resultError = nil; BOOL result = [self isMemberRecord:record error:&resultError]; if( resultError != nil ) { if( error != nil ) { *error = resultError; } return nil; } return [NSNumber numberWithBool:result]; } @end {YourProjectName}-Bridging-Header.h #include "ODRecord+hasMember.h" And you can use it like this: func myIsMember_attempt3(_ r: ODRecord, ofGroup g: ODRecord) -> Bool? { do { let isM = try g.hasMember(r).boolValue return isM } catch { print("Error: \(error)") return nil } }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to @StateObject and view installation
Can you show a complete code to reproduce the issue?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Completion with JSON
You are putting completion() at the wrong place: func first(completion: @escaping ()->()) { //<- let url = URL(string: "https://jsonplaceholder.typicode.com/users")! URLSession.shared.dataTask(with: url) { data, _, _ in if let data = data { let result = try? JSONDecoder().decode([User].self, from: data) self.result2 = result![0].name completion() //<- here } }.resume() //completion() //<- Not here }
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Why do Let Integer constants change values or always equal Zero?
static let variables (or you want to call them constants) are initialized dynamically on the first use. Did you check them in the debugger after all of them are initialized?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to App Crashing
Hard to say something sure with just shown EXC_BAD_ACCESS. Check all the info shown in Xcode, stack traces, debug prints and logs, all such things.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Why do Let Integer constants change values or always equal Zero?
Yes. The ones I showed in the video were all initialized. I cannot find anything in the video which confirms all the static let variables are initialized. Do you know how to check static let variable is initialized?
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21
Reply to Why do Let Integer constants change values or always equal Zero?
@blaine l, thanks for clarifying. And that is the one I was to propose to you. I will take time to check it on some actual devices. You should better send a bug report to Apple, attaching a project which reproduces the issue and the precise condition and steps-to-reproduce may be needed.
Topic: Programming Languages SubTopic: Swift Tags:
Replies
Boosts
Views
Activity
Sep ’21